From 4c0ab09c9a88ae644b4b6ecd0a5b541428b0be24 Mon Sep 17 00:00:00 2001 From: Feoramund <161657516+Feoramund@users.noreply.github.com> Date: Mon, 5 Aug 2024 12:51:56 -0400 Subject: [PATCH] Handle `EPIPE` in Darwin `core:net` --- core/net/socket_darwin.odin | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/core/net/socket_darwin.odin b/core/net/socket_darwin.odin index 83c627423..ba369810b 100644 --- a/core/net/socket_darwin.odin +++ b/core/net/socket_darwin.odin @@ -195,7 +195,11 @@ _send_tcp :: proc(skt: TCP_Socket, buf: []byte) -> (bytes_written: int, err: Net limit := min(int(max(i32)), len(buf) - bytes_written) remaining := buf[bytes_written:][:limit] res, res_err := os.send(os.Socket(skt), remaining, os.MSG_NOSIGNAL) - if res_err != nil { + if res_err == os.EPIPE { + // EPIPE arises if the socket has been closed remotely. + err = TCP_Send_Error.Connection_Closed + return + } else if res_err != nil { err = TCP_Send_Error(os.is_platform_error(res_err) or_else -1) return } @@ -211,7 +215,11 @@ _send_udp :: proc(skt: UDP_Socket, buf: []byte, to: Endpoint) -> (bytes_written: limit := min(1<<31, len(buf) - bytes_written) remaining := buf[bytes_written:][:limit] res, res_err := os.sendto(os.Socket(skt), remaining, os.MSG_NOSIGNAL, cast(^os.SOCKADDR)&toaddr, i32(toaddr.len)) - if res_err != nil { + if res_err == os.EPIPE { + // EPIPE arises if the socket has been closed remotely. + err = UDP_Send_Error.Not_Socket + return + } else if res_err != nil { err = UDP_Send_Error(os.is_platform_error(res_err) or_else -1) return }