authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-10-30 14:43:55-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-10-30 14:43:55-04:00
log618ee5b63a2f817492b4da0d5c8b7fa1584680bc
tree3e1f2435a2ea7e100d7e4110487c62774d3719a3
parent24b3da871d7ab45d373c7ad05b30a1b96b41be50

fixes for macos and 32 bit arches


3 files changed, 98 insertions(+), 14 deletions(-)

lib/std/c/darwin.zig+55
...@@ -56,3 +56,58 @@ pub fn sigaddset(set: *sigset_t, signo: u5) void {...@@ -56,3 +56,58 @@ pub fn sigaddset(set: *sigset_t, signo: u5) void {
56}56}
5757
58pub extern "c" fn sigaltstack(ss: ?*stack_t, old_ss: ?*stack_t) c_int;58pub extern "c" fn sigaltstack(ss: ?*stack_t, old_ss: ?*stack_t) c_int;
59
60/// get address to use bind()
61pub const AI_PASSIVE = 0x00000001;
62
63/// fill ai_canonname
64pub const AI_CANONNAME = 0x00000002;
65
66/// prevent host name resolution
67pub const AI_NUMERICHOST = 0x00000004;
68
69/// prevent service name resolution
70pub const AI_NUMERICSERV = 0x00001000;
71
72/// address family for hostname not supported
73pub const EAI_ADDRFAMILY = 1;
74
75/// temporary failure in name resolution
76pub const EAI_AGAIN = 2;
77
78/// invalid value for ai_flags
79pub const EAI_BADFLAGS = 3;
80
81/// non-recoverable failure in name resolution
82pub const EAI_FAIL = 4;
83
84/// ai_family not supported
85pub const EAI_FAMILY = 5;
86
87/// memory allocation failure
88pub const EAI_MEMORY = 6;
89
90/// no address associated with hostname
91pub const EAI_NODATA = 7;
92
93/// hostname nor servname provided, or not known
94pub const EAI_NONAME = 8;
95
96/// servname not supported for ai_socktype
97pub const EAI_SERVICE = 9;
98
99/// ai_socktype not supported
100pub const EAI_SOCKTYPE = 10;
101
102/// system error returned in errno
103pub const EAI_SYSTEM = 11;
104
105/// invalid value for hints
106pub const EAI_BADHINTS = 12;
107
108/// resolved protocol is unknown
109pub const EAI_PROTOCOL = 13;
110
111/// argument buffer overflow
112pub const EAI_OVERFLOW = 14;
113pub const EAI_MAX = 15;
lib/std/net.zig+27-14
...@@ -30,10 +30,9 @@ pub const Address = struct {...@@ -30,10 +30,9 @@ pub const Address = struct {
3030
31 pub fn initIp4(ip4: u32, _port: u16) Address {31 pub fn initIp4(ip4: u32, _port: u16) Address {
32 switch (builtin.os) {32 switch (builtin.os) {
33 .macosx, .ios, .watchos, .tvos, .freebsd, .netbsd => return Address{33 .linux => return Address{
34 .os_addr = os.sockaddr{34 .os_addr = os.sockaddr{
35 .in = os.sockaddr_in{35 .in = os.sockaddr_in{
36 .len = @sizeOf(os.sockaddr_in),
37 .family = os.AF_INET,36 .family = os.AF_INET,
38 .port = mem.nativeToBig(u16, _port),37 .port = mem.nativeToBig(u16, _port),
39 .addr = ip4,38 .addr = ip4,
...@@ -41,9 +40,10 @@ pub const Address = struct {...@@ -41,9 +40,10 @@ pub const Address = struct {
41 },40 },
42 },41 },
43 },42 },
44 .linux => return Address{43 else => return Address{
45 .os_addr = os.sockaddr{44 .os_addr = os.sockaddr{
46 .in = os.sockaddr_in{45 .in = os.sockaddr_in{
46 .len = @sizeOf(os.sockaddr_in),
47 .family = os.AF_INET,47 .family = os.AF_INET,
48 .port = mem.nativeToBig(u16, _port),48 .port = mem.nativeToBig(u16, _port),
49 .addr = ip4,49 .addr = ip4,
...@@ -51,22 +51,35 @@ pub const Address = struct {...@@ -51,22 +51,35 @@ pub const Address = struct {
51 },51 },
52 },52 },
53 },53 },
54 else => @compileError("Address.initIp4 not implemented for this platform"),
55 }54 }
56 }55 }
5756
58 pub fn initIp6(ip6: Ip6Addr, _port: u16) Address {57 pub fn initIp6(ip6: Ip6Addr, _port: u16) Address {
59 return Address{58 switch (builtin.os) {
60 .os_addr = os.sockaddr{59 .linux => return Address{
61 .in6 = os.sockaddr_in6{60 .os_addr = os.sockaddr{
62 .family = os.AF_INET6,61 .in6 = os.sockaddr_in6{
63 .port = mem.nativeToBig(u16, _port),62 .family = os.AF_INET6,
64 .flowinfo = 0,63 .port = mem.nativeToBig(u16, _port),
65 .addr = ip6.addr,64 .flowinfo = 0,
66 .scope_id = ip6.scope_id,65 .addr = ip6.addr,
66 .scope_id = ip6.scope_id,
67 },
67 },68 },
68 },69 },
69 };70 else => return Address{
71 .os_addr = os.sockaddr{
72 .in6 = os.sockaddr_in6{
73 .len = @sizeOf(os.sockaddr_in6),
74 .family = os.AF_INET6,
75 .port = mem.nativeToBig(u16, _port),
76 .flowinfo = 0,
77 .addr = ip6.addr,
78 .scope_id = ip6.scope_id,
79 },
80 },
81 },
82 }
70 }83 }
7184
72 pub fn port(self: Address) u16 {85 pub fn port(self: Address) u16 {
...@@ -1126,7 +1139,7 @@ fn resMSendRc(...@@ -1126,7 +1139,7 @@ fn resMSendRc(
1126 }};1139 }};
1127 const retry_interval = timeout / attempts;1140 const retry_interval = timeout / attempts;
1128 var next: u32 = 0;1141 var next: u32 = 0;
1129 var t2: usize = std.time.milliTimestamp();1142 var t2: u64 = std.time.milliTimestamp();
1130 var t0 = t2;1143 var t0 = t2;
1131 var t1 = t2 - retry_interval;1144 var t1 = t2 - retry_interval;
11321145
lib/std/os/bits/darwin.zig+16
...@@ -11,6 +11,7 @@ pub const socklen_t = u32;...@@ -11,6 +11,7 @@ pub const socklen_t = u32;
11pub const sockaddr = extern union {11pub const sockaddr = extern union {
12 in: sockaddr_in,12 in: sockaddr_in,
13 in6: sockaddr_in6,13 in6: sockaddr_in6,
14 un: sockaddr_un,
14};15};
15pub const sockaddr_in = extern struct {16pub const sockaddr_in = extern struct {
16 len: u8,17 len: u8,
...@@ -27,6 +28,10 @@ pub const sockaddr_in6 = extern struct {...@@ -27,6 +28,10 @@ pub const sockaddr_in6 = extern struct {
27 addr: [16]u8,28 addr: [16]u8,
28 scope_id: u32,29 scope_id: u32,
29};30};
31pub const sockaddr_un = extern struct {
32 len: u8,
33 family: sa_family_t,
34};
3035
31pub const timeval = extern struct {36pub const timeval = extern struct {
32 tv_sec: c_long,37 tv_sec: c_long,
...@@ -1192,3 +1197,14 @@ pub const AT_SYMLINK_FOLLOW = 0x0040;...@@ -1192,3 +1197,14 @@ pub const AT_SYMLINK_FOLLOW = 0x0040;
11921197
1193/// Path refers to directory1198/// Path refers to directory
1194pub const AT_REMOVEDIR = 0x0080;1199pub const AT_REMOVEDIR = 0x0080;
1200
1201pub const addrinfo = extern struct {
1202 flags: i32,
1203 family: i32,
1204 socktype: i32,
1205 protocol: i32,
1206 addrlen: socklen_t,
1207 canonname: ?[*]u8,
1208 addr: ?*sockaddr,
1209 next: ?*addrinfo,
1210};