def write(self, data):
     """Write data to the remote end, buffering if not connected."""
     if self.state() == QAbstractSocket.ConnectedState:
         logger.debug("writing remote: %d bytes", len(data))
         super(RemoteSocket, self).write(data)
     else:
         self.buffered_data.append(data)
 def handle_connected(self):
     """When connected, send all pending data."""
     self.disconnected.connect(self.handle_disconnected)
     self.connected_d.callback(None)
     for d in self.buffered_data:
         logger.debug("writing remote: %d bytes", len(d))
         super(RemoteSocket, self).write(d)
     self.buffered_data = []
 def local_disconnected(self):
     """The local end disconnected."""
     logger.debug("The local socket got disconnected.")
 def loseConnection(self):
     """The remote end disconnected."""
     logger.debug("disconnecting local end.")
     self.local_socket.close()
 def write(self, data):
     """Data available on the remote end. Bring it back."""
     logger.debug("writing local: %d bytes", len(data))
     self.local_socket.write(data)
 def handle_disconnected(self):
     """Do something with disconnections."""
     logger.debug("Remote socket disconnected")
     self.protocol.remote_disconnected()