| author | |
| committer | |
| log | 8ef9d98e6dd24bf9c3def1e938e3eab66b39667c |
| tree | 5e5934b5b530a535ec6158f4e27d50c25bd36067 |
| parent | 76304a36afb6d2cc77902a0e60906382b53d7baa |
Use i32 instead of isize for os.timeval's for socket read/write
timeouts.
Add a comptime check to resolveScopeID to see if `IFNAMESIZE` is
available on the host. If it is not available, return an error
indicating that resolving the scope ID of a IPv6 address is not yet
supported on the host platform.2 files changed, 15 insertions(+), 12 deletions(-)
lib/std/x/os/Socket.zig+4-4| ... | ... | @@ -273,8 +273,8 @@ pub fn setReadBufferSize(self: Socket, size: u32) !void { |
| 273 | 273 | /// to the socket will thereafter return `error.WouldBlock` should the timeout be exceeded. |
| 274 | 274 | pub fn setWriteTimeout(self: Socket, milliseconds: usize) !void { |
| 275 | 275 | const timeout = os.timeval{ |
| 276 | .tv_sec = @intCast(isize, milliseconds / time.ms_per_s), | |
| 277 | .tv_usec = @intCast(isize, (milliseconds % time.ms_per_s) * time.us_per_ms), | |
| 276 | .tv_sec = @intCast(i32, milliseconds / time.ms_per_s), | |
| 277 | .tv_usec = @intCast(i32, (milliseconds % time.ms_per_s) * time.us_per_ms), | |
| 278 | 278 | }; |
| 279 | 279 | |
| 280 | 280 | return os.setsockopt(self.fd, os.SOL_SOCKET, os.SO_SNDTIMEO, mem.asBytes(&timeout)); |
| ... | ... | @@ -286,8 +286,8 @@ pub fn setWriteTimeout(self: Socket, milliseconds: usize) !void { |
| 286 | 286 | /// exceeded. |
| 287 | 287 | pub fn setReadTimeout(self: Socket, milliseconds: usize) !void { |
| 288 | 288 | const timeout = os.timeval{ |
| 289 | .tv_sec = @intCast(isize, milliseconds / time.ms_per_s), | |
| 290 | .tv_usec = @intCast(isize, (milliseconds % time.ms_per_s) * time.us_per_ms), | |
| 289 | .tv_sec = @intCast(i32, milliseconds / time.ms_per_s), | |
| 290 | .tv_usec = @intCast(i32, (milliseconds % time.ms_per_s) * time.us_per_ms), | |
| 291 | 291 | }; |
| 292 | 292 | |
| 293 | 293 | return os.setsockopt(self.fd, os.SOL_SOCKET, os.SO_RCVTIMEO, mem.asBytes(&timeout)); |
lib/std/x/os/net.zig+11-8| ... | ... | @@ -17,18 +17,21 @@ const testing = std.testing; |
| 17 | 17 | /// an error if either resolution fails, or if the interface name is |
| 18 | 18 | /// too long. |
| 19 | 19 | pub fn resolveScopeID(name: []const u8) !u32 { |
| 20 | if (name.len >= os.IFNAMESIZE - 1) return error.NameTooLong; | |
| 20 | if (comptime @hasDecl(os, "IFNAMESIZE")) { | |
| 21 | if (name.len >= os.IFNAMESIZE - 1) return error.NameTooLong; | |
| 21 | 22 | |
| 22 | const fd = try os.socket(os.AF_UNIX, os.SOCK_DGRAM, 0); | |
| 23 | defer os.closeSocket(fd); | |
| 23 | const fd = try os.socket(os.AF_UNIX, os.SOCK_DGRAM, 0); | |
| 24 | defer os.closeSocket(fd); | |
| 24 | 25 | |
| 25 | var f: os.ifreq = undefined; | |
| 26 | mem.copy(u8, &f.ifrn.name, name); | |
| 27 | f.ifrn.name[name.len] = 0; | |
| 26 | var f: os.ifreq = undefined; | |
| 27 | mem.copy(u8, &f.ifrn.name, name); | |
| 28 | f.ifrn.name[name.len] = 0; | |
| 28 | 29 | |
| 29 | try os.ioctl_SIOCGIFINDEX(fd, &f); | |
| 30 | try os.ioctl_SIOCGIFINDEX(fd, &f); | |
| 30 | 31 | |
| 31 | return @bitCast(u32, f.ifru.ivalue); | |
| 32 | return @bitCast(u32, f.ifru.ivalue); | |
| 33 | } | |
| 34 | return error.Unsupported; | |
| 32 | 35 | } |
| 33 | 36 | |
| 34 | 37 | /// An IPv4 address comprised of 4 bytes. |