From 0134cb0214131d1a7edb18a48f54f9d25277cf84 Mon Sep 17 00:00:00 2001 From: Jonathan Marler Date: Tue, 22 Jun 2021 08:05:18 -0600 Subject: [PATCH] nice error for unsupported async sockets on Windows --- lib/std/event/loop.zig | 4 ++-- test/compile_errors.zig | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/std/event/loop.zig b/lib/std/event/loop.zig index bfc204919c..5353341363 100644 --- a/lib/std/event/loop.zig +++ b/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 => { diff --git a/test/compile_errors.zig b/test/compile_errors.zig index 65c7de6dec..bb7cfcfc1d 100644 --- a/test/compile_errors.zig +++ b/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", + }); }