This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def socketpair(family=socket.AF_INET, type=socket.SOCK_STREAM, proto=0): | |
"""Emulate the Unix socketpair() function on Windows.""" | |
# We create a connected TCP socket. Note the trick with setblocking(0) | |
# that prevents us from having to create a thread. | |
lsock = socket.socket(family, type, proto) | |
lsock.bind(('localhost', 0)) | |
lsock.listen(1) | |
addr, port = lsock.getsockname() | |
csock = socket.socket(family, type, proto) | |
csock.setblocking(0) |