'Reads data from stream and switch state.'

@socket_exception
def read(self):

    assert (self.status in (WAIT_LEN, WAIT_MESSAGE))
    if (self.status == WAIT_LEN):
        self._read_len()
    elif (self.status == WAIT_MESSAGE):
        read = self.socket.recv((self.len - len(self.message)))
        if (len(read) == 0):
            logging.error(("can't    read    frame    from    socket    (get    %d    of    %d    bytes)" % (len(self.message), self.len)))
            self.close()
            return
        self.message += read
        if (len(self.message) == self.len):
            self.status = WAIT_PROCESS
