def connect(self, timeout=None, optimist=False):
if timeout != None:
limit = time.time() + timeout
while True:
if timeout != None and time.time() > limit:
raise ConnectionTimeout('connection attempt timed out')
try:
Connection.connect(self)
except ConnectionInProgress:
if timeout == None:
events = self.poll(select.POLLOUT, -1)
else:
events = self.poll(select.POLLOUT, timeout)
if not events:
raise ConnectionTimeout('connection attempt timed out')
if events[0][1] & (select.POLLERR | select.POLLHUP):
if optimist:
time.sleep(0.1)
continue
raise ConnectionRefused()
if events[0][1] & select.POLLOUT:
e = self.socket.getsockopt(socket.SOL_SOCKET, socket.SO_ERROR)
if e == errno.ECONNREFUSED:
raise ConnectionRefused()
return
return # good
评论列表
文章目录