parameters: (self)
docstring: Reads data from stream and switch state.
docstring_summary: Reads data from stream and switch state.
docstring_tokens: Reads data from stream and switch state .
function: def read(self):
          """Reads data from stream and switch state."""
          assert self.status in (WAIT_LEN, WAIT_MESSAGE)
          assert not self.received
          buf_size = 8192
          first = True
          done = False
          while not done:
              read = self.socket.recv(buf_size)
              rlen = len(read)
              done = rlen < buf_size
              self._rbuf += read
              if first and rlen == 0:
                  if self.status != WAIT_LEN or self._rbuf:
                      logger.error('could not read frame from socket')
                  else:
                      logger.debug('read zero length. client might have disconnected')
                  self.close()
              while len(self._rbuf) >= self._reading.end:
                  if self._reading.is_header:
                      mlen, = struct.unpack('!i', self._rbuf[:4])
                      self._reading = Message(self._reading.end, mlen, False)
                      self.status = WAIT_MESSAGE
                  else:
                      self._reading.buffer = self._rbuf
                      self.received.append(self._reading)
                      self._rbuf = self._rbuf[self._reading.end:]
                      self._reading = Message(0, 4, True)
              first = False
              if self.received:
                  self.status = WAIT_PROCESS
                  break
          self.remaining = not done
function_tokens: def read ( self ) : assert self . status in ( WAIT_LEN , WAIT_MESSAGE ) assert not self . received buf_size = 8192 first = True done = False while not done : read = self . socket . recv ( buf_size ) rlen = len ( read ) done = rlen < buf_size self . _rbuf += read if first and rlen == 0 : if self . status != WAIT_LEN or self . _rbuf : logger . error ( 'could not read frame from socket' ) else : logger . debug ( 'read zero length. client might have disconnected' ) self . close ( ) while len ( self . _rbuf ) >= self . _reading . end : if self . _reading . is_header : mlen , = struct . unpack ( '!i' , self . _rbuf [ : 4 ] ) self . _reading = Message ( self . _reading . end , mlen , False ) self . status = WAIT_MESSAGE else : self . _reading . buffer = self . _rbuf self . received . append ( self . _reading ) self . _rbuf = self . _rbuf [ self . _reading . end : ] self . _reading = Message ( 0 , 4 , True ) first = False if self . received : self . status = WAIT_PROCESS break self . remaining = not done