Skip to content

bpo-33408: Enable AF_UNIX support in Windows#14823

Closed
paulmon wants to merge 2 commits into
python:masterfrom
paulmon:af_unix_on_windows
Closed

bpo-33408: Enable AF_UNIX support in Windows#14823
paulmon wants to merge 2 commits into
python:masterfrom
paulmon:af_unix_on_windows

Conversation

@paulmon

@paulmon paulmon commented Jul 17, 2019

Copy link
Copy Markdown
Contributor

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

Comment thread Lib/socket.py Outdated

# 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
Copy Markdown
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

Comment thread Lib/socket.py
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
Copy Markdown
Member

Choose a reason for hiding this comment

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

Update this message?

Comment thread Lib/socket.py
host = _LOCALHOST_V6
elif family == AF_UNIX:
from uuid import uuid4
host = os.path.join(os.environ['TEMP'], str(uuid4()))

Copy link
Copy Markdown
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
Copy Markdown
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.

Comment thread Lib/socket.py
finally:
lsock.close()
if family == AF_UNIX:
os.unlink(host)

Copy link
Copy Markdown
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 :)

Comment thread Lib/test/test_asyncore.py
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
Copy Markdown
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?

Comment thread Lib/test/test_socket.py
self.assertIn(self.sock.getsockname(), ('', None))
if sys.platform == 'win32':
# Getting the name of unbound socket on Windows
# raises an exception

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

self.dgram_examine)

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

Copy link
Copy Markdown
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
Copy Markdown
Contributor

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

@paulmon

paulmon commented Jan 15, 2020

Copy link
Copy Markdown
Contributor Author

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

AmirHmZz commented Apr 3, 2020

Copy link
Copy Markdown

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