Skip to content

Commit 0003a02

Browse files
committed
Add unix domain socket for Windows
1 parent 801cf3f commit 0003a02

4 files changed

Lines changed: 13 additions & 1 deletion

File tree

Lib/test/test_socket.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5131,7 +5131,7 @@ def __init__(self, methodName='runTest'):
51315131

51325132
def _check_defaults(self, sock):
51335133
self.assertIsInstance(sock, socket.socket)
5134-
if hasattr(socket, 'AF_UNIX'):
5134+
if sys.platform != 'win32' and hasattr(socket, 'AF_UNIX'):
51355135
self.assertEqual(sock.family, socket.AF_UNIX)
51365136
else:
51375137
self.assertEqual(sock.family, socket.AF_INET)
@@ -6188,6 +6188,8 @@ def bind(self, sock, path):
61886188
else:
61896189
raise
61906190

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

62286230
@unittest.skipIf(sys.platform in ('linux', 'android'),
62296231
'Linux behavior is tested by TestLinuxAbstractNamespace')
6232+
@unittest.skipIf(sys.platform == 'win32',
6233+
'Windows allow bind on empty path')
62306234
def testEmptyAddress(self):
62316235
# Test that binding empty address fails.
62326236
self.assertRaises(OSError, self.sock.bind, "")

Modules/socketmodule.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,8 @@ typedef struct {
334334

335335
/* IMPORTANT: make sure the list ordered by descending build_number */
336336
static FlagRuntimeInfo win_runtime_flags[] = {
337+
/* available starting with Windows 10 1803 */
338+
{17134, "AF_UNIX"},
337339
/* available starting with Windows 10 1709 */
338340
{16299, "TCP_KEEPIDLE"},
339341
{16299, "TCP_KEEPINTVL"},

Modules/socketmodule.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,11 @@ typedef int socklen_t;
9494
# include <hvsocket.h>
9595
#endif /* MS_WINDOWS */
9696

97+
#define HAVE_AFUNIX_H 1
9798
#ifdef HAVE_SYS_UN_H
9899
# include <sys/un.h>
100+
#elif HAVE_AFUNIX_H
101+
# include <afunix.h>
99102
#else
100103
# undef AF_UNIX
101104
#endif

PC/pyconfig.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -671,6 +671,9 @@ Py_NO_ENABLE_SHARED to find out. Also support MS_NO_COREDLL for b/w compat */
671671
/* Define if you have the <sys/un.h> header file. */
672672
/* #define HAVE_SYS_UN_H 1 */
673673

674+
/* Define if you have the <afunix.h> header file. */
675+
#define HAVE_AFUNIX_H 1
676+
674677
/* Define if you have the <sys/utime.h> header file. */
675678
/* #define HAVE_SYS_UTIME_H 1 */
676679

0 commit comments

Comments
 (0)