protocol.py 文件源码

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

项目:SameKeyProxy 作者: xzhou 项目源码 文件源码
def __recv_msg_compat(sock,size,timeout):   # compatibility implementation for non-MSG_WAITALL / M2Crypto
    msglen=0
    msglist=[]
    # Receive chunks of max. 60kb size:
    # (rather arbitrary limit, but it avoids memory/buffer problems on certain OSes -- VAX/VMS, Windows)
    while msglen<size:
        chunk=sock.recv(min(60000,size-msglen))
        if not chunk:
            if hasattr(sock,'pending'):
                # m2crypto ssl socket - they have problems with a defaulttimeout
                if socket.getdefaulttimeout() != None:
                    raise ConnectionClosedError("m2crypto SSL can't be used when socket.setdefaulttimeout() has been set")
            err = ConnectionClosedError('connection lost')
            err.partialMsg=''.join(msglist)    # store the message that was received until now
            raise err
        msglist.append(chunk)
        msglen+=len(chunk)
    return ''.join(msglist)


# Send a message over a socket. Raises ConnectionClosedError if the msg
# couldn't be sent (the connection has probably been lost then).
# We need this because 'send' isn't guaranteed to send all desired
# bytes in one call, for instance, when network load is high.
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号