#NEWLINE# def _read_to_buffer( self ) : #NEWLINE# #INDENT# 'Reads from the socket and appends the result to the read buffer.\n\n        Returns the number of bytes read.  Returns 0 if there is nothing\n        to read (i.e. the read returns EWOULDBLOCK or equivalent).  On\n        error closes the socket and raises an exception.\n        ' #NEWLINE# try : #NEWLINE# #INDENT# chunk = self . read_from_fd ( ) #NEWLINE# #UNINDENT# except ( socket . error , IOError , OSError ) as e : #NEWLINE# #INDENT# if ( e . args [ 0 ] in _ERRNO_CONNRESET ) : #NEWLINE# #INDENT# self . close ( exc_info = True ) #NEWLINE# return #NEWLINE# #UNINDENT# self . close ( exc_info = True ) #NEWLINE# raise #NEWLINE# #UNINDENT# if ( chunk is None ) : #NEWLINE# #INDENT# return 0 #NEWLINE# #UNINDENT# self . _read_buffer . append ( chunk ) #NEWLINE# self . _read_buffer_size += len ( chunk ) #NEWLINE# if ( self . _read_buffer_size > self . max_buffer_size ) : #NEWLINE# #INDENT# gen_log . error ( 'Reached maximum read buffer size' ) #NEWLINE# self . close ( ) #NEWLINE# raise StreamBufferFullError ( 'Reached maximum read buffer size' ) #NEWLINE# #UNINDENT# return len ( chunk )