Skip to content
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

bpo-33408: Enable AF_UNIX support in Windows #14823

Closed
wants to merge 2 commits into from

Conversation

paulmon
Copy link
Contributor

@paulmon paulmon commented Jul 17, 2019

These changes are incomplete, but this seems like a good point to get feedback on what I've learned so far.

Tests in test_asyncio are failing because create_unix_server and create_unix_connection are not implemented for Windows on the ProactorEventLoop class.

Linux implements create_unix_server and create_unix_connection on the _UnixEventSelectorLoop class, and the implementation cannot be simply copied because Linux uses signals, which don't exist for Windows. Windows appears to uses IO completion ports to achieve the same results.

https://bugs.python.org/issue33408

Lib/socket.py Outdated
@@ -494,11 +494,14 @@ 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=AF_UNIX, type=SOCK_STREAM, proto=0):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This causes test failures in appveyor and Azure Pipelines. Must be refactored

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 "
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update this message?

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()))
Copy link
Member

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?

Copy link
Contributor

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.

@@ -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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I don't like this at all :)

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

set_reuse_addr seems to handle all OSError silently - why do we need to skip it here?

self.assertIn(self.sock.getsockname(), ('', None))
if sys.platform == 'win32':
# Getting the name of unbound socket on Windows
# raises an exception
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this make more sense than returning None? Which is apparently a valid return value

@@ -232,12 +233,14 @@ def test_ForkingUDPServer(self):
self.dgram_examine)

@requires_unix_sockets
@unittest.skipIf(sys.platform == 'win32', "no datagram support")
Copy link
Member

Choose a reason for hiding this comment

The 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?

@csabella
Copy link
Contributor

@paulmon, please address the code reviews and resolve the merge conflict. Thank you!

@paulmon
Copy link
Contributor Author

paulmon commented Jan 15, 2020

I don't currently have time to follow up on this PR or the immediate need for AF_UNIX in Windows

@paulmon paulmon closed this Jan 15, 2020
@AmirHmZz
Copy link

AmirHmZz commented Apr 3, 2020

Will python support AF_UNIX on windows ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants