connection.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:ave 作者: sonyxperiadev 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号