SocketBase.py 文件源码

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

项目:newsreap 作者: caronc 项目源码 文件源码
def can_read(self, timeout=0.0):
        """
        Checks if there is data that can be read from the
        socket (if open). Returns True if there is data and
        False if not.

        It returns None if something very bad happens such as
        a dead connection (bad file descriptor), etc
        """

        # rs = Read Sockets
        # ws = Write Sockets
        # es = Error Sockets
        if self.socket is not None:
            try:
                rs, _, es = select([self.socket], [], [], timeout)
            except (SelectError, socket.error), e:
                if e[0] == errno.EBADF:
                    # Bad File Descriptor... hmm
                    self.close()
                    return None

            if len(es) > 0:
                # Bad File Descriptor
                self.close()
                return None

            return len(rs) > 0

        # no socket or no connection
        return None
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号