authorgravatar for git@l4.pmLuna <git@l4.pm> 2019-11-10 14:04:52-03:00
committergravatar for git@l4.pmLuna <git@l4.pm> 2019-11-10 14:04:52-03:00
log2d02920a905e20b7f43991657cdc028e444b9df7
tree4c9a3ee6a1cdba23567890e947bbbb47a9189f79
parent25423eb453e1c0cece457f4012106dbcd97f29f3

use hasDecl instead of switch on builtin.os


1 files changed, 5 insertions(+), 4 deletions(-)

lib/std/net.zig+5-4
...@@ -10,14 +10,13 @@ test "" {...@@ -10,14 +10,13 @@ test "" {
10 _ = @import("net/test.zig");10 _ = @import("net/test.zig");
11}11}
1212
13const has_unix_sockets = @hasDecl(os, "sockaddr_un");
14
13pub const Address = extern union {15pub const Address = extern union {
14 any: os.sockaddr,16 any: os.sockaddr,
15 in: os.sockaddr_in,17 in: os.sockaddr_in,
16 in6: os.sockaddr_in6,18 in6: os.sockaddr_in6,
17 un: switch (builtin.os) {19 un: if (has_unix_sockets) os.sockaddr_un else void,
18 .linux, .macosx, .freebsd, .netbsd => os.sockaddr_un,
19 else => void,
20 },
2120
22 // TODO this crashed the compiler21 // TODO this crashed the compiler
23 //pub const localhost = initIp4(parseIp4("127.0.0.1") catch unreachable, 0);22 //pub const localhost = initIp4(parseIp4("127.0.0.1") catch unreachable, 0);
...@@ -239,6 +238,7 @@ pub const Address = extern union {...@@ -239,6 +238,7 @@ pub const Address = extern union {
239 }238 }
240239
241 /// Returns the port in native endian.240 /// Returns the port in native endian.
241 /// Asserts that the address is ip4 or ip6.
242 pub fn getPort(self: Address) u16 {242 pub fn getPort(self: Address) u16 {
243 const big_endian_port = switch (self.any.family) {243 const big_endian_port = switch (self.any.family) {
244 os.AF_INET => self.in.port,244 os.AF_INET => self.in.port,
...@@ -249,6 +249,7 @@ pub const Address = extern union {...@@ -249,6 +249,7 @@ pub const Address = extern union {
249 }249 }
250250
251 /// `port` is native-endian.251 /// `port` is native-endian.
252 /// Asserts that the address is ip4 or ip6.
252 pub fn setPort(self: *Address, port: u16) void {253 pub fn setPort(self: *Address, port: u16) void {
253 const ptr = switch (self.any.family) {254 const ptr = switch (self.any.family) {
254 os.AF_INET => &self.in.port,255 os.AF_INET => &self.in.port,