Skip to content

Commit c7e1845

Browse files
committed
[GR-30512] Socket module: add AF_PACKET and AF_UNIX constants.
PullRequest: graalpython/1963
2 parents a70a4e7 + c2ce6e2 commit c7e1845

File tree

15 files changed

+64
-20
lines changed

15 files changed

+64
-20
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/PosixConstants.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,8 @@ public final class PosixConstants {
132132
public static final MandatoryIntConstant AF_UNSPEC;
133133
public static final MandatoryIntConstant AF_INET;
134134
public static final MandatoryIntConstant AF_INET6;
135+
public static final OptionalIntConstant AF_PACKET;
136+
public static final MandatoryIntConstant AF_UNIX;
135137
public static final MandatoryIntConstant SOCK_DGRAM;
136138
public static final MandatoryIntConstant SOCK_STREAM;
137139
public static final MandatoryIntConstant INADDR_ANY;
@@ -354,6 +356,9 @@ public final class PosixConstants {
354356
AF_UNSPEC = reg.createMandatoryInt("AF_UNSPEC");
355357
AF_INET = reg.createMandatoryInt("AF_INET");
356358
AF_INET6 = reg.createMandatoryInt("AF_INET6");
359+
// Following two aren't really supported, but we can fail later:
360+
AF_PACKET = reg.createOptionalInt("AF_PACKET");
361+
AF_UNIX = reg.createMandatoryInt("AF_UNIX");
357362
SOCK_DGRAM = reg.createMandatoryInt("SOCK_DGRAM");
358363
SOCK_STREAM = reg.createMandatoryInt("SOCK_STREAM");
359364
INADDR_ANY = reg.createMandatoryInt("INADDR_ANY");
@@ -483,7 +488,7 @@ public final class PosixConstants {
483488
waitOptions = new IntConstant[]{WNOHANG, WUNTRACED};
484489
accessMode = new IntConstant[]{R_OK, W_OK, X_OK, F_OK};
485490
rtld = new IntConstant[]{RTLD_LAZY, RTLD_NOW, RTLD_GLOBAL, RTLD_LOCAL};
486-
socketFamily = new IntConstant[]{AF_UNSPEC, AF_INET, AF_INET6};
491+
socketFamily = new IntConstant[]{AF_UNSPEC, AF_INET, AF_INET6, AF_PACKET, AF_UNIX};
487492
socketType = new IntConstant[]{SOCK_DGRAM, SOCK_STREAM};
488493
ip4Address = new IntConstant[]{INADDR_ANY, INADDR_BROADCAST, INADDR_NONE, INADDR_LOOPBACK, INADDR_ALLHOSTS_GROUP, INADDR_MAX_LOCAL_GROUP, INADDR_UNSPEC_GROUP};
489494
gaiFlags = new IntConstant[]{AI_PASSIVE, AI_CANONNAME, AI_NUMERICHOST, AI_V4MAPPED, AI_ALL, AI_ADDRCONFIG, AI_IDN, AI_CANONIDN, AI_NUMERICSERV};

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/PosixConstantsDarwin.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ static void getConstants(PosixConstants.Registry constants) {
122122
constants.put("AF_UNSPEC", 0);
123123
constants.put("AF_INET", 2);
124124
constants.put("AF_INET6", 30);
125+
constants.put("AF_UNIX", 1);
125126
constants.put("SOCK_DGRAM", 2);
126127
constants.put("SOCK_STREAM", 1);
127128
constants.put("INADDR_ANY", 0x00000000);

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/PosixConstantsLinux.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ static void getConstants(PosixConstants.Registry constants) {
125125
constants.put("AF_UNSPEC", 0);
126126
constants.put("AF_INET", 2);
127127
constants.put("AF_INET6", 10);
128+
constants.put("AF_PACKET", 17);
129+
constants.put("AF_UNIX", 1);
128130
constants.put("SOCK_DGRAM", 2);
129131
constants.put("SOCK_STREAM", 1);
130132
constants.put("INADDR_ANY", 0x00000000);

graalpython/lib-python/3/multiprocessing/connection.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,11 @@
4747
default_family = 'AF_INET'
4848
families = ['AF_INET']
4949

50-
if hasattr(socket, 'AF_UNIX'):
51-
default_family = 'AF_UNIX'
52-
families += ['AF_UNIX']
50+
# Begin Truffle change
51+
# if hasattr(socket, 'AF_UNIX'):
52+
# default_family = 'AF_UNIX'
53+
# families += ['AF_UNIX']
54+
# End Truffle change
5355

5456
if sys.platform == 'win32':
5557
default_family = 'AF_PIPE'

graalpython/lib-python/3/test/_test_multiprocessing.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3344,7 +3344,9 @@ def test_context(self):
33443344
if self.TYPE == 'processes':
33453345
self.assertRaises(OSError, l.accept)
33463346

3347+
# GR-28433
33473348
@unittest.skipIf(IS_LINUX, "module 'socket' has no attribute 'AF_UNIX'")
3349+
@unittest.skipIf(sys.implementation.name == 'graalpython', "module 'socket' has no attribute 'AF_UNIX'")
33483350
@unittest.skipUnless(util.abstract_sockets_supported,
33493351
"test needs abstract socket support")
33503352
def test_abstract_socket(self):

graalpython/lib-python/3/test/support/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2718,7 +2718,8 @@ def skip_if_pgo_task(test):
27182718
_bind_nix_socket_error = None
27192719
def skip_unless_bind_unix_socket(test):
27202720
"""Decorator for tests requiring a functional bind() for unix sockets."""
2721-
if not hasattr(socket, 'AF_UNIX'):
2721+
# GR-28433
2722+
if (not hasattr(socket, 'AF_UNIX')) or sys.implementation.name == 'graalpython':
27222723
return unittest.skip('No UNIX Sockets')(test)
27232724
global _bind_nix_socket_error
27242725
if _bind_nix_socket_error is None:

graalpython/lib-python/3/test/test_asyncio/functional.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@ def tcp_server(self, server_prog, *,
5454
max_clients=10):
5555

5656
if addr is None:
57-
if hasattr(socket, 'AF_UNIX') and family == socket.AF_UNIX:
57+
# GR-28433
58+
import sys
59+
if hasattr(socket, 'AF_UNIX') and family == socket.AF_UNIX and sys.implementation.name != 'graalpython':
5860
with tempfile.NamedTemporaryFile() as tmp:
5961
addr = tmp.name
6062
else:

graalpython/lib-python/3/test/test_asyncio/test_base_events.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1683,6 +1683,7 @@ def test_create_datagram_endpoint_sock(self):
16831683
self.loop.run_until_complete(protocol.done)
16841684
self.assertEqual('CLOSED', protocol.state)
16851685

1686+
@unittest.skipIf(sys.implementation.name == 'graalpython', 'GR-28433')
16861687
@unittest.skipUnless(hasattr(socket, 'AF_UNIX'), 'No UNIX Sockets')
16871688
def test_create_datagram_endpoint_sock_unix(self):
16881689
fut = self.loop.create_datagram_endpoint(

graalpython/lib-python/3/test/test_asyncio/test_events.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -868,6 +868,7 @@ def test_create_unix_server(self):
868868
# close server
869869
server.close()
870870

871+
@unittest.skipIf(sys.implementation.name == 'graalpython', 'GR-28433')
871872
@unittest.skipUnless(hasattr(socket, 'AF_UNIX'), 'No UNIX Sockets')
872873
def test_create_unix_server_path_socket_error(self):
873874
proto = MyProto(loop=self.loop)

graalpython/lib-python/3/test/test_asyncio/test_unix_events.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ def test_close_on_finalizing(self, m_signal, m_sys):
264264
self.assertFalse(m_signal.signal.called)
265265

266266

267+
@unittest.skipIf(sys.implementation.name == 'graalpython', 'GR-28433')
267268
@unittest.skipUnless(hasattr(socket, 'AF_UNIX'),
268269
'UNIX Sockets are not supported')
269270
class SelectorEventLoopUnixSocketTests(test_utils.TestCase):

0 commit comments

Comments
 (0)