aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIsaac Andrade <andradei@proton.me>2024-09-11 22:25:38 -0600
committerIsaac Andrade <andradei@proton.me>2024-09-11 22:25:38 -0600
commit55a9ba1fc00a68fb83ad0b24878db815e68b546a (patch)
tree7145aed55b976b3693015771f356c5a59b9ec497
parent1632f198265147dcfd9c3a7dc717e5a6647aeff4 (diff)
Finish sys/socket POSIX support for Linux.
-rw-r--r--core/sys/posix/sys_socket.odin130
1 files changed, 81 insertions, 49 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
-
- 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
+ when ODIN_OS == .Linux {
+ SOL_SOCKET :: 1
+
+ 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
+
+ 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