diff options
| author | Feoramund <161657516+Feoramund@users.noreply.github.com> | 2024-08-05 00:23:11 -0400 |
|---|---|---|
| committer | Feoramund <161657516+Feoramund@users.noreply.github.com> | 2024-08-05 00:30:39 -0400 |
| commit | 05c50561aef3272d194e9bfac8c461d988cb0d2a (patch) | |
| tree | 33428bc04044534831cc200845bf357bf4f9f4b4 | |
| parent | 46455dd0a6aed75b074952dad2c76be54b1094a7 (diff) | |
Set `NOSIGPIPE` on all `core:net` FreeBSD sockets
| -rw-r--r-- | core/net/socket_freebsd.odin | 17 |
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 |