def recv(self):
<EOL>if self._recvbuf:<EOL><INDENT>return self._recvbuf_pop()<EOL><DEDENT>if not self._sock:<EOL><INDENT>raise ConnectionClosed("<STR_LIT>")<EOL><DEDENT>while True:<EOL><INDENT>try:<EOL><INDENT>data = self._sock.recv(<NUM_LIT>)<EOL><DEDENT>except socket.error:<EOL><INDENT>e_type, e_value, e_tb = sys.exc_info()<EOL>self.close()<EOL>raise e_type(e_value).with_traceback(e_tb)<EOL><DEDENT>if not data:<EOL><INDENT>self.close()<EOL>raise ConnectionClosed("<STR_LIT>")<EOL><DEDENT>partial = self._recvbuf_partial + data<EOL>self._recvbuf_partial = '<STR_LIT>'<EOL>while partial:<EOL><INDENT>msg, sep, partial = partial.partition('<STR_LIT:\n>')<EOL>if not sep:<EOL><INDENT>self._recvbuf_partial = msg<EOL>break<EOL><DEDENT>try:<EOL><INDENT>self._recvbuf.append(json.loads(msg))<EOL><DEDENT>except ValueError as exc:<EOL><INDENT>self._recvbuf.append(exc)<EOL><DEDENT><DEDENT>if self._recvbuf:<EOL><INDENT>return self._recvbuf_pop()<EOL><DEDENT><DEDENT>
Receive a message from the other end.  Returns a tuple of the
command (a string) and payload (a list).