From 55a9ba1fc00a68fb83ad0b24878db815e68b546a Mon Sep 17 00:00:00 2001 From: Isaac Andrade Date: Wed, 11 Sep 2024 22:25:38 -0600 Subject: [PATCH] Finish sys/socket POSIX support for Linux. --- core/sys/posix/sys_socket.odin | 126 +++++++++++++++++++++------------ 1 file changed, 79 insertions(+), 47 deletions(-) diff --git a/core/sys/posix/sys_socket.odin b/core/sys/posix/sys_socket.odin index 1f228c396..185bb7722 100644 --- a/core/sys/posix/sys_socket.odin +++ b/core/sys/posix/sys_socket.odin @@ -382,6 +382,12 @@ when ODIN_OS == .Darwin || ODIN_OS == .FreeBSD || ODIN_OS == .NetBSD || ODIN_OS msg_controllen: c.size_t, /* [PSX] ancillary data buffer length */ msg_flags: Msg_Flags, /* [PSX] flags on received message */ } + + cmsghdr :: struct { + cmsg_len: c.size_t, /* [PSX] data byte count, including cmsghdr */ + cmsg_level: c.int, /* [PSX] originating protocol */ + cmsg_type: c.int, /* [PSX] protocol-specific type */ + } } else { sockaddr_storage :: struct { ss_len: c.uint8_t, /* address length */ @@ -400,13 +406,12 @@ when ODIN_OS == .Darwin || ODIN_OS == .FreeBSD || ODIN_OS == .NetBSD || ODIN_OS msg_controllen: socklen_t, /* [PSX] ancillary data buffer length */ msg_flags: Msg_Flags, /* [PSX] flags on received message */ } - } - - cmsghdr :: struct { - cmsg_len: socklen_t, /* [PSX] data byte count, including cmsghdr */ - cmsg_level: c.int, /* [PSX] originating protocol */ - cmsg_type: c.int, /* [PSX] protocol-specific type */ + cmsghdr :: struct { + cmsg_len: socklen_t, /* [PSX] data byte count, including cmsghdr */ + cmsg_level: c.int, /* [PSX] originating protocol */ + cmsg_type: c.int, /* [PSX] protocol-specific type */ + } } SCM_RIGHTS :: 0x01 @@ -456,51 +461,78 @@ when ODIN_OS == .Darwin || ODIN_OS == .FreeBSD || ODIN_OS == .NetBSD || ODIN_OS SOCK_STREAM :: 1 // Options to be accessed at socket level, not protocol level. - SOL_SOCKET :: 0xffff + when ODIN_OS == .Linux { + SOL_SOCKET :: 1 - SO_ACCEPTCONN :: 0x0002 - SO_BROADCAST :: 0x0020 - SO_DEBUG :: 0x0001 - SO_DONTROUTE :: 0x0010 - SO_ERROR :: 0x1007 - SO_KEEPALIVE :: 0x0008 - SO_OOBINLINE :: 0x0100 - SO_RCVBUF :: 0x1002 - SO_RCVLOWAT :: 0x1004 - SO_REUSEADDR :: 0x0004 - SO_SNDBUF :: 0x1001 - SO_SNDLOWAT :: 0x1003 - SO_TYPE :: 0x1008 + SO_ACCEPTCONN :: 30 + SO_BROADCAST :: 6 + SO_DEBUG :: 1 + SO_DONTROUTE :: 5 + SO_ERROR :: 4 + SO_KEEPALIVE :: 9 + SO_OOBINLINE :: 10 + SO_RCVBUF :: 8 + SO_RCVLOWAT :: 18 + SO_REUSEADDR :: 2 + SO_SNDBUF :: 7 + SO_SNDLOWAT :: 19 + SO_TYPE :: 3 + SO_LINGER :: 13 - when ODIN_OS == .Darwin { - SO_LINGER :: 0x1080 - SO_RCVTIMEO :: 0x1006 - SO_SNDTIMEO :: 0x1005 - } else when ODIN_OS == .FreeBSD { - SO_LINGER :: 0x0080 - SO_RCVTIMEO :: 0x1006 - SO_SNDTIMEO :: 0x1005 - } else when ODIN_OS == .NetBSD { - SO_LINGER :: 0x0080 - SO_RCVTIMEO :: 0x100c - SO_SNDTIMEO :: 0x100b - } else when ODIN_OS == .OpenBSD { - SO_LINGER :: 0x0080 - SO_RCVTIMEO :: 0x1006 - SO_SNDTIMEO :: 0x1005 + SO_RCVTIMEO :: 66 + SO_SNDTIMEO :: 67 + } else { + SOL_SOCKET :: 0xffff + + SO_ACCEPTCONN :: 0x0002 + SO_BROADCAST :: 0x0020 + SO_DEBUG :: 0x0001 + SO_DONTROUTE :: 0x0010 + SO_ERROR :: 0x1007 + SO_KEEPALIVE :: 0x0008 + SO_OOBINLINE :: 0x0100 + SO_RCVBUF :: 0x1002 + SO_RCVLOWAT :: 0x1004 + SO_REUSEADDR :: 0x0004 + SO_SNDBUF :: 0x1001 + SO_SNDLOWAT :: 0x1003 + SO_TYPE :: 0x1008 + + when ODIN_OS == .Darwin { + SO_LINGER :: 0x1080 + SO_RCVTIMEO :: 0x1006 + SO_SNDTIMEO :: 0x1005 + } else when ODIN_OS == .FreeBSD { + SO_LINGER :: 0x0080 + SO_RCVTIMEO :: 0x1006 + SO_SNDTIMEO :: 0x1005 + } else when ODIN_OS == .NetBSD { + SO_LINGER :: 0x0080 + SO_RCVTIMEO :: 0x100c + SO_SNDTIMEO :: 0x100b + } else when ODIN_OS == .OpenBSD { + SO_LINGER :: 0x0080 + SO_RCVTIMEO :: 0x1006 + SO_SNDTIMEO :: 0x1005 + } } // The maximum backlog queue length for listen(). - SOMAXCONN :: 128 + when ODIN_OS == .Linux { + SOMAXCONN :: 4096 + } else { + SOMAXCONN :: 128 + } when ODIN_OS == .Linux { - MSG_CTRUNC :: 0x007 + MSG_CTRUNC :: 0x008 MSG_DONTROUTE :: 0x004 MSG_EOR :: 0x080 MSG_OOB :: 0x001 MSG_PEEK :: 0x002 MSG_TRUNC :: 0x020 MSG_WAITALL :: 0x100 + MSG_NOSIGNAL :: 0x4000 } else { MSG_CTRUNC :: 0x20 MSG_DONTROUTE :: 0x4 @@ -509,16 +541,14 @@ when ODIN_OS == .Darwin || ODIN_OS == .FreeBSD || ODIN_OS == .NetBSD || ODIN_OS MSG_PEEK :: 0x2 MSG_TRUNC :: 0x10 MSG_WAITALL :: 0x40 - } - when ODIN_OS == .Darwin { - MSG_NOSIGNAL :: 0x80000 - } else when ODIN_OS == .FreeBSD { - MSG_NOSIGNAL :: 0x00020000 - } else when ODIN_OS == .NetBSD || ODIN_OS == .OpenBSD { - MSG_NOSIGNAL :: 0x0400 - } else when ODIN_OS == .Linux { - MSG_NOSIGNAL :: 0x4000 + when ODIN_OS == .Darwin { + MSG_NOSIGNAL :: 0x80000 + } else when ODIN_OS == .FreeBSD { + MSG_NOSIGNAL :: 0x00020000 + } else when ODIN_OS == .NetBSD || ODIN_OS == .OpenBSD { + MSG_NOSIGNAL :: 0x0400 + } } AF_INET :: 2 @@ -530,6 +560,8 @@ when ODIN_OS == .Darwin || ODIN_OS == .FreeBSD || ODIN_OS == .NetBSD || ODIN_OS AF_INET6 :: 28 } else when ODIN_OS == .NetBSD || ODIN_OS == .OpenBSD { AF_INET6 :: 24 + } else when ODIN_OS == .Linux { + AF_INET6 :: 10 } SHUT_RD :: 0