-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
bpo-33408: Enable AF_UNIX support in Windows #14823
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -494,11 +494,19 @@ def socketpair(family=None, type=SOCK_STREAM, proto=0): | |
else: | ||
|
||
# Origin: https://gist.github.com/4325783, by Geert Jansen. Public domain. | ||
def socketpair(family=AF_INET, type=SOCK_STREAM, proto=0): | ||
def socketpair(family=None, type=SOCK_STREAM, proto=0): | ||
if family is None: | ||
try: | ||
family = AF_UNIX | ||
except NameError: | ||
family = AF_INET | ||
if family == AF_INET: | ||
host = _LOCALHOST | ||
elif family == AF_INET6: | ||
host = _LOCALHOST_V6 | ||
elif family == AF_UNIX: | ||
from uuid import uuid4 | ||
host = os.path.join(os.environ['TEMP'], str(uuid4())) | ||
else: | ||
raise ValueError("Only AF_INET and AF_INET6 socket address families " | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Update this message? |
||
"are supported") | ||
|
@@ -511,15 +519,21 @@ def socketpair(family=AF_INET, type=SOCK_STREAM, proto=0): | |
# setblocking(False) that prevents us from having to create a thread. | ||
lsock = socket(family, type, proto) | ||
try: | ||
lsock.bind((host, 0)) | ||
if family == AF_UNIX: | ||
lsock.bind(host) | ||
else: | ||
lsock.bind((host, 0)) | ||
lsock.listen() | ||
# On IPv6, ignore flow_info and scope_id | ||
addr, port = lsock.getsockname()[:2] | ||
csock = socket(family, type, proto) | ||
try: | ||
csock.setblocking(False) | ||
try: | ||
csock.connect((addr, port)) | ||
if family == AF_UNIX: | ||
csock.connect(host) | ||
else: | ||
csock.connect((addr, port)) | ||
except (BlockingIOError, InterruptedError): | ||
pass | ||
csock.setblocking(True) | ||
|
@@ -529,6 +543,8 @@ def socketpair(family=AF_INET, type=SOCK_STREAM, proto=0): | |
raise | ||
finally: | ||
lsock.close() | ||
if family == AF_UNIX: | ||
os.unlink(host) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I don't like this at all :) |
||
return (ssock, csock) | ||
__all__.append("socketpair") | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -469,7 +469,12 @@ class BaseServer(asyncore.dispatcher): | |
def __init__(self, family, addr, handler=BaseTestHandler): | ||
asyncore.dispatcher.__init__(self) | ||
self.create_socket(family) | ||
self.set_reuse_addr() | ||
if sys.platform == 'win32' and family == socket.AF_UNIX: | ||
# calling set_reuse_addr() on Windows with family AF_UNIX results in: | ||
# OSError: [WinError 10045] The attempted operation is not supported for the type of object referenced | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
pass | ||
else: | ||
self.set_reuse_addr() | ||
bind_af_aware(self.socket, addr) | ||
self.listen(5) | ||
self.handler = handler | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5276,8 +5276,14 @@ def bind(self, sock, path): | |
raise | ||
|
||
def testUnbound(self): | ||
# Issue #30205 (note getsockname() can return None on OS X) | ||
self.assertIn(self.sock.getsockname(), ('', None)) | ||
if sys.platform == 'win32': | ||
# Getting the name of unbound socket on Windows | ||
# raises an exception | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this make more sense than returning |
||
self.assertRaises(OSError, self.sock.getsockname) | ||
else: | ||
# Issue #30205 (note getsockname() can return None on OS X) | ||
name = self.sock.getsockname() | ||
self.assertIn(name, ('', None)) | ||
|
||
def testStrAddr(self): | ||
# Test binding to and retrieving a normal string pathname. | ||
|
@@ -5293,6 +5299,7 @@ def testBytesAddr(self): | |
self.addCleanup(support.unlink, path) | ||
self.assertEqual(self.sock.getsockname(), path) | ||
|
||
@unittest.skipIf(sys.platform == 'win32', "ASCII path name required on Windows") | ||
def testSurrogateescapeBind(self): | ||
# Test binding to a valid non-ASCII pathname, with the | ||
# non-ASCII bytes supplied using surrogateescape encoding. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
import select | ||
import signal | ||
import socket | ||
import sys | ||
import tempfile | ||
import threading | ||
import unittest | ||
|
@@ -232,12 +233,14 @@ def test_ForkingUDPServer(self): | |
self.dgram_examine) | ||
|
||
@requires_unix_sockets | ||
@unittest.skipIf(sys.platform == 'win32', "no datagram support") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm seeing a lot of these - is there any more specific way to detect datagram support? The socket module already has a number of conditional constants, so maybe one of those will help? |
||
def test_UnixDatagramServer(self): | ||
self.run_server(socketserver.UnixDatagramServer, | ||
socketserver.DatagramRequestHandler, | ||
self.dgram_examine) | ||
|
||
@requires_unix_sockets | ||
@unittest.skipIf(sys.platform == 'win32', "no datagram support") | ||
def test_ThreadingUnixDatagramServer(self): | ||
self.run_server(socketserver.ThreadingUnixDatagramServer, | ||
socketserver.DatagramRequestHandler, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm really not a fan of this - can we use unnamed sockets instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Abstract sockets (starting from NULL in the name) is another options.
Web says that Windows supports it.