Browse Source

feat(net): turn `EPIPE` into `Connection_Closed`

Rickard Andersson 1 year ago
parent
commit
7b95562827
2 changed files with 3 additions and 2 deletions
  1. 0 1
      core/net/errors_linux.odin
  2. 3 1
      core/net/socket_linux.odin

+ 0 - 1
core/net/errors_linux.odin

@@ -136,7 +136,6 @@ TCP_Send_Error :: enum c.int {
 	Interrupted               = c.int(linux.Errno.EINTR),        // A signal occurred before any data was transmitted. See signal(7).
 	Interrupted               = c.int(linux.Errno.EINTR),        // A signal occurred before any data was transmitted. See signal(7).
 	Timeout                   = c.int(linux.Errno.EWOULDBLOCK),  // The send timeout duration passed before all data was sent. See Socket_Option.Send_Timeout.
 	Timeout                   = c.int(linux.Errno.EWOULDBLOCK),  // The send timeout duration passed before all data was sent. See Socket_Option.Send_Timeout.
 	Not_Socket                = c.int(linux.Errno.ENOTSOCK),     // The so-called socket is not an open socket.
 	Not_Socket                = c.int(linux.Errno.ENOTSOCK),     // The so-called socket is not an open socket.
-	Broken_Pipe               = c.int(linux.Errno.EPIPE),        // The peer has disconnected when we are trying to send to it
 }
 }
 
 
 // TODO
 // TODO

+ 3 - 1
core/net/socket_linux.odin

@@ -259,7 +259,9 @@ _send_tcp :: proc(tcp_sock: TCP_Socket, buf: []byte) -> (int, Network_Error) {
 		limit := min(int(max(i32)), len(buf) - total_written)
 		limit := min(int(max(i32)), len(buf) - total_written)
 		remaining := buf[total_written:][:limit]
 		remaining := buf[total_written:][:limit]
 		res, errno := linux.send(linux.Fd(tcp_sock), remaining, {.NOSIGNAL})
 		res, errno := linux.send(linux.Fd(tcp_sock), remaining, {.NOSIGNAL})
-		if errno != .NONE {
+		if errno == .EPIPE {
+			return total_written, TCP_Send_Error.Connection_Closed
+		} else if errno != .NONE {
 			return total_written, TCP_Send_Error(errno)
 			return total_written, TCP_Send_Error(errno)
 		}
 		}
 		total_written += int(res)
 		total_written += int(res)