Skip to content

Commit

Permalink
Replace some socket.send() calls with socket.sendall()
Browse files Browse the repository at this point in the history
In most places we already used sendall() but four fell through the cracks
  • Loading branch information
joerivanruth committed Feb 4, 2025
1 parent ecc83ef commit 770f20c
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions pymonetdb/mapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ def _sabotage(self):
bad_header = struct.pack('<H', 2 * 8193 + 0) # larger than allowed, and not the final message
bad_body = b"ERROR\x80ERROR" # invalid utf-8, and too small
try:
sock.send(bad_header + bad_body)
sock.sendall(bad_header + bad_body)
# and then we hang up
sock.close()
except Exception:
Expand Down Expand Up @@ -780,19 +780,13 @@ def _putblock_raw(self, block, finish):
if length < MAX_PACKAGE_LENGTH:
last = 1
flag = struct.pack('<H', (length << 1) + (last if finish else 0))
self.socket.send(flag)
self.socket.send(data)
self.socket.sendall(flag)
self.socket.sendall(data)
pos += length

def _send_all_and_shutdown(self, block):
""" put the data into the socket """
pos = 0
end = len(block)
block = memoryview(block)
while pos < end:
data = block[pos:pos + 8192]
nsent = self.socket.send(data)
pos += nsent
self.socket.sendall(block)
try:
self.socket.shutdown(socket.SHUT_WR)
except OSError:
Expand Down

0 comments on commit 770f20c

Please sign in to comment.