| 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 | 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 | 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 | 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 | 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 | 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 | 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 | 12 | |
| 13 | 13 | const fmt = std.fmt; |
| 14 | 14 | const mem = std.mem; |
| 15 | const builtin = std.builtin; | |
| 16 | 15 | const testing = std.testing; |
| 16 | const native_os = std.Target.current.os; | |
| 17 | 17 | |
| 18 | 18 | const IPv4 = std.x.os.IPv4; |
| 19 | 19 | const IPv6 = std.x.os.IPv6; |
| ... | ... | @@ -325,7 +325,7 @@ pub const Listener = struct { |
| 325 | 325 | }; |
| 326 | 326 | |
| 327 | 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 | 330 | const listener = try tcp.Listener.init(.ip, .{ .close_on_exec = true }); |
| 331 | 331 | defer listener.deinit(); |
| ... | ... | @@ -349,7 +349,7 @@ test "tcp: create client/listener pair" { |
| 349 | 349 | } |
| 350 | 350 | |
| 351 | 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 | 354 | const listener = try tcp.Listener.init(.ip, .{ .close_on_exec = true }); |
| 355 | 355 | defer listener.deinit(); |
| ... | ... | @@ -377,7 +377,7 @@ test "tcp/client: 1ms read timeout" { |
| 377 | 377 | } |
| 378 | 378 | |
| 379 | 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 | 382 | const listener = try tcp.Listener.init(.ip, .{ .close_on_exec = true }); |
| 383 | 383 | defer listener.deinit(); |
| ... | ... | @@ -416,7 +416,7 @@ test "tcp/client: read and write multiple vectors" { |
| 416 | 416 | } |
| 417 | 417 | |
| 418 | 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 | 421 | const listener = try tcp.Listener.init(.ip, .{ .close_on_exec = true }); |
| 422 | 422 | defer listener.deinit(); |
| ... | ... | @@ -429,7 +429,7 @@ test "tcp/listener: bind to unspecified ipv4 address" { |
| 429 | 429 | } |
| 430 | 430 | |
| 431 | 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 | 434 | const listener = try tcp.Listener.init(.ipv6, .{ .close_on_exec = true }); |
| 435 | 435 | defer listener.deinit(); |
lib/std/x/os/io.zig+4-4| ... | ... | @@ -2,12 +2,12 @@ const std = @import("../../std.zig"); |
| 2 | 2 | |
| 3 | 3 | const os = std.os; |
| 4 | 4 | const mem = std.mem; |
| 5 | const builtin = std.builtin; | |
| 6 | 5 | const testing = std.testing; |
| 6 | const native_os = std.Target.current.os; | |
| 7 | 7 | |
| 8 | 8 | /// POSIX `iovec`, or Windows `WSABUF`. The difference between the two are the ordering |
| 9 | 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 | 11 | extern struct { |
| 12 | 12 | len: c_ulong, |
| 13 | 13 | ptr: usize, |
| ... | ... | @@ -38,7 +38,7 @@ else |
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 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 | 115 | }; |
| 116 | 116 | |
| 117 | 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 | 120 | const ip = std.x.net.ip; |
| 121 | 121 | const tcp = std.x.net.tcp; |
lib/std/x/os/net.zig+2-2| ... | ... | @@ -10,8 +10,8 @@ const os = std.os; |
| 10 | 10 | const fmt = std.fmt; |
| 11 | 11 | const mem = std.mem; |
| 12 | 12 | const math = std.math; |
| 13 | const builtin = std.builtin; | |
| 14 | 13 | const testing = std.testing; |
| 14 | const native_os = std.Target.current.os; | |
| 15 | 15 | |
| 16 | 16 | /// Resolves a network interface name into a scope/zone ID. It returns |
| 17 | 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 | 20 | if (comptime @hasDecl(os, "IFNAMESIZE")) { |
| 21 | 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 | 24 | var interface_name: [os.IFNAMESIZE]u8 = undefined; |
| 25 | 25 | mem.copy(u8, &interface_name, name); |
| 26 | 26 | interface_name[name.len] = 0; |
lib/std/x/os/socket.zig+11-10| ... | ... | @@ -12,7 +12,8 @@ const fmt = std.fmt; |
| 12 | 12 | const mem = std.mem; |
| 13 | 13 | const time = std.time; |
| 14 | 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 | 18 | const Buffer = std.x.os.Buffer; |
| 18 | 19 | |
| ... | ... | @@ -35,7 +36,7 @@ pub const Socket = struct { |
| 35 | 36 | /// the fields of a `Socket.Address`. |
| 36 | 37 | pub const Address = union(enum) { |
| 37 | 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 | 40 | pub const Length = if (requires_prepended_length) u8 else [0]u8; |
| 40 | 41 | |
| 41 | 42 | pub const Family = if (requires_prepended_length) u8 else c_ushort; |
| ... | ... | @@ -140,7 +141,7 @@ pub const Socket = struct { |
| 140 | 141 | |
| 141 | 142 | /// POSIX `msghdr`. Denotes a destination address, set of buffers, control data, and flags. Ported |
| 142 | 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 | 145 | extern struct { |
| 145 | 146 | name: usize = @ptrToInt(@as(?[*]u8, null)), |
| 146 | 147 | name_len: c_int = 0, |
| ... | ... | @@ -156,7 +157,7 @@ pub const Socket = struct { |
| 156 | 157 | |
| 157 | 158 | pub usingnamespace MessageMixin(Message); |
| 158 | 159 | } |
| 159 | else if (builtin.os.tag == .windows) | |
| 160 | else if (native_os.tag == .windows) | |
| 160 | 161 | extern struct { |
| 161 | 162 | name: usize = @ptrToInt(@as(?[*]u8, null)), |
| 162 | 163 | name_len: c_int = 0, |
| ... | ... | @@ -172,7 +173,7 @@ pub const Socket = struct { |
| 172 | 173 | |
| 173 | 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 | 177 | extern struct { |
| 177 | 178 | name: usize = @ptrToInt(@as(?[*]u8, null)), |
| 178 | 179 | name_len: c_uint = 0, |
| ... | ... | @@ -189,7 +190,7 @@ pub const Socket = struct { |
| 189 | 190 | |
| 190 | 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 | 194 | extern struct { |
| 194 | 195 | name: usize = @ptrToInt(@as(?[*]u8, null)), |
| 195 | 196 | name_len: c_uint = 0, |
| ... | ... | @@ -241,7 +242,7 @@ pub const Socket = struct { |
| 241 | 242 | } |
| 242 | 243 | |
| 243 | 244 | pub fn setControl(self: *Self, control: []const u8) void { |
| 244 | if (builtin.os.tag == .windows) { | |
| 245 | if (native_os.tag == .windows) { | |
| 245 | 246 | self.control = Buffer.from(control); |
| 246 | 247 | } else { |
| 247 | 248 | self.control = @ptrToInt(control.ptr); |
| ... | ... | @@ -262,7 +263,7 @@ pub const Socket = struct { |
| 262 | 263 | } |
| 263 | 264 | |
| 264 | 265 | pub fn getControl(self: Self) []const u8 { |
| 265 | if (builtin.os.tag == .windows) { | |
| 266 | if (native_os.tag == .windows) { | |
| 266 | 267 | return self.control.into(); |
| 267 | 268 | } else { |
| 268 | 269 | return @intToPtr([*]const u8, self.control)[0..@intCast(usize, self.control_len)]; |
| ... | ... | @@ -281,7 +282,7 @@ pub const Socket = struct { |
| 281 | 282 | /// short's on Windows, whereas glibc and musl denote the fields to be |
| 282 | 283 | /// int's on every other platform. |
| 283 | 284 | pub const Linger = extern struct { |
| 284 | pub const Field = switch (builtin.os.tag) { | |
| 285 | pub const Field = switch (native_os.tag) { | |
| 285 | 286 | .windows => c_ushort, |
| 286 | 287 | else => c_int, |
| 287 | 288 | }; |
| ... | ... | @@ -315,7 +316,7 @@ pub const Socket = struct { |
| 315 | 316 | } |
| 316 | 317 | |
| 317 | 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 | 320 | .windows => @import("socket_windows.zig"), |
| 320 | 321 | else => @import("socket_posix.zig"), |
| 321 | 322 | }.Mixin(Socket); |