| author | |
| committer | |
| log | 278e5d398ea137a4c81bd00b1f40e50a16755684 |
| tree | de5baa7748e1dc810c5ad878dcc42226c273ae43 |
| parent | 21ec0158a1b76cb52014b5dc79fb35ba3449d226 |
5 files changed, 27 insertions(+), 26 deletions(-)
lib/std/os/linux.zig+4-4| ... | @@ -1000,9 +1000,9 @@ pub fn getsockopt(fd: i32, level: u32, optname: u32, noalias optval: [*]u8, noal | ... | @@ -1000,9 +1000,9 @@ pub fn getsockopt(fd: i32, level: u32, optname: u32, noalias optval: [*]u8, noal |
| 1000 | return syscall5(.getsockopt, @bitCast(usize, @as(isize, fd)), level, optname, @ptrToInt(optval), @ptrToInt(optlen)); | 1000 | return syscall5(.getsockopt, @bitCast(usize, @as(isize, fd)), level, optname, @ptrToInt(optval), @ptrToInt(optlen)); |
| 1001 | } | 1001 | } |
| 1002 | 1002 | ||
| 1003 | pub fn sendmsg(fd: i32, msg: *const msghdr_const, flags: u32) usize { | 1003 | pub fn sendmsg(fd: i32, msg: *const std.x.os.Socket.Message, flags: c_int) usize { |
| 1004 | if (native_arch == .i386) { | 1004 | if (native_arch == .i386) { |
| 1005 | return socketcall(SC_sendmsg, &[3]usize{ @bitCast(usize, @as(isize, fd)), @ptrToInt(msg), flags }); | 1005 | return socketcall(SC_sendmsg, &[3]usize{ @bitCast(usize, @as(isize, fd)), @ptrToInt(msg), @bitCast(usize, @as(isize, flags)) }); |
| 1006 | } | 1006 | } |
| 1007 | return syscall3(.sendmsg, @bitCast(usize, @as(isize, fd)), @ptrToInt(msg), @bitCast(usize, @as(isize, flags))); | 1007 | return syscall3(.sendmsg, @bitCast(usize, @as(isize, fd)), @ptrToInt(msg), @bitCast(usize, @as(isize, flags))); |
| 1008 | } | 1008 | } |
| ... | @@ -1054,9 +1054,9 @@ pub fn connect(fd: i32, addr: *const c_void, len: socklen_t) usize { | ... | @@ -1054,9 +1054,9 @@ pub fn connect(fd: i32, addr: *const c_void, len: socklen_t) usize { |
| 1054 | return syscall3(.connect, @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), len); | 1054 | return syscall3(.connect, @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), len); |
| 1055 | } | 1055 | } |
| 1056 | 1056 | ||
| 1057 | pub fn recvmsg(fd: i32, msg: *msghdr, flags: u32) usize { | 1057 | pub fn recvmsg(fd: i32, msg: *std.x.os.Socket.Message, flags: c_int) usize { |
| 1058 | if (native_arch == .i386) { | 1058 | if (native_arch == .i386) { |
| 1059 | return socketcall(SC_recvmsg, &[3]usize{ @bitCast(usize, @as(isize, fd)), @ptrToInt(msg), flags }); | 1059 | return socketcall(SC_recvmsg, &[3]usize{ @bitCast(usize, @as(isize, fd)), @ptrToInt(msg), @bitCast(usize, @as(isize, flags)) }); |
| 1060 | } | 1060 | } |
| 1061 | return syscall3(.recvmsg, @bitCast(usize, @as(isize, fd)), @ptrToInt(msg), @bitCast(usize, @as(isize, flags))); | 1061 | return syscall3(.recvmsg, @bitCast(usize, @as(isize, fd)), @ptrToInt(msg), @bitCast(usize, @as(isize, flags))); |
| 1062 | } | 1062 | } |
lib/std/x/net/tcp.zig+6-6| ... | @@ -12,8 +12,8 @@ const ip = std.x.net.ip; | ... | @@ -12,8 +12,8 @@ const ip = std.x.net.ip; |
| 12 | 12 | ||
| 13 | const fmt = std.fmt; | 13 | const fmt = std.fmt; |
| 14 | const mem = std.mem; | 14 | const mem = std.mem; |
| 15 | const builtin = std.builtin; | ||
| 16 | const testing = std.testing; | 15 | const testing = std.testing; |
| 16 | const native_os = std.Target.current.os; | ||
| 17 | 17 | ||
| 18 | const IPv4 = std.x.os.IPv4; | 18 | const IPv4 = std.x.os.IPv4; |
| 19 | const IPv6 = std.x.os.IPv6; | 19 | const IPv6 = std.x.os.IPv6; |
| ... | @@ -325,7 +325,7 @@ pub const Listener = struct { | ... | @@ -325,7 +325,7 @@ pub const Listener = struct { |
| 325 | }; | 325 | }; |
| 326 | 326 | ||
| 327 | test "tcp: create client/listener pair" { | 327 | test "tcp: create client/listener pair" { |
| 328 | if (builtin.os.tag == .wasi) return error.SkipZigTest; | 328 | if (native_os.tag == .wasi) return error.SkipZigTest; |
| 329 | 329 | ||
| 330 | const listener = try tcp.Listener.init(.ip, .{ .close_on_exec = true }); | 330 | const listener = try tcp.Listener.init(.ip, .{ .close_on_exec = true }); |
| 331 | defer listener.deinit(); | 331 | defer listener.deinit(); |
| ... | @@ -349,7 +349,7 @@ test "tcp: create client/listener pair" { | ... | @@ -349,7 +349,7 @@ test "tcp: create client/listener pair" { |
| 349 | } | 349 | } |
| 350 | 350 | ||
| 351 | test "tcp/client: 1ms read timeout" { | 351 | test "tcp/client: 1ms read timeout" { |
| 352 | if (builtin.os.tag == .wasi) return error.SkipZigTest; | 352 | if (native_os.tag == .wasi) return error.SkipZigTest; |
| 353 | 353 | ||
| 354 | const listener = try tcp.Listener.init(.ip, .{ .close_on_exec = true }); | 354 | const listener = try tcp.Listener.init(.ip, .{ .close_on_exec = true }); |
| 355 | defer listener.deinit(); | 355 | defer listener.deinit(); |
| ... | @@ -377,7 +377,7 @@ test "tcp/client: 1ms read timeout" { | ... | @@ -377,7 +377,7 @@ test "tcp/client: 1ms read timeout" { |
| 377 | } | 377 | } |
| 378 | 378 | ||
| 379 | test "tcp/client: read and write multiple vectors" { | 379 | test "tcp/client: read and write multiple vectors" { |
| 380 | if (builtin.os.tag == .wasi) return error.SkipZigTest; | 380 | if (native_os.tag == .wasi) return error.SkipZigTest; |
| 381 | 381 | ||
| 382 | const listener = try tcp.Listener.init(.ip, .{ .close_on_exec = true }); | 382 | const listener = try tcp.Listener.init(.ip, .{ .close_on_exec = true }); |
| 383 | defer listener.deinit(); | 383 | defer listener.deinit(); |
| ... | @@ -416,7 +416,7 @@ test "tcp/client: read and write multiple vectors" { | ... | @@ -416,7 +416,7 @@ test "tcp/client: read and write multiple vectors" { |
| 416 | } | 416 | } |
| 417 | 417 | ||
| 418 | test "tcp/listener: bind to unspecified ipv4 address" { | 418 | test "tcp/listener: bind to unspecified ipv4 address" { |
| 419 | if (builtin.os.tag == .wasi) return error.SkipZigTest; | 419 | if (native_os.tag == .wasi) return error.SkipZigTest; |
| 420 | 420 | ||
| 421 | const listener = try tcp.Listener.init(.ip, .{ .close_on_exec = true }); | 421 | const listener = try tcp.Listener.init(.ip, .{ .close_on_exec = true }); |
| 422 | defer listener.deinit(); | 422 | defer listener.deinit(); |
| ... | @@ -429,7 +429,7 @@ test "tcp/listener: bind to unspecified ipv4 address" { | ... | @@ -429,7 +429,7 @@ test "tcp/listener: bind to unspecified ipv4 address" { |
| 429 | } | 429 | } |
| 430 | 430 | ||
| 431 | test "tcp/listener: bind to unspecified ipv6 address" { | 431 | test "tcp/listener: bind to unspecified ipv6 address" { |
| 432 | if (builtin.os.tag == .wasi) return error.SkipZigTest; | 432 | if (native_os.tag == .wasi) return error.SkipZigTest; |
| 433 | 433 | ||
| 434 | const listener = try tcp.Listener.init(.ipv6, .{ .close_on_exec = true }); | 434 | const listener = try tcp.Listener.init(.ipv6, .{ .close_on_exec = true }); |
| 435 | defer listener.deinit(); | 435 | defer listener.deinit(); |
lib/std/x/os/io.zig+4-4| ... | @@ -2,12 +2,12 @@ const std = @import("../../std.zig"); | ... | @@ -2,12 +2,12 @@ const std = @import("../../std.zig"); |
| 2 | 2 | ||
| 3 | const os = std.os; | 3 | const os = std.os; |
| 4 | const mem = std.mem; | 4 | const mem = std.mem; |
| 5 | const builtin = std.builtin; | ||
| 6 | const testing = std.testing; | 5 | const testing = std.testing; |
| 6 | const native_os = std.Target.current.os; | ||
| 7 | 7 | ||
| 8 | /// POSIX `iovec`, or Windows `WSABUF`. The difference between the two are the ordering | 8 | /// POSIX `iovec`, or Windows `WSABUF`. The difference between the two are the ordering |
| 9 | /// of fields, alongside the length being represented as either a ULONG or a size_t. | 9 | /// of fields, alongside the length being represented as either a ULONG or a size_t. |
| 10 | pub const Buffer = if (builtin.os.tag == .windows) | 10 | pub const Buffer = if (native_os.tag == .windows) |
| 11 | extern struct { | 11 | extern struct { |
| 12 | len: c_ulong, | 12 | len: c_ulong, |
| 13 | ptr: usize, | 13 | ptr: usize, |
| ... | @@ -38,7 +38,7 @@ else | ... | @@ -38,7 +38,7 @@ else |
| 38 | } | 38 | } |
| 39 | 39 | ||
| 40 | pub fn intoMutable(self: Buffer) []u8 { | 40 | pub fn intoMutable(self: Buffer) []u8 { |
| 41 | return @intToptr([*]u8, self.ptr)[0..self.len]; | 41 | return @intToPtr([*]u8, self.ptr)[0..self.len]; |
| 42 | } | 42 | } |
| 43 | }; | 43 | }; |
| 44 | 44 | ||
| ... | @@ -115,7 +115,7 @@ pub const Reactor = struct { | ... | @@ -115,7 +115,7 @@ pub const Reactor = struct { |
| 115 | }; | 115 | }; |
| 116 | 116 | ||
| 117 | test "reactor/linux: drive async tcp client/listener pair" { | 117 | test "reactor/linux: drive async tcp client/listener pair" { |
| 118 | if (builtin.os.tag != .linux) return error.SkipZigTest; | 118 | if (native_os.tag != .linux) return error.SkipZigTest; |
| 119 | 119 | ||
| 120 | const ip = std.x.net.ip; | 120 | const ip = std.x.net.ip; |
| 121 | const tcp = std.x.net.tcp; | 121 | const tcp = std.x.net.tcp; |
lib/std/x/os/net.zig+2-2| ... | @@ -10,8 +10,8 @@ const os = std.os; | ... | @@ -10,8 +10,8 @@ const os = std.os; |
| 10 | const fmt = std.fmt; | 10 | const fmt = std.fmt; |
| 11 | const mem = std.mem; | 11 | const mem = std.mem; |
| 12 | const math = std.math; | 12 | const math = std.math; |
| 13 | const builtin = std.builtin; | ||
| 14 | const testing = std.testing; | 13 | const testing = std.testing; |
| 14 | const native_os = std.Target.current.os; | ||
| 15 | 15 | ||
| 16 | /// Resolves a network interface name into a scope/zone ID. It returns | 16 | /// Resolves a network interface name into a scope/zone ID. It returns |
| 17 | /// an error if either resolution fails, or if the interface name is | 17 | /// an error if either resolution fails, or if the interface name is |
| ... | @@ -20,7 +20,7 @@ pub fn resolveScopeID(name: []const u8) !u32 { | ... | @@ -20,7 +20,7 @@ pub fn resolveScopeID(name: []const u8) !u32 { |
| 20 | if (comptime @hasDecl(os, "IFNAMESIZE")) { | 20 | if (comptime @hasDecl(os, "IFNAMESIZE")) { |
| 21 | if (name.len >= os.IFNAMESIZE - 1) return error.NameTooLong; | 21 | if (name.len >= os.IFNAMESIZE - 1) return error.NameTooLong; |
| 22 | 22 | ||
| 23 | if (comptime builtin.os.tag == .windows) { | 23 | if (comptime native_os.tag == .windows) { |
| 24 | var interface_name: [os.IFNAMESIZE]u8 = undefined; | 24 | var interface_name: [os.IFNAMESIZE]u8 = undefined; |
| 25 | mem.copy(u8, &interface_name, name); | 25 | mem.copy(u8, &interface_name, name); |
| 26 | interface_name[name.len] = 0; | 26 | interface_name[name.len] = 0; |
lib/std/x/os/socket.zig+11-10| ... | @@ -12,7 +12,8 @@ const fmt = std.fmt; | ... | @@ -12,7 +12,8 @@ const fmt = std.fmt; |
| 12 | const mem = std.mem; | 12 | const mem = std.mem; |
| 13 | const time = std.time; | 13 | const time = std.time; |
| 14 | const meta = std.meta; | 14 | const meta = std.meta; |
| 15 | const builtin = std.builtin; | 15 | const native_os = std.Target.current.os; |
| 16 | const native_endian = std.Target.current.cpu.arch.endian(); | ||
| 16 | 17 | ||
| 17 | const Buffer = std.x.os.Buffer; | 18 | const Buffer = std.x.os.Buffer; |
| 18 | 19 | ||
| ... | @@ -35,7 +36,7 @@ pub const Socket = struct { | ... | @@ -35,7 +36,7 @@ pub const Socket = struct { |
| 35 | /// the fields of a `Socket.Address`. | 36 | /// the fields of a `Socket.Address`. |
| 36 | pub const Address = union(enum) { | 37 | pub const Address = union(enum) { |
| 37 | pub const Native = struct { | 38 | pub const Native = struct { |
| 38 | pub const requires_prepended_length = builtin.os.getVersionRange() == .semver; | 39 | pub const requires_prepended_length = native_os.getVersionRange() == .semver; |
| 39 | pub const Length = if (requires_prepended_length) u8 else [0]u8; | 40 | pub const Length = if (requires_prepended_length) u8 else [0]u8; |
| 40 | 41 | ||
| 41 | pub const Family = if (requires_prepended_length) u8 else c_ushort; | 42 | pub const Family = if (requires_prepended_length) u8 else c_ushort; |
| ... | @@ -140,7 +141,7 @@ pub const Socket = struct { | ... | @@ -140,7 +141,7 @@ pub const Socket = struct { |
| 140 | 141 | ||
| 141 | /// POSIX `msghdr`. Denotes a destination address, set of buffers, control data, and flags. Ported | 142 | /// POSIX `msghdr`. Denotes a destination address, set of buffers, control data, and flags. Ported |
| 142 | /// directly from musl. | 143 | /// directly from musl. |
| 143 | pub const Message = if (builtin.os.isAtLeast(.windows, .vista) != null and builtin.os.isAtLeast(.windows, .vista).?) | 144 | pub const Message = if (native_os.isAtLeast(.windows, .vista) != null and native_os.isAtLeast(.windows, .vista).?) |
| 144 | extern struct { | 145 | extern struct { |
| 145 | name: usize = @ptrToInt(@as(?[*]u8, null)), | 146 | name: usize = @ptrToInt(@as(?[*]u8, null)), |
| 146 | name_len: c_int = 0, | 147 | name_len: c_int = 0, |
| ... | @@ -156,7 +157,7 @@ pub const Socket = struct { | ... | @@ -156,7 +157,7 @@ pub const Socket = struct { |
| 156 | 157 | ||
| 157 | pub usingnamespace MessageMixin(Message); | 158 | pub usingnamespace MessageMixin(Message); |
| 158 | } | 159 | } |
| 159 | else if (builtin.os.tag == .windows) | 160 | else if (native_os.tag == .windows) |
| 160 | extern struct { | 161 | extern struct { |
| 161 | name: usize = @ptrToInt(@as(?[*]u8, null)), | 162 | name: usize = @ptrToInt(@as(?[*]u8, null)), |
| 162 | name_len: c_int = 0, | 163 | name_len: c_int = 0, |
| ... | @@ -172,7 +173,7 @@ pub const Socket = struct { | ... | @@ -172,7 +173,7 @@ pub const Socket = struct { |
| 172 | 173 | ||
| 173 | pub usingnamespace MessageMixin(Message); | 174 | pub usingnamespace MessageMixin(Message); |
| 174 | } | 175 | } |
| 175 | else if (@sizeOf(usize) > 4 and builtin.endian == .Big) | 176 | else if (@sizeOf(usize) > 4 and native_endian == .Big) |
| 176 | extern struct { | 177 | extern struct { |
| 177 | name: usize = @ptrToInt(@as(?[*]u8, null)), | 178 | name: usize = @ptrToInt(@as(?[*]u8, null)), |
| 178 | name_len: c_uint = 0, | 179 | name_len: c_uint = 0, |
| ... | @@ -189,7 +190,7 @@ pub const Socket = struct { | ... | @@ -189,7 +190,7 @@ pub const Socket = struct { |
| 189 | 190 | ||
| 190 | pub usingnamespace MessageMixin(Message); | 191 | pub usingnamespace MessageMixin(Message); |
| 191 | } | 192 | } |
| 192 | else if (@sizeOf(usize) > 4 and builtin.endian == .Little) | 193 | else if (@sizeOf(usize) > 4 and native_endian == .Little) |
| 193 | extern struct { | 194 | extern struct { |
| 194 | name: usize = @ptrToInt(@as(?[*]u8, null)), | 195 | name: usize = @ptrToInt(@as(?[*]u8, null)), |
| 195 | name_len: c_uint = 0, | 196 | name_len: c_uint = 0, |
| ... | @@ -241,7 +242,7 @@ pub const Socket = struct { | ... | @@ -241,7 +242,7 @@ pub const Socket = struct { |
| 241 | } | 242 | } |
| 242 | 243 | ||
| 243 | pub fn setControl(self: *Self, control: []const u8) void { | 244 | pub fn setControl(self: *Self, control: []const u8) void { |
| 244 | if (builtin.os.tag == .windows) { | 245 | if (native_os.tag == .windows) { |
| 245 | self.control = Buffer.from(control); | 246 | self.control = Buffer.from(control); |
| 246 | } else { | 247 | } else { |
| 247 | self.control = @ptrToInt(control.ptr); | 248 | self.control = @ptrToInt(control.ptr); |
| ... | @@ -262,7 +263,7 @@ pub const Socket = struct { | ... | @@ -262,7 +263,7 @@ pub const Socket = struct { |
| 262 | } | 263 | } |
| 263 | 264 | ||
| 264 | pub fn getControl(self: Self) []const u8 { | 265 | pub fn getControl(self: Self) []const u8 { |
| 265 | if (builtin.os.tag == .windows) { | 266 | if (native_os.tag == .windows) { |
| 266 | return self.control.into(); | 267 | return self.control.into(); |
| 267 | } else { | 268 | } else { |
| 268 | return @intToPtr([*]const u8, self.control)[0..@intCast(usize, self.control_len)]; | 269 | return @intToPtr([*]const u8, self.control)[0..@intCast(usize, self.control_len)]; |
| ... | @@ -281,7 +282,7 @@ pub const Socket = struct { | ... | @@ -281,7 +282,7 @@ pub const Socket = struct { |
| 281 | /// short's on Windows, whereas glibc and musl denote the fields to be | 282 | /// short's on Windows, whereas glibc and musl denote the fields to be |
| 282 | /// int's on every other platform. | 283 | /// int's on every other platform. |
| 283 | pub const Linger = extern struct { | 284 | pub const Linger = extern struct { |
| 284 | pub const Field = switch (builtin.os.tag) { | 285 | pub const Field = switch (native_os.tag) { |
| 285 | .windows => c_ushort, | 286 | .windows => c_ushort, |
| 286 | else => c_int, | 287 | else => c_int, |
| 287 | }; | 288 | }; |
| ... | @@ -315,7 +316,7 @@ pub const Socket = struct { | ... | @@ -315,7 +316,7 @@ pub const Socket = struct { |
| 315 | } | 316 | } |
| 316 | 317 | ||
| 317 | /// Mix in socket syscalls depending on the platform we are compiling against. | 318 | /// Mix in socket syscalls depending on the platform we are compiling against. |
| 318 | pub usingnamespace switch (builtin.os.tag) { | 319 | pub usingnamespace switch (native_os.tag) { |
| 319 | .windows => @import("socket_windows.zig"), | 320 | .windows => @import("socket_windows.zig"), |
| 320 | else => @import("socket_posix.zig"), | 321 | else => @import("socket_posix.zig"), |
| 321 | }.Mixin(Socket); | 322 | }.Mixin(Socket); |