Commit 048f9126b8

Brandon Black <bblack@wikimedia.org>
2025-09-03 16:07:32
Return runtime err for EISCONN when connecting
Fixes #25063
1 parent 18bdd0e
Changed files (1)
lib
lib/std/posix.zig
@@ -4285,6 +4285,9 @@ pub const ConnectError = error{
 
     /// Socket is non-blocking and already has a pending connection in progress.
     ConnectionPending,
+
+    /// Socket was already connected
+    AlreadyConnected,
 } || UnexpectedError;
 
 /// Initiate a connection on a socket.
@@ -4305,7 +4308,7 @@ pub fn connect(sock: socket_t, sock_addr: *const sockaddr, len: socklen_t) Conne
             => return error.NetworkUnreachable,
             .WSAEFAULT => unreachable,
             .WSAEINVAL => unreachable,
-            .WSAEISCONN => unreachable,
+            .WSAEISCONN => return error.AlreadyConnected,
             .WSAENOTSOCK => unreachable,
             .WSAEWOULDBLOCK => return error.WouldBlock,
             .WSAEACCES => unreachable,
@@ -4331,7 +4334,7 @@ pub fn connect(sock: socket_t, sock_addr: *const sockaddr, len: socklen_t) Conne
             .CONNRESET => return error.ConnectionResetByPeer,
             .FAULT => unreachable, // The socket structure address is outside the user's address space.
             .INTR => continue,
-            .ISCONN => unreachable, // The socket is already connected.
+            .ISCONN => return error.AlreadyConnected, // The socket is already connected.
             .HOSTUNREACH => return error.NetworkUnreachable,
             .NETUNREACH => return error.NetworkUnreachable,
             .NOTSOCK => unreachable, // The file descriptor sockfd does not refer to a socket.
@@ -4391,7 +4394,7 @@ pub fn getsockoptError(sockfd: fd_t) ConnectError!void {
             .BADF => unreachable, // sockfd is not a valid open file descriptor.
             .CONNREFUSED => return error.ConnectionRefused,
             .FAULT => unreachable, // The socket structure address is outside the user's address space.
-            .ISCONN => unreachable, // The socket is already connected.
+            .ISCONN => return error.AlreadyConnected, // The socket is already connected.
             .HOSTUNREACH => return error.NetworkUnreachable,
             .NETUNREACH => return error.NetworkUnreachable,
             .NOTSOCK => unreachable, // The file descriptor sockfd does not refer to a socket.