Finish sys/socket POSIX support for Linux.

This commit is contained in:
Isaac Andrade
2024-09-11 22:25:38 -06:00
parent 1632f19826
commit 55a9ba1fc0
+79 -47
View File
@@ -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_controllen: c.size_t, /* [PSX] ancillary data buffer length */
msg_flags: Msg_Flags, /* [PSX] flags on received message */ 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 { } else {
sockaddr_storage :: struct { sockaddr_storage :: struct {
ss_len: c.uint8_t, /* address length */ 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_controllen: socklen_t, /* [PSX] ancillary data buffer length */
msg_flags: Msg_Flags, /* [PSX] flags on received message */ msg_flags: Msg_Flags, /* [PSX] flags on received message */
} }
}
cmsghdr :: struct {
cmsghdr :: struct { cmsg_len: socklen_t, /* [PSX] data byte count, including cmsghdr */
cmsg_len: socklen_t, /* [PSX] data byte count, including cmsghdr */ cmsg_level: c.int, /* [PSX] originating protocol */
cmsg_level: c.int, /* [PSX] originating protocol */ cmsg_type: c.int, /* [PSX] protocol-specific type */
cmsg_type: c.int, /* [PSX] protocol-specific type */ }
} }
SCM_RIGHTS :: 0x01 SCM_RIGHTS :: 0x01
@@ -456,51 +461,78 @@ when ODIN_OS == .Darwin || ODIN_OS == .FreeBSD || ODIN_OS == .NetBSD || ODIN_OS
SOCK_STREAM :: 1 SOCK_STREAM :: 1
// Options to be accessed at socket level, not protocol level. // Options to be accessed at socket level, not protocol level.
SOL_SOCKET :: 0xffff when ODIN_OS == .Linux {
SOL_SOCKET :: 1
SO_ACCEPTCONN :: 0x0002 SO_ACCEPTCONN :: 30
SO_BROADCAST :: 0x0020 SO_BROADCAST :: 6
SO_DEBUG :: 0x0001 SO_DEBUG :: 1
SO_DONTROUTE :: 0x0010 SO_DONTROUTE :: 5
SO_ERROR :: 0x1007 SO_ERROR :: 4
SO_KEEPALIVE :: 0x0008 SO_KEEPALIVE :: 9
SO_OOBINLINE :: 0x0100 SO_OOBINLINE :: 10
SO_RCVBUF :: 0x1002 SO_RCVBUF :: 8
SO_RCVLOWAT :: 0x1004 SO_RCVLOWAT :: 18
SO_REUSEADDR :: 0x0004 SO_REUSEADDR :: 2
SO_SNDBUF :: 0x1001 SO_SNDBUF :: 7
SO_SNDLOWAT :: 0x1003 SO_SNDLOWAT :: 19
SO_TYPE :: 0x1008 SO_TYPE :: 3
SO_LINGER :: 13
when ODIN_OS == .Darwin { SO_RCVTIMEO :: 66
SO_LINGER :: 0x1080 SO_SNDTIMEO :: 67
SO_RCVTIMEO :: 0x1006 } else {
SO_SNDTIMEO :: 0x1005 SOL_SOCKET :: 0xffff
} else when ODIN_OS == .FreeBSD {
SO_LINGER :: 0x0080 SO_ACCEPTCONN :: 0x0002
SO_RCVTIMEO :: 0x1006 SO_BROADCAST :: 0x0020
SO_SNDTIMEO :: 0x1005 SO_DEBUG :: 0x0001
} else when ODIN_OS == .NetBSD { SO_DONTROUTE :: 0x0010
SO_LINGER :: 0x0080 SO_ERROR :: 0x1007
SO_RCVTIMEO :: 0x100c SO_KEEPALIVE :: 0x0008
SO_SNDTIMEO :: 0x100b SO_OOBINLINE :: 0x0100
} else when ODIN_OS == .OpenBSD { SO_RCVBUF :: 0x1002
SO_LINGER :: 0x0080 SO_RCVLOWAT :: 0x1004
SO_RCVTIMEO :: 0x1006 SO_REUSEADDR :: 0x0004
SO_SNDTIMEO :: 0x1005 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(). // The maximum backlog queue length for listen().
SOMAXCONN :: 128 when ODIN_OS == .Linux {
SOMAXCONN :: 4096
} else {
SOMAXCONN :: 128
}
when ODIN_OS == .Linux { when ODIN_OS == .Linux {
MSG_CTRUNC :: 0x007 MSG_CTRUNC :: 0x008
MSG_DONTROUTE :: 0x004 MSG_DONTROUTE :: 0x004
MSG_EOR :: 0x080 MSG_EOR :: 0x080
MSG_OOB :: 0x001 MSG_OOB :: 0x001
MSG_PEEK :: 0x002 MSG_PEEK :: 0x002
MSG_TRUNC :: 0x020 MSG_TRUNC :: 0x020
MSG_WAITALL :: 0x100 MSG_WAITALL :: 0x100
MSG_NOSIGNAL :: 0x4000
} else { } else {
MSG_CTRUNC :: 0x20 MSG_CTRUNC :: 0x20
MSG_DONTROUTE :: 0x4 MSG_DONTROUTE :: 0x4
@@ -509,16 +541,14 @@ when ODIN_OS == .Darwin || ODIN_OS == .FreeBSD || ODIN_OS == .NetBSD || ODIN_OS
MSG_PEEK :: 0x2 MSG_PEEK :: 0x2
MSG_TRUNC :: 0x10 MSG_TRUNC :: 0x10
MSG_WAITALL :: 0x40 MSG_WAITALL :: 0x40
}
when ODIN_OS == .Darwin { when ODIN_OS == .Darwin {
MSG_NOSIGNAL :: 0x80000 MSG_NOSIGNAL :: 0x80000
} else when ODIN_OS == .FreeBSD { } else when ODIN_OS == .FreeBSD {
MSG_NOSIGNAL :: 0x00020000 MSG_NOSIGNAL :: 0x00020000
} else when ODIN_OS == .NetBSD || ODIN_OS == .OpenBSD { } else when ODIN_OS == .NetBSD || ODIN_OS == .OpenBSD {
MSG_NOSIGNAL :: 0x0400 MSG_NOSIGNAL :: 0x0400
} else when ODIN_OS == .Linux { }
MSG_NOSIGNAL :: 0x4000
} }
AF_INET :: 2 AF_INET :: 2
@@ -530,6 +560,8 @@ when ODIN_OS == .Darwin || ODIN_OS == .FreeBSD || ODIN_OS == .NetBSD || ODIN_OS
AF_INET6 :: 28 AF_INET6 :: 28
} else when ODIN_OS == .NetBSD || ODIN_OS == .OpenBSD { } else when ODIN_OS == .NetBSD || ODIN_OS == .OpenBSD {
AF_INET6 :: 24 AF_INET6 :: 24
} else when ODIN_OS == .Linux {
AF_INET6 :: 10
} }
SHUT_RD :: 0 SHUT_RD :: 0