Commit a0289d0cce

Nikolay Govorov <me@govorov.online>
2025-11-18 19:15:22
std.posix.accept: handle non-listening socket EINVAL
1 parent 7d9ad99
Changed files (2)
lib/std/Io/net.zig
@@ -1333,6 +1333,10 @@ pub const Server = struct {
         /// Not enough free memory. This often means that the memory allocation is limited
         /// by the socket buffer limits, not by the system memory.
         SystemResources,
+        /// Either `listen` was never called, or `shutdown` was called (possibly while
+        /// this call was blocking). This allows `shutdown` to be used as a concurrent
+        /// cancellation mechanism.
+        SocketNotListening,
         /// The network subsystem has failed.
         NetworkDown,
         /// No connection is already queued and ready to be accepted, and
lib/std/Io/Threaded.zig
@@ -3900,7 +3900,7 @@ fn netAcceptPosix(userdata: ?*anyopaque, listen_fd: net.Socket.Handle) net.Serve
             .BADF => |err| return errnoBug(err), // File descriptor used after closed.
             .CONNABORTED => return error.ConnectionAborted,
             .FAULT => |err| return errnoBug(err),
-            .INVAL => |err| return errnoBug(err),
+            .INVAL => return error.SocketNotListening,
             .NOTSOCK => |err| return errnoBug(err),
             .MFILE => return error.ProcessFdQuotaExceeded,
             .NFILE => return error.SystemFdQuotaExceeded,