Skip to content
2 changes: 2 additions & 0 deletions Lib/test/test_asyncio/test_base_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -1939,6 +1939,8 @@ def test_create_datagram_endpoint_sock(self):
self.assertEqual('CLOSED', protocol.state)

@unittest.skipUnless(hasattr(socket, 'AF_UNIX'), 'No UNIX Sockets')
@unittest.skipIf(sys.platform == 'win32', 'AF_UNIX support for asyncio is '
'not implemented on Windows for now')
def test_create_datagram_endpoint_sock_unix(self):
fut = self.loop.create_datagram_endpoint(
lambda: MyDatagramProto(create_future=True, loop=self.loop),
Expand Down
5 changes: 5 additions & 0 deletions Lib/test/test_asyncio/test_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -1035,6 +1035,9 @@ def test_create_server_reuse_port(self):
server.close()

def _make_unix_server(self, factory, **kwargs):
if sys.platform == 'win32':
raise unittest.SkipTest('AF_UNIX support for asyncio is not '
'implemented on Windows for now')
path = test_utils.gen_unix_socket_path()
self.addCleanup(lambda: os.path.exists(path) and os.unlink(path))

Expand Down Expand Up @@ -1072,6 +1075,8 @@ def test_create_unix_server(self):
server.close()

@unittest.skipUnless(hasattr(socket, 'AF_UNIX'), 'No UNIX Sockets')
@unittest.skipIf(sys.platform == 'win32', 'AF_UNIX support for asyncio is '
'not implemented on Windows for now')
def test_create_unix_server_path_socket_error(self):
proto = MyProto(loop=self.loop)
sock = socket.socket()
Expand Down
8 changes: 8 additions & 0 deletions Lib/test/test_asyncio/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,8 @@ def app(environ, start_response):
if hasattr(socket, 'AF_UNIX'):

class UnixHTTPServer(socketserver.UnixStreamServer, HTTPServer):
if sys.platform == 'win32':
allow_reuse_address = False

def server_bind(self):
socketserver.UnixStreamServer.server_bind(self)
Expand Down Expand Up @@ -243,6 +245,9 @@ def gen_unix_socket_path():

@contextlib.contextmanager
def unix_socket_path():
if sys.platform == 'win32':
raise unittest.SkipTest('AF_UNIX support for asyncio is not '
'implemented on Windows for now')
path = gen_unix_socket_path()
try:
yield path
Expand All @@ -255,6 +260,9 @@ def unix_socket_path():

@contextlib.contextmanager
def run_test_unix_server(*, use_ssl=False):
if sys.platform == 'win32':
raise unittest.SkipTest('AF_UNIX support for asyncio is not '
'implemented on Windows for now')
with unix_socket_path() as path:
yield from _run_test_server(address=path, use_ssl=use_ssl,
server_cls=SilentUnixWSGIServer,
Expand Down
1 change: 1 addition & 0 deletions Lib/test/test_pathlib/test_pathlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -2747,6 +2747,7 @@ def test_is_socket_false(self):
@unittest.skipIf(
is_wasi, "Cannot create socket on WASI."
)
@unittest.skipIf(sys.platform=='win32', "didn't work on Windows")
def test_is_socket_true(self):
P = self.cls(self.base, 'mysock')
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
Expand Down
6 changes: 5 additions & 1 deletion Lib/test/test_socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -5131,7 +5131,7 @@ def __init__(self, methodName='runTest'):

def _check_defaults(self, sock):
self.assertIsInstance(sock, socket.socket)
if hasattr(socket, 'AF_UNIX'):
if sys.platform != 'win32' and hasattr(socket, 'AF_UNIX'):
self.assertEqual(sock.family, socket.AF_UNIX)
else:
self.assertEqual(sock.family, socket.AF_INET)
Expand Down Expand Up @@ -6188,6 +6188,8 @@ def bind(self, sock, path):
else:
raise

@unittest.skipIf(sys.platform == 'win32',
'Windows will raise Error if is not bound')
def testUnbound(self):
# Issue #30205 (note getsockname() can return None on OS X)
self.assertIn(self.sock.getsockname(), ('', None))
Expand Down Expand Up @@ -6227,6 +6229,8 @@ def testUnencodableAddr(self):

@unittest.skipIf(sys.platform in ('linux', 'android'),
'Linux behavior is tested by TestLinuxAbstractNamespace')
@unittest.skipIf(sys.platform == 'win32',
'Windows allow bind on empty path')
def testEmptyAddress(self):
# Test that binding empty address fails.
self.assertRaises(OSError, self.sock.bind, "")
Expand Down
7 changes: 7 additions & 0 deletions Lib/test/test_socketserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import select
import signal
import socket
import sys
import threading
import unittest
import socketserver
Expand Down Expand Up @@ -218,18 +219,24 @@ def test_ForkingUDPServer(self):
self.dgram_examine)

@requires_unix_sockets
@unittest.skipIf(sys.platform=="win32",
"Unix with Dadagram is not supported on Windows")
def test_UnixDatagramServer(self):
self.run_server(socketserver.UnixDatagramServer,
socketserver.DatagramRequestHandler,
self.dgram_examine)

@requires_unix_sockets
@unittest.skipIf(sys.platform=="win32",
"Unix with Dadagram is not supported on Windows")
def test_ThreadingUnixDatagramServer(self):
self.run_server(socketserver.ThreadingUnixDatagramServer,
socketserver.DatagramRequestHandler,
self.dgram_examine)

@requires_unix_sockets
@unittest.skipIf(sys.platform=="win32",
"Unix with Dadagram is not supported on Windows")
@requires_forking
def test_ForkingUnixDatagramServer(self):
self.run_server(socketserver.ForkingUnixDatagramServer,
Expand Down
1 change: 1 addition & 0 deletions Lib/test/test_stat.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ def test_devices(self):
break

@socket_helper.skip_unless_bind_unix_socket
@unittest.skipIf(sys.platform=='win32', "didn't work on Windows")
def test_socket(self):
with socket.socket(socket.AF_UNIX) as s:
s.bind(TESTFN)
Expand Down
2 changes: 2 additions & 0 deletions Modules/socketmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,8 @@

/* IMPORTANT: make sure the list ordered by descending build_number */
static FlagRuntimeInfo win_runtime_flags[] = {
/* available starting with Windows 10 1803 */
{17134, "AF_UNIX"},
/* available starting with Windows 10 1709 */
{16299, "TCP_KEEPIDLE"},
{16299, "TCP_KEEPINTVL"},
Expand Down Expand Up @@ -1900,7 +1902,7 @@
addr->sun_path[path.len] = 0;

/* including the tailing NUL */
*len_ret = path.len + offsetof(struct sockaddr_un, sun_path) + 1;

Check warning on line 1905 in Modules/socketmodule.c

View workflow job for this annotation

GitHub Actions / Windows / Build and test (x64)

'=': conversion from 'size_t' to 'int', possible loss of data [D:\a\cpython\cpython\PCbuild\_socket.vcxproj]

Check warning on line 1905 in Modules/socketmodule.c

View workflow job for this annotation

GitHub Actions / Windows (free-threading) / Build and test (x64)

'=': conversion from 'size_t' to 'int', possible loss of data [D:\a\cpython\cpython\PCbuild\_socket.vcxproj]

Check warning on line 1905 in Modules/socketmodule.c

View workflow job for this annotation

GitHub Actions / Windows / Build and test (arm64)

'=': conversion from 'size_t' to 'int', possible loss of data [C:\a\cpython\cpython\PCbuild\_socket.vcxproj]

Check warning on line 1905 in Modules/socketmodule.c

View workflow job for this annotation

GitHub Actions / Windows (free-threading) / Build and test (arm64)

'=': conversion from 'size_t' to 'int', possible loss of data [C:\a\cpython\cpython\PCbuild\_socket.vcxproj]
}
addr->sun_family = s->sock_family;
memcpy(addr->sun_path, path.buf, path.len);
Expand Down
3 changes: 3 additions & 0 deletions Modules/socketmodule.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,11 @@ typedef int socklen_t;
# include <hvsocket.h>
#endif /* MS_WINDOWS */

#define HAVE_AFUNIX_H 1
#ifdef HAVE_SYS_UN_H
# include <sys/un.h>
#elif HAVE_AFUNIX_H
# include <afunix.h>
#else
# undef AF_UNIX
#endif
Expand Down
3 changes: 3 additions & 0 deletions PC/pyconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,9 @@ Py_NO_ENABLE_SHARED to find out. Also support MS_NO_COREDLL for b/w compat */
/* Define if you have the <sys/un.h> header file. */
/* #define HAVE_SYS_UN_H 1 */

/* Define if you have the <afunix.h> header file. */
#define HAVE_AFUNIX_H 1

/* Define if you have the <sys/utime.h> header file. */
/* #define HAVE_SYS_UTIME_H 1 */

Expand Down
Loading