Pymet fix transport automatic roll over

bug/bundler_fix
Spencer McIntyre 2015-07-14 15:18:11 -04:00
parent 00da619556
commit 18cb55f1fa
1 changed files with 28 additions and 23 deletions

View File

@ -469,8 +469,9 @@ class Transport(object):
pkt = self._get_packet()
except:
return None
if pkt is None:
return None
self.communication_last = time.time()
if pkt:
self.communication_active = True
return pkt
@ -536,11 +537,13 @@ class HttpTransport(Transport):
request = urllib.Request(self.url, bytes('RECV', 'UTF-8'), self._http_request_headers)
url_h = urllib.urlopen(request, timeout=self.communication_timeout)
packet = url_h.read()
if not packet or len(packet) < 8:
return None
if packet == '':
return ''
if len(packet) < 8:
return None # looks corrupt
pkt_length, _ = struct.unpack('>II', packet[:8])
if len(packet) != pkt_length:
return None
return None # looks corrupt
return packet[8:]
def _send_packet(self, packet):
@ -609,11 +612,13 @@ class TcpTransport(Transport):
self.socket = None
def _get_packet(self):
packet = None
first = self._first_packet
self._first_packet = False
if select.select([self.socket], [], [], 0.5)[0]:
if not select.select([self.socket], [], [], 0.5)[0]:
return ''
packet = self.socket.recv(8)
if packet == '': # remote is closed
return None
if len(packet) != 8:
if first and len(packet) == 4:
received = 0