Make recv_data less greedy so it doesn't eat other packets

This commit is contained in:
James Cammarata 2013-10-01 16:50:32 -05:00
parent 8923a5b0d9
commit fa80a17aa3
2 changed files with 4 additions and 4 deletions

View file

@ -138,7 +138,7 @@ class Connection(object):
try: try:
vvvv("%s: in recv_data(), waiting for the header" % self.host) vvvv("%s: in recv_data(), waiting for the header" % self.host)
while len(data) < header_len: while len(data) < header_len:
d = self.conn.recv(1024) d = self.conn.recv(header_len - len(data))
if not d: if not d:
vvvv("%s: received nothing, bailing out" % self.host) vvvv("%s: received nothing, bailing out" % self.host)
return None return None
@ -148,7 +148,7 @@ class Connection(object):
data = data[header_len:] data = data[header_len:]
vvvv("%s: data received so far (expecting %d): %d" % (self.host,data_len,len(data))) vvvv("%s: data received so far (expecting %d): %d" % (self.host,data_len,len(data)))
while len(data) < data_len: while len(data) < data_len:
d = self.conn.recv(1024) d = self.conn.recv(data_len - len(data))
if not d: if not d:
vvvv("%s: received nothing, bailing out" % self.host) vvvv("%s: received nothing, bailing out" % self.host)
return None return None

View file

@ -198,7 +198,7 @@ class ThreadedTCPRequestHandler(SocketServer.BaseRequestHandler):
data = b"" data = b""
vvvv("in recv_data(), waiting for the header") vvvv("in recv_data(), waiting for the header")
while len(data) < header_len: while len(data) < header_len:
d = self.request.recv(1024) d = self.request.recv(header_len - len(data))
if not d: if not d:
vvv("received nothing, bailing out") vvv("received nothing, bailing out")
return None return None
@ -208,7 +208,7 @@ class ThreadedTCPRequestHandler(SocketServer.BaseRequestHandler):
data = data[header_len:] data = data[header_len:]
vvvv("data received so far (expecting %d): %d" % (data_len,len(data))) vvvv("data received so far (expecting %d): %d" % (data_len,len(data)))
while len(data) < data_len: while len(data) < data_len:
d = self.request.recv(1024) d = self.request.recv(data_len - len(data))
if not d: if not d:
vvv("received nothing, bailing out") vvv("received nothing, bailing out")
return None return None