Commit 9834ca91 authored by Antoine Millet's avatar Antoine Millet
Browse files

Better error management on endpoint operations

parent a57f92dc
Loading
Loading
Loading
Loading
+23 −2
Original line number Diff line number Diff line
@@ -54,7 +54,20 @@ class TunnelProtocol(Protocol):
        Handle data coming from the endpoint socket and push it through the
        sjRpc tunnel.
        '''
        try:
            read = self._endpoint.recv(self._ok_to_send)
        except (IOError, socket.error) as err:
            if err.errno in self.connection.NONBLOCKING_ERRORS:
                return
            else:
                self.close()
                return

        # Empty read means the connection has been closed on other side:
        if not read:
            self.close()
            return

        self._ok_to_send -= len(read)
        self.send(read)
        if not self._ok_to_send:
@@ -69,7 +82,15 @@ class TunnelProtocol(Protocol):
        This method is also responsible of asking more data to the peer when
        the incoming buffer is empty.
        '''
        try:
            sent = self._endpoint.send(self._from_tun_to_endpoint_buf)
        except (IOError, socket.error) as err:
            if err.errno in self.connection.NONBLOCKING_ERRORS:
                return
            else:
                self.close()
                return

        self._from_tun_to_endpoint_buf = self._from_tun_to_endpoint_buf[sent:]
        self._asked -= sent
        if self._asked < TunnelProtocol.GET_SIZE * 2: