aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFeoramund <161657516+Feoramund@users.noreply.github.com>2024-08-05 00:23:11 -0400
committerFeoramund <161657516+Feoramund@users.noreply.github.com>2024-08-05 00:30:39 -0400
commit05c50561aef3272d194e9bfac8c461d988cb0d2a (patch)
tree33428bc04044534831cc200845bf357bf4f9f4b4
parent46455dd0a6aed75b074952dad2c76be54b1094a7 (diff)
Set `NOSIGPIPE` on all `core:net` FreeBSD sockets
-rw-r--r--core/net/socket_freebsd.odin17
1 files changed, 17 insertions, 0 deletions
diff --git a/core/net/socket_freebsd.odin b/core/net/socket_freebsd.odin
index 1cd44db80..579ea90f2 100644
--- a/core/net/socket_freebsd.odin
+++ b/core/net/socket_freebsd.odin
@@ -57,6 +57,23 @@ _create_socket :: proc(family: Address_Family, protocol: Socket_Protocol) -> (so
return
}
+ // NOTE(Feoramund): By default, FreeBSD will generate SIGPIPE if an EPIPE
+ // error is raised during the writing of a socket that may be closed.
+ // This behavior is unlikely to be expected by general users.
+ //
+ // There are two workarounds. One is to apply the .NOSIGNAL flag when using
+ // the `sendto` syscall. However, that would prevent users of this library
+ // from re-enabling the SIGPIPE-raising functionality, if they really
+ // wanted it.
+ //
+ // So I have disabled it here with this socket option for all sockets.
+ truth: b32 = true
+ errno = freebsd.setsockopt(new_socket, .SOCKET, .NOSIGPIPE, &truth, size_of(truth))
+ if errno != nil {
+ err = cast(Socket_Option_Error)errno
+ return
+ }
+
switch protocol {
case .TCP: return cast(TCP_Socket)new_socket, nil
case .UDP: return cast(UDP_Socket)new_socket, nil