Return runtime err for EISCONN when connecting

Fixes #25063
This commit is contained in:
Brandon Black 2025-09-03 09:07:32 -05:00 committed by Alex Rønne Petersen
parent 18bdd0e9a4
commit 048f9126b8

View File

@ -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.