def _async_recv_msg(self):
"""Internal use only; use 'recv_msg' with 'yield' instead.
Message is tagged with length of the payload (data). This method
receives length of payload, then the payload and returns the payload.
"""
n = AsyncSocket._MsgLengthSize
try:
data = yield self.recvall(n)
except socket.error as err:
if err.args[0] == 'hangup':
# raise socket.error(errno.EPIPE, 'Insufficient data')
raise StopIteration(b'')
else:
raise
if len(data) != n:
# raise socket.error(errno.EPIPE, 'Insufficient data: %s / %s' % (len(data), n))
raise StopIteration(b'')
n = struct.unpack('>L', data)[0]
# assert n >= 0
if n:
try:
data = yield self.recvall(n)
except socket.error as err:
if err.args[0] == 'hangup':
# raise socket.error(errno.EPIPE, 'Insufficient data')
raise StopIteration(b'')
else:
raise
if len(data) != n:
# raise socket.error(errno.EPIPE, 'Insufficient data: %s / %s' % (len(data), n))
raise StopIteration(b'')
raise StopIteration(data)
else:
raise StopIteration(b'')
评论列表
文章目录