mirror of
https://github.com/ziglang/zig.git
synced 2026-01-21 06:45:24 +00:00
fixes for macos and 32 bit arches
This commit is contained in:
parent
24b3da871d
commit
618ee5b63a
@ -56,3 +56,58 @@ pub fn sigaddset(set: *sigset_t, signo: u5) void {
|
||||
}
|
||||
|
||||
pub extern "c" fn sigaltstack(ss: ?*stack_t, old_ss: ?*stack_t) c_int;
|
||||
|
||||
/// get address to use bind()
|
||||
pub const AI_PASSIVE = 0x00000001;
|
||||
|
||||
/// fill ai_canonname
|
||||
pub const AI_CANONNAME = 0x00000002;
|
||||
|
||||
/// prevent host name resolution
|
||||
pub const AI_NUMERICHOST = 0x00000004;
|
||||
|
||||
/// prevent service name resolution
|
||||
pub const AI_NUMERICSERV = 0x00001000;
|
||||
|
||||
/// address family for hostname not supported
|
||||
pub const EAI_ADDRFAMILY = 1;
|
||||
|
||||
/// temporary failure in name resolution
|
||||
pub const EAI_AGAIN = 2;
|
||||
|
||||
/// invalid value for ai_flags
|
||||
pub const EAI_BADFLAGS = 3;
|
||||
|
||||
/// non-recoverable failure in name resolution
|
||||
pub const EAI_FAIL = 4;
|
||||
|
||||
/// ai_family not supported
|
||||
pub const EAI_FAMILY = 5;
|
||||
|
||||
/// memory allocation failure
|
||||
pub const EAI_MEMORY = 6;
|
||||
|
||||
/// no address associated with hostname
|
||||
pub const EAI_NODATA = 7;
|
||||
|
||||
/// hostname nor servname provided, or not known
|
||||
pub const EAI_NONAME = 8;
|
||||
|
||||
/// servname not supported for ai_socktype
|
||||
pub const EAI_SERVICE = 9;
|
||||
|
||||
/// ai_socktype not supported
|
||||
pub const EAI_SOCKTYPE = 10;
|
||||
|
||||
/// system error returned in errno
|
||||
pub const EAI_SYSTEM = 11;
|
||||
|
||||
/// invalid value for hints
|
||||
pub const EAI_BADHINTS = 12;
|
||||
|
||||
/// resolved protocol is unknown
|
||||
pub const EAI_PROTOCOL = 13;
|
||||
|
||||
/// argument buffer overflow
|
||||
pub const EAI_OVERFLOW = 14;
|
||||
pub const EAI_MAX = 15;
|
||||
|
||||
@ -30,17 +30,6 @@ pub const Address = struct {
|
||||
|
||||
pub fn initIp4(ip4: u32, _port: u16) Address {
|
||||
switch (builtin.os) {
|
||||
.macosx, .ios, .watchos, .tvos, .freebsd, .netbsd => return Address{
|
||||
.os_addr = os.sockaddr{
|
||||
.in = os.sockaddr_in{
|
||||
.len = @sizeOf(os.sockaddr_in),
|
||||
.family = os.AF_INET,
|
||||
.port = mem.nativeToBig(u16, _port),
|
||||
.addr = ip4,
|
||||
.zero = [_]u8{0} ** 8,
|
||||
},
|
||||
},
|
||||
},
|
||||
.linux => return Address{
|
||||
.os_addr = os.sockaddr{
|
||||
.in = os.sockaddr_in{
|
||||
@ -51,22 +40,46 @@ pub const Address = struct {
|
||||
},
|
||||
},
|
||||
},
|
||||
else => @compileError("Address.initIp4 not implemented for this platform"),
|
||||
else => return Address{
|
||||
.os_addr = os.sockaddr{
|
||||
.in = os.sockaddr_in{
|
||||
.len = @sizeOf(os.sockaddr_in),
|
||||
.family = os.AF_INET,
|
||||
.port = mem.nativeToBig(u16, _port),
|
||||
.addr = ip4,
|
||||
.zero = [_]u8{0} ** 8,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
pub fn initIp6(ip6: Ip6Addr, _port: u16) Address {
|
||||
return Address{
|
||||
.os_addr = os.sockaddr{
|
||||
.in6 = os.sockaddr_in6{
|
||||
.family = os.AF_INET6,
|
||||
.port = mem.nativeToBig(u16, _port),
|
||||
.flowinfo = 0,
|
||||
.addr = ip6.addr,
|
||||
.scope_id = ip6.scope_id,
|
||||
switch (builtin.os) {
|
||||
.linux => return Address{
|
||||
.os_addr = os.sockaddr{
|
||||
.in6 = os.sockaddr_in6{
|
||||
.family = os.AF_INET6,
|
||||
.port = mem.nativeToBig(u16, _port),
|
||||
.flowinfo = 0,
|
||||
.addr = ip6.addr,
|
||||
.scope_id = ip6.scope_id,
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
else => return Address{
|
||||
.os_addr = os.sockaddr{
|
||||
.in6 = os.sockaddr_in6{
|
||||
.len = @sizeOf(os.sockaddr_in6),
|
||||
.family = os.AF_INET6,
|
||||
.port = mem.nativeToBig(u16, _port),
|
||||
.flowinfo = 0,
|
||||
.addr = ip6.addr,
|
||||
.scope_id = ip6.scope_id,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
pub fn port(self: Address) u16 {
|
||||
@ -1126,7 +1139,7 @@ fn resMSendRc(
|
||||
}};
|
||||
const retry_interval = timeout / attempts;
|
||||
var next: u32 = 0;
|
||||
var t2: usize = std.time.milliTimestamp();
|
||||
var t2: u64 = std.time.milliTimestamp();
|
||||
var t0 = t2;
|
||||
var t1 = t2 - retry_interval;
|
||||
|
||||
|
||||
@ -11,6 +11,7 @@ pub const socklen_t = u32;
|
||||
pub const sockaddr = extern union {
|
||||
in: sockaddr_in,
|
||||
in6: sockaddr_in6,
|
||||
un: sockaddr_un,
|
||||
};
|
||||
pub const sockaddr_in = extern struct {
|
||||
len: u8,
|
||||
@ -27,6 +28,10 @@ pub const sockaddr_in6 = extern struct {
|
||||
addr: [16]u8,
|
||||
scope_id: u32,
|
||||
};
|
||||
pub const sockaddr_un = extern struct {
|
||||
len: u8,
|
||||
family: sa_family_t,
|
||||
};
|
||||
|
||||
pub const timeval = extern struct {
|
||||
tv_sec: c_long,
|
||||
@ -1192,3 +1197,14 @@ pub const AT_SYMLINK_FOLLOW = 0x0040;
|
||||
|
||||
/// Path refers to directory
|
||||
pub const AT_REMOVEDIR = 0x0080;
|
||||
|
||||
pub const addrinfo = extern struct {
|
||||
flags: i32,
|
||||
family: i32,
|
||||
socktype: i32,
|
||||
protocol: i32,
|
||||
addrlen: socklen_t,
|
||||
canonname: ?[*]u8,
|
||||
addr: ?*sockaddr,
|
||||
next: ?*addrinfo,
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user