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