authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-10-23 08:02:03-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-10-29 06:20:51-07:00
log5d7672f2adc8f1058aa1f49f80055b8816a06371
tree47da8d1ae830506f254f4fa659705c721eb63fa1
parent89bb58e5a3c663b139e55e943ce32331baa24c61

std.Io.Threaded: stub netConnectUnix for Windows


1 files changed, 46 insertions(+), 32 deletions(-)

lib/std/Io/Threaded.zig+46-32
...@@ -57,7 +57,7 @@ const Closure = struct {...@@ -57,7 +57,7 @@ const Closure = struct {
57 fn requestCancel(closure: *Closure) void {57 fn requestCancel(closure: *Closure) void {
58 switch (@atomicRmw(std.Thread.Id, &closure.cancel_tid, .Xchg, canceling_tid, .acq_rel)) {58 switch (@atomicRmw(std.Thread.Id, &closure.cancel_tid, .Xchg, canceling_tid, .acq_rel)) {
59 0, canceling_tid => {},59 0, canceling_tid => {},
60 else => |tid| switch (builtin.os.tag) {60 else => |tid| switch (native_os) {
61 .linux => _ = std.os.linux.tgkill(std.os.linux.getpid(), @bitCast(tid), posix.SIG.IO),61 .linux => _ = std.os.linux.tgkill(std.os.linux.getpid(), @bitCast(tid), posix.SIG.IO),
62 else => {},62 else => {},
63 },63 },
...@@ -168,49 +168,49 @@ pub fn io(t: *Threaded) Io {...@@ -168,49 +168,49 @@ pub fn io(t: *Threaded) Io {
168 .conditionWaitUncancelable = conditionWaitUncancelable,168 .conditionWaitUncancelable = conditionWaitUncancelable,
169 .conditionWake = conditionWake,169 .conditionWake = conditionWake,
170170
171 .dirMake = switch (builtin.os.tag) {171 .dirMake = switch (native_os) {
172 .windows => dirMakeWindows,172 .windows => dirMakeWindows,
173 .wasi => dirMakeWasi,173 .wasi => dirMakeWasi,
174 else => dirMakePosix,174 else => dirMakePosix,
175 },175 },
176 .dirMakePath = switch (builtin.os.tag) {176 .dirMakePath = switch (native_os) {
177 .windows => dirMakePathWindows,177 .windows => dirMakePathWindows,
178 else => dirMakePathPosix,178 else => dirMakePathPosix,
179 },179 },
180 .dirMakeOpenPath = switch (builtin.os.tag) {180 .dirMakeOpenPath = switch (native_os) {
181 .windows => dirMakeOpenPathWindows,181 .windows => dirMakeOpenPathWindows,
182 .wasi => dirMakeOpenPathWasi,182 .wasi => dirMakeOpenPathWasi,
183 else => dirMakeOpenPathPosix,183 else => dirMakeOpenPathPosix,
184 },184 },
185 .dirStat = dirStat,185 .dirStat = dirStat,
186 .dirStatPath = switch (builtin.os.tag) {186 .dirStatPath = switch (native_os) {
187 .linux => dirStatPathLinux,187 .linux => dirStatPathLinux,
188 .windows => dirStatPathWindows,188 .windows => dirStatPathWindows,
189 .wasi => dirStatPathWasi,189 .wasi => dirStatPathWasi,
190 else => dirStatPathPosix,190 else => dirStatPathPosix,
191 },191 },
192 .fileStat = switch (builtin.os.tag) {192 .fileStat = switch (native_os) {
193 .linux => fileStatLinux,193 .linux => fileStatLinux,
194 .windows => fileStatWindows,194 .windows => fileStatWindows,
195 .wasi => fileStatWasi,195 .wasi => fileStatWasi,
196 else => fileStatPosix,196 else => fileStatPosix,
197 },197 },
198 .dirAccess = switch (builtin.os.tag) {198 .dirAccess = switch (native_os) {
199 .windows => dirAccessWindows,199 .windows => dirAccessWindows,
200 .wasi => dirAccessWasi,200 .wasi => dirAccessWasi,
201 else => dirAccessPosix,201 else => dirAccessPosix,
202 },202 },
203 .dirCreateFile = switch (builtin.os.tag) {203 .dirCreateFile = switch (native_os) {
204 .windows => dirCreateFileWindows,204 .windows => dirCreateFileWindows,
205 .wasi => dirCreateFileWasi,205 .wasi => dirCreateFileWasi,
206 else => dirCreateFilePosix,206 else => dirCreateFilePosix,
207 },207 },
208 .dirOpenFile = switch (builtin.os.tag) {208 .dirOpenFile = switch (native_os) {
209 .windows => dirOpenFileWindows,209 .windows => dirOpenFileWindows,
210 .wasi => dirOpenFileWasi,210 .wasi => dirOpenFileWasi,
211 else => dirOpenFilePosix,211 else => dirOpenFilePosix,
212 },212 },
213 .dirOpenDir = switch (builtin.os.tag) {213 .dirOpenDir = switch (native_os) {
214 .wasi => dirOpenDirWasi,214 .wasi => dirOpenDirWasi,
215 .haiku => dirOpenDirHaiku,215 .haiku => dirOpenDirHaiku,
216 else => dirOpenDirPosix,216 else => dirOpenDirPosix,
...@@ -219,11 +219,11 @@ pub fn io(t: *Threaded) Io {...@@ -219,11 +219,11 @@ pub fn io(t: *Threaded) Io {
219 .fileClose = fileClose,219 .fileClose = fileClose,
220 .fileWriteStreaming = fileWriteStreaming,220 .fileWriteStreaming = fileWriteStreaming,
221 .fileWritePositional = fileWritePositional,221 .fileWritePositional = fileWritePositional,
222 .fileReadStreaming = switch (builtin.os.tag) {222 .fileReadStreaming = switch (native_os) {
223 .windows => fileReadStreamingWindows,223 .windows => fileReadStreamingWindows,
224 else => fileReadStreamingPosix,224 else => fileReadStreamingPosix,
225 },225 },
226 .fileReadPositional = switch (builtin.os.tag) {226 .fileReadPositional = switch (native_os) {
227 .windows => fileReadPositionalWindows,227 .windows => fileReadPositionalWindows,
228 else => fileReadPositionalPosix,228 else => fileReadPositionalPosix,
229 },229 },
...@@ -231,53 +231,56 @@ pub fn io(t: *Threaded) Io {...@@ -231,53 +231,56 @@ pub fn io(t: *Threaded) Io {
231 .fileSeekTo = fileSeekTo,231 .fileSeekTo = fileSeekTo,
232 .openSelfExe = openSelfExe,232 .openSelfExe = openSelfExe,
233233
234 .now = switch (builtin.os.tag) {234 .now = switch (native_os) {
235 .windows => nowWindows,235 .windows => nowWindows,
236 .wasi => nowWasi,236 .wasi => nowWasi,
237 else => nowPosix,237 else => nowPosix,
238 },238 },
239 .sleep = switch (builtin.os.tag) {239 .sleep = switch (native_os) {
240 .windows => sleepWindows,240 .windows => sleepWindows,
241 .wasi => sleepWasi,241 .wasi => sleepWasi,
242 .linux => sleepLinux,242 .linux => sleepLinux,
243 else => sleepPosix,243 else => sleepPosix,
244 },244 },
245245
246 .netListenIp = switch (builtin.os.tag) {246 .netListenIp = switch (native_os) {
247 .windows => netListenIpWindows,247 .windows => netListenIpWindows,
248 else => netListenIpPosix,248 else => netListenIpPosix,
249 },249 },
250 .netListenUnix = switch (builtin.os.tag) {250 .netListenUnix = switch (native_os) {
251 .windows => netListenUnixWindows,251 .windows => netListenUnixWindows,
252 else => netListenUnixPosix,252 else => netListenUnixPosix,
253 },253 },
254 .netAccept = switch (builtin.os.tag) {254 .netAccept = switch (native_os) {
255 .windows => netAcceptWindows,255 .windows => netAcceptWindows,
256 else => netAcceptPosix,256 else => netAcceptPosix,
257 },257 },
258 .netBindIp = switch (builtin.os.tag) {258 .netBindIp = switch (native_os) {
259 .windows => netBindIpWindows,259 .windows => netBindIpWindows,
260 else => netBindIpPosix,260 else => netBindIpPosix,
261 },261 },
262 .netConnectIp = switch (builtin.os.tag) {262 .netConnectIp = switch (native_os) {
263 .windows => netConnectIpWindows,263 .windows => netConnectIpWindows,
264 else => netConnectIpPosix,264 else => netConnectIpPosix,
265 },265 },
266 .netConnectUnix = netConnectUnix,266 .netConnectUnix = switch (native_os) {
267 .windows => netConnectUnixWindows,
268 else => netConnectUnixPosix,
269 },
267 .netClose = netClose,270 .netClose = netClose,
268 .netRead = switch (builtin.os.tag) {271 .netRead = switch (native_os) {
269 .windows => netReadWindows,272 .windows => netReadWindows,
270 else => netReadPosix,273 else => netReadPosix,
271 },274 },
272 .netWrite = switch (builtin.os.tag) {275 .netWrite = switch (native_os) {
273 .windows => netWriteWindows,276 .windows => netWriteWindows,
274 else => netWritePosix,277 else => netWritePosix,
275 },278 },
276 .netSend = switch (builtin.os.tag) {279 .netSend = switch (native_os) {
277 .windows => netSendWindows,280 .windows => netSendWindows,
278 else => netSendPosix,281 else => netSendPosix,
279 },282 },
280 .netReceive = switch (builtin.os.tag) {283 .netReceive = switch (native_os) {
281 .windows => netReceiveWindows,284 .windows => netReceiveWindows,
282 else => netReceivePosix,285 else => netReceivePosix,
283 },286 },
...@@ -288,12 +291,12 @@ pub fn io(t: *Threaded) Io {...@@ -288,12 +291,12 @@ pub fn io(t: *Threaded) Io {
288 };291 };
289}292}
290293
291pub const socket_flags_unsupported = builtin.os.tag.isDarwin() or native_os == .haiku; // 💩💩294pub const socket_flags_unsupported = native_os.isDarwin() or native_os == .haiku; // 💩💩
292const have_accept4 = !socket_flags_unsupported;295const have_accept4 = !socket_flags_unsupported;
293const have_flock_open_flags = @hasField(posix.O, "EXLOCK");296const have_flock_open_flags = @hasField(posix.O, "EXLOCK");
294const have_networking = builtin.os.tag != .wasi;297const have_networking = native_os != .wasi;
295const have_flock = @TypeOf(posix.system.flock) != void;298const have_flock = @TypeOf(posix.system.flock) != void;
296const have_sendmmsg = builtin.os.tag == .linux;299const have_sendmmsg = native_os == .linux;
297const have_futex = switch (builtin.cpu.arch) {300const have_futex = switch (builtin.cpu.arch) {
298 .wasm32, .wasm64 => builtin.cpu.has(.wasm, .atomics),301 .wasm32, .wasm64 => builtin.cpu.has(.wasm, .atomics),
299 else => true,302 else => true,
...@@ -2916,7 +2919,7 @@ fn netListenUnixWindows(...@@ -2916,7 +2919,7 @@ fn netListenUnixWindows(
2916) net.UnixAddress.ListenError!net.Socket.Handle {2919) net.UnixAddress.ListenError!net.Socket.Handle {
2917 if (!net.has_unix_sockets) return error.AddressFamilyUnsupported;2920 if (!net.has_unix_sockets) return error.AddressFamilyUnsupported;
2918 const t: *Threaded = @ptrCast(@alignCast(userdata));2921 const t: *Threaded = @ptrCast(@alignCast(userdata));
2919 _ = t;2922 try t.checkCancel();
2920 _ = address;2923 _ = address;
2921 _ = options;2924 _ = options;
2922 @panic("TODO");2925 @panic("TODO");
...@@ -3192,7 +3195,7 @@ fn netConnectIpWindows(...@@ -3192,7 +3195,7 @@ fn netConnectIpWindows(
3192 } };3195 } };
3193}3196}
31943197
3195fn netConnectUnix(3198fn netConnectUnixPosix(
3196 userdata: ?*anyopaque,3199 userdata: ?*anyopaque,
3197 address: *const net.UnixAddress,3200 address: *const net.UnixAddress,
3198) net.UnixAddress.ConnectError!net.Socket.Handle {3201) net.UnixAddress.ConnectError!net.Socket.Handle {
...@@ -3209,6 +3212,17 @@ fn netConnectUnix(...@@ -3209,6 +3212,17 @@ fn netConnectUnix(
3209 return socket_fd;3212 return socket_fd;
3210}3213}
32113214
3215fn netConnectUnixWindows(
3216 userdata: ?*anyopaque,
3217 address: *const net.UnixAddress,
3218) net.UnixAddress.ConnectError!net.Socket.Handle {
3219 if (!net.has_unix_sockets) return error.AddressFamilyUnsupported;
3220 const t: *Threaded = @ptrCast(@alignCast(userdata));
3221 try t.checkCancel();
3222 _ = address;
3223 @panic("TODO");
3224}
3225
3212fn netBindIpPosix(3226fn netBindIpPosix(
3213 userdata: ?*anyopaque,3227 userdata: ?*anyopaque,
3214 address: *const IpAddress,3228 address: *const IpAddress,
...@@ -4456,11 +4470,11 @@ fn recoverableOsBugDetected() void {...@@ -4456,11 +4470,11 @@ fn recoverableOsBugDetected() void {
4456fn clockToPosix(clock: Io.Clock) posix.clockid_t {4470fn clockToPosix(clock: Io.Clock) posix.clockid_t {
4457 return switch (clock) {4471 return switch (clock) {
4458 .real => posix.CLOCK.REALTIME,4472 .real => posix.CLOCK.REALTIME,
4459 .awake => switch (builtin.os.tag) {4473 .awake => switch (native_os) {
4460 .macos, .ios, .watchos, .tvos => posix.CLOCK.UPTIME_RAW,4474 .macos, .ios, .watchos, .tvos => posix.CLOCK.UPTIME_RAW,
4461 else => posix.CLOCK.MONOTONIC,4475 else => posix.CLOCK.MONOTONIC,
4462 },4476 },
4463 .boot => switch (builtin.os.tag) {4477 .boot => switch (native_os) {
4464 .macos, .ios, .watchos, .tvos => posix.CLOCK.MONOTONIC_RAW,4478 .macos, .ios, .watchos, .tvos => posix.CLOCK.MONOTONIC_RAW,
4465 else => posix.CLOCK.BOOTTIME,4479 else => posix.CLOCK.BOOTTIME,
4466 },4480 },
...@@ -4523,7 +4537,7 @@ fn statFromPosix(st: *const std.posix.Stat) Io.File.Stat {...@@ -4523,7 +4537,7 @@ fn statFromPosix(st: *const std.posix.Stat) Io.File.Stat {
4523 std.posix.S.IFSOCK => break :k .unix_domain_socket,4537 std.posix.S.IFSOCK => break :k .unix_domain_socket,
4524 else => {},4538 else => {},
4525 }4539 }
4526 if (builtin.os.tag == .illumos) switch (m) {4540 if (native_os == .illumos) switch (m) {
4527 std.posix.S.IFDOOR => break :k .door,4541 std.posix.S.IFDOOR => break :k .door,
4528 std.posix.S.IFPORT => break :k .event_port,4542 std.posix.S.IFPORT => break :k .event_port,
4529 else => {},4543 else => {},