common_func.py 文件源码

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

项目:passbytcp 作者: mxdg 项目源码 文件源码
def select_recv(conn, buff_size, timeout=None):
    """add timeout for socket.recv()
    :type conn: socket.SocketType
    :type buff_size: int
    :type timeout: float
    :rtype: Union[bytes, None]
    """
    rlist, _, _ = select.select([conn], [], [], timeout)
    if not rlist:
        # timeout
        raise RuntimeError("recv timeout")

    buff = conn.recv(buff_size)
    if not buff:
        raise RuntimeError("received zero bytes, socket was closed")

    return buff
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号