def handle_read(self):
with self.lock:<EOL><INDENT>logger.debug("<STR_LIT>")<EOL>if self._eof or self._socket is None:<EOL><INDENT>return<EOL><DEDENT>if self._state == "<STR_LIT>":<EOL><INDENT>while True:<EOL><INDENT>logger.debug("<STR_LIT>")<EOL>self._continue_tls_handshake()<EOL>logger.debug("<STR_LIT>".format(self._tls_state))<EOL>if self._tls_state != "<STR_LIT>":<EOL><INDENT>break<EOL><DEDENT><DEDENT><DEDENT>elif self._tls_state == "<STR_LIT>":<EOL><INDENT>while self._socket and not self._eof:<EOL><INDENT>logger.debug("<STR_LIT>")<EOL>try:<EOL><INDENT>data = self._socket.read(<NUM_LIT>)<EOL><DEDENT>except ssl.SSLError as err:<EOL><INDENT>if err.args[<NUM_LIT:0>] == ssl.SSL_ERROR_WANT_READ:<EOL><INDENT>break<EOL><DEDENT>elif err.args[<NUM_LIT:0>] == ssl.SSL_ERROR_WANT_WRITE:<EOL><INDENT>break<EOL><DEDENT>else:<EOL><INDENT>raise<EOL><DEDENT><DEDENT>except socket.error as err:<EOL><INDENT>if err.args[<NUM_LIT:0>] == errno.EINTR:<EOL><INDENT>continue<EOL><DEDENT>elif err.args[<NUM_LIT:0>] in BLOCKING_ERRORS:<EOL><INDENT>break<EOL><DEDENT>elif err.args[<NUM_LIT:0>] == errno.ECONNRESET:<EOL><INDENT>logger.warning("<STR_LIT>")<EOL>data = None<EOL><DEDENT>else:<EOL><INDENT>raise<EOL><DEDENT><DEDENT>self._feed_reader(data)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>while self._socket and not self._eof:<EOL><INDENT>logger.debug("<STR_LIT>")<EOL>try:<EOL><INDENT>data = self._socket.recv(<NUM_LIT>)<EOL><DEDENT>except socket.error as err:<EOL><INDENT>if err.args[<NUM_LIT:0>] == errno.EINTR:<EOL><INDENT>continue<EOL><DEDENT>elif err.args[<NUM_LIT:0>] in BLOCKING_ERRORS:<EOL><INDENT>break<EOL><DEDENT>elif err.args[<NUM_LIT:0>] == errno.ECONNRESET:<EOL><INDENT>logger.warning("<STR_LIT>")<EOL>data = None<EOL><DEDENT>else:<EOL><INDENT>raise<EOL><DEDENT><DEDENT>self._feed_reader(data)<EOL><DEDENT><DEDENT><DEDENT>
Handle the 'channel readable' state. E.g. read from a socket.