我们有类似于下面的代码来在机器和远程主机之间创建一个启用 SSL 的套接字来传输数据。我们注意到,每次调用 sock.send 时发送的数据量约为 16K。有没有办法配置这个?以 16K 的块发送 10 MB 的数据非常慢,我们可以将块大小配置为 1-2 MB 左右吗?
from OpenSSL import SSL
import socket
''' Create SSL context.
ctx = ...
''' Create SSL enabled socket.
sock = SSL.Connection(ctx, socket.socket(socket.AF_INET, socket.SOCK_STREAM))
''' Connect to the remote host.
sock.connect((host_address, port))
''' msg is a large string about 10 MB.
msg = ...
''' Send data over the socket.
total_sent = 0
while (total_sent < len(msg)):
sent = sock.send(msg[total_sent:])
total_sent += sent