Commit 0134cb0214

Jonathan Marler <johnnymarler@gmail.com>
2021-06-22 16:05:18
nice error for unsupported async sockets on Windows
1 parent 29945fb
Changed files (2)
lib
std
event
test
lib/std/event/loop.zig
@@ -894,7 +894,7 @@ pub const Loop = struct {
         self: *Loop,
         /// This argument is a socket that has been created with `socket`, bound to a local address
         /// with `bind`, and is listening for connections after a `listen`.
-        sockfd: os.fd_t,
+        sockfd: os.socket_t,
         /// This argument is a pointer to a sockaddr structure.  This structure is filled in with  the
         /// address  of  the  peer  socket, as known to the communications layer.  The exact format of the
         /// address returned addr is determined by the socket's address  family  (see  `socket`  and  the
@@ -911,7 +911,7 @@ pub const Loop = struct {
         /// * `SOCK_CLOEXEC`  - Set the close-on-exec (`FD_CLOEXEC`) flag on the new file descriptor.   See  the
         ///   description  of the `O_CLOEXEC` flag in `open` for reasons why this may be useful.
         flags: u32,
-    ) os.AcceptError!os.fd_t {
+    ) os.AcceptError!os.socket_t {
         while (true) {
             return os.accept(sockfd, addr, addr_size, flags | os.SOCK_NONBLOCK) catch |err| switch (err) {
                 error.WouldBlock => {
test/compile_errors.zig
@@ -8439,4 +8439,18 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
     , &[_][]const u8{
         "tmp.zig:2:30: error: `.*` cannot be followed by `*`. Are you missing a space?",
     });
+
+    cases.add("Issue #9165: windows tcp server compilation error",
+        \\const std = @import("std");
+        \\pub const io_mode = .evented;
+        \\pub fn main() !void {
+        \\    if (std.builtin.os.tag == .windows) {
+        \\        _ = try (std.net.StreamServer.init(.{})).accept();
+        \\    } else {
+        \\        @compileError("Unsupported OS");
+        \\    }
+        \\}
+    , &[_][]const u8{
+        "error: Unsupported OS",
+    });
 }