aboutsummaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorFeoramund <161657516+Feoramund@users.noreply.github.com>2024-08-05 12:23:09 -0400
committerFeoramund <161657516+Feoramund@users.noreply.github.com>2024-08-05 12:23:09 -0400
commiteba0774bf3bd2b89ca64f6851d465cb74559005c (patch)
treea5a1d8c21ef57c09ddd1fc285303b34dd422caa9 /core
parent7c3461b0df6020ab20017d0eaca990a60fc9e8b1 (diff)
Prevent `SIGPIPE` on Darwin when writing to a closed `core:net` socket
Mimics behavior found on Linux implementation.
Diffstat (limited to 'core')
-rw-r--r--core/net/socket_darwin.odin8
1 files changed, 6 insertions, 2 deletions
diff --git a/core/net/socket_darwin.odin b/core/net/socket_darwin.odin
index 10069963a..83280cad9 100644
--- a/core/net/socket_darwin.odin
+++ b/core/net/socket_darwin.odin
@@ -35,6 +35,10 @@ Socket_Option :: enum c.int {
Send_Timeout = c.int(os.SO_SNDTIMEO),
}
+// https://github.com/apple/darwin-xnu/blob/2ff845c2e033bd0ff64b5b6aa6063a1f8f65aa32/bsd/sys/socket.h#L1025-L1027
+// Prevent the raising of SIGPIPE on writing to a closed network socket.
+@private MSG_NOSIGNAL :: 0x80000
+
@(private)
_create_socket :: proc(family: Address_Family, protocol: Socket_Protocol) -> (socket: Any_Socket, err: Network_Error) {
c_type, c_protocol, c_family: int
@@ -194,7 +198,7 @@ _send_tcp :: proc(skt: TCP_Socket, buf: []byte) -> (bytes_written: int, err: Net
for bytes_written < len(buf) {
limit := min(int(max(i32)), len(buf) - bytes_written)
remaining := buf[bytes_written:][:limit]
- res, res_err := os.send(os.Socket(skt), remaining, 0)
+ res, res_err := os.send(os.Socket(skt), remaining, MSG_NOSIGNAL)
if res_err != nil {
err = TCP_Send_Error(os.is_platform_error(res_err) or_else -1)
return
@@ -210,7 +214,7 @@ _send_udp :: proc(skt: UDP_Socket, buf: []byte, to: Endpoint) -> (bytes_written:
for bytes_written < len(buf) {
limit := min(1<<31, len(buf) - bytes_written)
remaining := buf[bytes_written:][:limit]
- res, res_err := os.sendto(os.Socket(skt), remaining, 0, cast(^os.SOCKADDR)&toaddr, i32(toaddr.len))
+ res, res_err := os.sendto(os.Socket(skt), remaining, MSG_NOSIGNAL, cast(^os.SOCKADDR)&toaddr, i32(toaddr.len))
if res_err != nil {
err = UDP_Send_Error(os.is_platform_error(res_err) or_else -1)
return