def write(self, payload, timeout=None):
size = len(payload)
done = 0
limit = None
if timeout != None: # first and last test of 'timeout'
limit = time.time() + timeout
while done < size:
try:
done += Connection.write(self, payload[done:])
except ConnectionAgain:
if limit:
timeout == limit - time.time()
else:
timeout = -1
events = self.poll(select.POLLOUT, timeout)
if not events:
raise ConnectionTimeout('write attempt timed out')
if events[0][1] & (select.POLLHUP | select.POLLERR):
raise ConnectionClosed(
'write attempt failed with %d at %d %f'
% (events[0][1], done, timeout)
)
if events[0][1] & select.POLLOUT:
continue
raise Exception('unknown events: %s' % events)
评论列表
文章目录