Send combined size and payload bytes to socket to avoid potentially split packets with TCP_NODELAY (#797)
This commit is contained in:
@@ -519,12 +519,12 @@ class BrokerConnection(object):
|
|||||||
client_id=self.config['client_id'])
|
client_id=self.config['client_id'])
|
||||||
message = b''.join([header.encode(), request.encode()])
|
message = b''.join([header.encode(), request.encode()])
|
||||||
size = Int32.encode(len(message))
|
size = Int32.encode(len(message))
|
||||||
|
data = size + message
|
||||||
try:
|
try:
|
||||||
# In the future we might manage an internal write buffer
|
# In the future we might manage an internal write buffer
|
||||||
# and send bytes asynchronously. For now, just block
|
# and send bytes asynchronously. For now, just block
|
||||||
# sending each request payload
|
# sending each request payload
|
||||||
self._sock.setblocking(True)
|
self._sock.setblocking(True)
|
||||||
for data in (size, message):
|
|
||||||
total_sent = 0
|
total_sent = 0
|
||||||
while total_sent < len(data):
|
while total_sent < len(data):
|
||||||
sent_bytes = self._sock.send(data[total_sent:])
|
sent_bytes = self._sock.send(data[total_sent:])
|
||||||
|
Reference in New Issue
Block a user