mirror of
https://github.com/ziglang/zig.git
synced 2025-12-06 06:13:07 +00:00
std.os: more reorganization efforts
* std lib tests are passing on x86_64-linux with and without -lc * stage2 is building from source on x86_64-linux * down to 38 remaining uses of `usingnamespace`
This commit is contained in:
parent
c09ba8796c
commit
7f03cfe161
@ -877,8 +877,8 @@ const LinuxThreadImpl = struct {
|
||||
const mapped = os.mmap(
|
||||
null,
|
||||
map_bytes,
|
||||
os.PROT_NONE,
|
||||
os.MAP_PRIVATE | os.MAP_ANONYMOUS,
|
||||
os.PROT.NONE,
|
||||
os.MAP.PRIVATE | os.MAP.ANONYMOUS,
|
||||
-1,
|
||||
0,
|
||||
) catch |err| switch (err) {
|
||||
@ -893,7 +893,7 @@ const LinuxThreadImpl = struct {
|
||||
// map everything but the guard page as read/write
|
||||
os.mprotect(
|
||||
mapped[guard_offset..],
|
||||
os.PROT_READ | os.PROT_WRITE,
|
||||
os.PROT.READ | os.PROT.WRITE,
|
||||
) catch |err| switch (err) {
|
||||
error.AccessDenied => unreachable,
|
||||
else => |e| return e,
|
||||
@ -923,10 +923,10 @@ const LinuxThreadImpl = struct {
|
||||
.thread = .{ .mapped = mapped },
|
||||
};
|
||||
|
||||
const flags: u32 = os.CLONE_THREAD | os.CLONE_DETACHED |
|
||||
os.CLONE_VM | os.CLONE_FS | os.CLONE_FILES |
|
||||
os.CLONE_PARENT_SETTID | os.CLONE_CHILD_CLEARTID |
|
||||
os.CLONE_SIGHAND | os.CLONE_SYSVSEM | os.CLONE_SETTLS;
|
||||
const flags: u32 = linux.CLONE.THREAD | linux.CLONE.DETACHED |
|
||||
linux.CLONE.VM | linux.CLONE.FS | linux.CLONE.FILES |
|
||||
linux.CLONE.PARENT_SETTID | linux.CLONE.CHILD_CLEARTID |
|
||||
linux.CLONE.SIGHAND | linux.CLONE.SYSVSEM | linux.CLONE.SETTLS;
|
||||
|
||||
switch (linux.getErrno(linux.clone(
|
||||
Instance.entryFn,
|
||||
@ -978,7 +978,7 @@ const LinuxThreadImpl = struct {
|
||||
|
||||
switch (linux.getErrno(linux.futex_wait(
|
||||
&self.thread.child_tid.value,
|
||||
linux.FUTEX_WAIT,
|
||||
linux.FUTEX.WAIT,
|
||||
tid,
|
||||
null,
|
||||
))) {
|
||||
|
||||
@ -142,7 +142,7 @@ const LinuxFutex = struct {
|
||||
|
||||
switch (linux.getErrno(linux.futex_wait(
|
||||
@ptrCast(*const i32, ptr),
|
||||
linux.FUTEX_PRIVATE_FLAG | linux.FUTEX_WAIT,
|
||||
linux.FUTEX.PRIVATE_FLAG | linux.FUTEX.WAIT,
|
||||
@bitCast(i32, expect),
|
||||
ts_ptr,
|
||||
))) {
|
||||
@ -159,7 +159,7 @@ const LinuxFutex = struct {
|
||||
fn wake(ptr: *const Atomic(u32), num_waiters: u32) void {
|
||||
switch (linux.getErrno(linux.futex_wake(
|
||||
@ptrCast(*const i32, ptr),
|
||||
linux.FUTEX_PRIVATE_FLAG | linux.FUTEX_WAKE,
|
||||
linux.FUTEX.PRIVATE_FLAG | linux.FUTEX.WAKE,
|
||||
std.math.cast(i32, num_waiters) catch std.math.maxInt(i32),
|
||||
))) {
|
||||
.SUCCESS => {}, // successful wake up
|
||||
@ -352,7 +352,7 @@ const PosixFutex = struct {
|
||||
var ts_ptr: ?*const std.os.timespec = null;
|
||||
if (timeout) |timeout_ns| {
|
||||
ts_ptr = &ts;
|
||||
std.os.clock_gettime(std.os.CLOCK_REALTIME, &ts) catch unreachable;
|
||||
std.os.clock_gettime(std.os.CLOCK.REALTIME, &ts) catch unreachable;
|
||||
ts.tv_sec += @intCast(@TypeOf(ts.tv_sec), timeout_ns / std.time.ns_per_s);
|
||||
ts.tv_nsec += @intCast(@TypeOf(ts.tv_nsec), timeout_ns % std.time.ns_per_s);
|
||||
if (ts.tv_nsec >= std.time.ns_per_s) {
|
||||
|
||||
@ -152,7 +152,7 @@ pub const PosixEvent = struct {
|
||||
pub fn timedWait(ev: *PosixEvent, timeout_ns: u64) TimedWaitResult {
|
||||
var ts: os.timespec = undefined;
|
||||
var timeout_abs = timeout_ns;
|
||||
os.clock_gettime(os.CLOCK_REALTIME, &ts) catch return .timed_out;
|
||||
os.clock_gettime(os.CLOCK.REALTIME, &ts) catch return .timed_out;
|
||||
timeout_abs += @intCast(u64, ts.tv_sec) * time.ns_per_s;
|
||||
timeout_abs += @intCast(u64, ts.tv_nsec);
|
||||
ts.tv_sec = @intCast(@TypeOf(ts.tv_sec), @divFloor(timeout_abs, time.ns_per_s));
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
const std = @import("std");
|
||||
const builtin = std.builtin;
|
||||
const page_size = std.mem.page_size;
|
||||
const iovec = std.os.iovec;
|
||||
const iovec_const = std.os.iovec_const;
|
||||
|
||||
pub const tokenizer = @import("c/tokenizer.zig");
|
||||
pub const Token = tokenizer.Token;
|
||||
@ -28,14 +30,9 @@ const system = switch (builtin.os.tag) {
|
||||
.wasi => @import("c/wasi.zig"),
|
||||
else => struct {},
|
||||
};
|
||||
pub const E = system.E;
|
||||
|
||||
pub const _errno = system._errno;
|
||||
pub const MAP_FAILED = system.MAP_FAILED;
|
||||
pub const AI = system.AI;
|
||||
pub const NI = system.NI;
|
||||
pub const EAI = system.EAI;
|
||||
pub const timespec = system.timespec;
|
||||
pub const Sigaction = system.Sigaction;
|
||||
pub const copy_file_range = system.copy_file_range;
|
||||
pub const fallocate64 = system.fallocate64;
|
||||
pub const fopen64 = system.fopen64;
|
||||
pub const fstat64 = system.fstat64;
|
||||
@ -53,21 +50,53 @@ pub const pwritev64 = system.pwritev64;
|
||||
pub const sendfile64 = system.sendfile64;
|
||||
pub const setrlimit64 = system.setrlimit64;
|
||||
|
||||
pub const AF = system.AF;
|
||||
pub const AI = system.AI;
|
||||
pub const AT = system.AT;
|
||||
pub const CLOCK = system.CLOCK;
|
||||
pub const CPU_COUNT = system.CPU_COUNT;
|
||||
pub const E = system.E;
|
||||
pub const EAI = system.EAI;
|
||||
pub const F = system.F;
|
||||
pub const FD_CLOEXEC = system.FD_CLOEXEC;
|
||||
pub const F_OK = system.F_OK;
|
||||
pub const HOST_NAME_MAX = system.HOST_NAME_MAX;
|
||||
pub const IFNAMESIZE = system.IFNAMESIZE;
|
||||
pub const IOV_MAX = system.IOV_MAX;
|
||||
pub const IPPROTO = system.IPPROTO;
|
||||
pub const LOCK = system.LOCK;
|
||||
pub const MADV = system.MADV;
|
||||
pub const MAP = system.MAP;
|
||||
pub const NAME_MAX = system.NAME_MAX;
|
||||
pub const NI = system.NI;
|
||||
pub const O = system.O;
|
||||
pub const PATH_MAX = system.PATH_MAX;
|
||||
pub const POLL = system.POLL;
|
||||
pub const PROT = system.PROT;
|
||||
pub const REG = system.REG;
|
||||
pub const RLIM = system.RLIM;
|
||||
pub const RTLD = system.RTLD;
|
||||
pub const R_OK = system.R_OK;
|
||||
pub const S = system.S;
|
||||
pub const SA = system.SA;
|
||||
pub const SEEK = system.SEEK;
|
||||
pub const SHUT = system.SHUT;
|
||||
pub const SIG = system.SIG;
|
||||
pub const SIOCGIFINDEX = system.SIOCGIFINDEX;
|
||||
pub const SO = system.SO;
|
||||
pub const SOCK = system.SOCK;
|
||||
pub const SOL = system.SOL;
|
||||
pub const STDERR_FILENO = system.STDIN_FILENO;
|
||||
pub const STDIN_FILENO = system.STDIN_FILENO;
|
||||
pub const STDOUT_FILENO = system.STDIN_FILENO;
|
||||
pub const Sigaction = system.Sigaction;
|
||||
pub const Stat = system.Stat;
|
||||
pub const copy_file_range = system.copy_file_range;
|
||||
pub const W = system.W;
|
||||
pub const W_OK = system.W_OK;
|
||||
pub const X_OK = system.X_OK;
|
||||
pub const addrinfo = system.addrinfo;
|
||||
pub const cpu_set_t = system.cpu_set_t;
|
||||
pub const dl_iterate_phdr = system.dl_iterate_phdr;
|
||||
pub const dl_iterate_phdr_callback = system.dl_iterate_phdr_callback;
|
||||
pub const dl_phdr_info = system.dl_phdr_info;
|
||||
pub const empty_sigset = system.empty_sigset;
|
||||
@ -81,12 +110,19 @@ pub const fd_t = system.fd_t;
|
||||
pub const getauxval = system.getauxval;
|
||||
pub const getdents = system.getdents;
|
||||
pub const getrandom = system.getrandom;
|
||||
pub const gid_t = system.gid_t;
|
||||
pub const ifreq = system.ifreq;
|
||||
pub const ino_t = system.ino_t;
|
||||
pub const inotify_add_watch = system.inotify_add_watch;
|
||||
pub const inotify_init1 = system.inotify_init1;
|
||||
pub const inotify_rm_watch = system.inotify_rm_watch;
|
||||
pub const madvise = system.madvise;
|
||||
pub const malloc_usable_size = system.malloc_usable_size;
|
||||
pub const memfd_create = system.memfd_create;
|
||||
pub const mode_t = system.mode_t;
|
||||
pub const nfds_t = system.nfds_t;
|
||||
pub const off_t = system.off_t;
|
||||
pub const pid_t = system.pid_t;
|
||||
pub const pipe2 = system.pipe2;
|
||||
pub const pollfd = system.pollfd;
|
||||
pub const posix_memalign = system.posix_memalign;
|
||||
@ -97,6 +133,7 @@ pub const pthread_getname_np = system.pthread_getname_np;
|
||||
pub const pthread_mutex_t = system.pthread_mutex_t;
|
||||
pub const pthread_rwlock_t = system.pthread_rwlock_t;
|
||||
pub const pthread_setname_np = system.pthread_setname_np;
|
||||
pub const rlim_t = system.rlim_t;
|
||||
pub const rlimit = system.rlimit;
|
||||
pub const rlimit_resource = system.rlimit_resource;
|
||||
pub const sched_getaffinity = system.sched_getaffinity;
|
||||
@ -106,14 +143,14 @@ pub const sigaltstack = system.sigaltstack;
|
||||
pub const siginfo_t = system.siginfo_t;
|
||||
pub const signalfd = system.signalfd;
|
||||
pub const sigset_t = system.sigset_t;
|
||||
pub const MAP = system.MAP;
|
||||
pub const LOCK = system.LOCK;
|
||||
pub const REG = system.REG;
|
||||
pub const dl_iterate_phdr = system.dl_iterate_phdr;
|
||||
pub const ino_t = system.ino_t;
|
||||
pub const mode_t = system.mode_t;
|
||||
pub const sockaddr = system.sockaddr;
|
||||
pub const socklen_t = system.socklen_t;
|
||||
pub const stack_t = system.stack_t;
|
||||
pub const timespec = system.timespec;
|
||||
pub const timeval = system.timeval;
|
||||
pub const ucontext_t = system.ucontext_t;
|
||||
pub const O = system.O;
|
||||
pub const uid_t = system.uid_t;
|
||||
pub const utsname = system.utsname;
|
||||
|
||||
pub const alarm = if (@hasDecl(system, "alarm")) system.alarm else generic.alarm;
|
||||
pub const clock_getres = if (@hasDecl(system, "clock_getres")) system.clock_getres else generic.clock_getres;
|
||||
|
||||
@ -109,17 +109,16 @@ 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;
|
||||
pub const AI = struct {
|
||||
/// get address to use bind()
|
||||
pub const PASSIVE = 0x00000001;
|
||||
/// fill ai_canonname
|
||||
pub const CANONNAME = 0x00000002;
|
||||
/// prevent host name resolution
|
||||
pub const NUMERICHOST = 0x00000004;
|
||||
/// prevent service name resolution
|
||||
pub const NUMERICSERV = 0x00001000;
|
||||
};
|
||||
|
||||
pub const EAI = enum(c_int) {
|
||||
/// address family for hostname not supported
|
||||
@ -292,31 +291,31 @@ pub const sockaddr = extern struct {
|
||||
len: u8,
|
||||
family: sa_family_t,
|
||||
data: [14]u8,
|
||||
};
|
||||
pub const sockaddr_storage = std.x.os.Socket.Address.Native.Storage;
|
||||
pub const sockaddr_in = extern struct {
|
||||
len: u8 = @sizeOf(sockaddr_in),
|
||||
family: sa_family_t = AF_INET,
|
||||
port: in_port_t,
|
||||
addr: u32,
|
||||
zero: [8]u8 = [8]u8{ 0, 0, 0, 0, 0, 0, 0, 0 },
|
||||
};
|
||||
pub const sockaddr_in6 = extern struct {
|
||||
len: u8 = @sizeOf(sockaddr_in6),
|
||||
family: sa_family_t = AF_INET6,
|
||||
port: in_port_t,
|
||||
flowinfo: u32,
|
||||
addr: [16]u8,
|
||||
scope_id: u32,
|
||||
};
|
||||
|
||||
/// UNIX domain socket
|
||||
pub const sockaddr_un = extern struct {
|
||||
len: u8 = @sizeOf(sockaddr_un),
|
||||
family: sa_family_t = AF_UNIX,
|
||||
path: [104]u8,
|
||||
};
|
||||
pub const storage = std.x.os.Socket.Address.Native.Storage;
|
||||
pub const in = extern struct {
|
||||
len: u8 = @sizeOf(in),
|
||||
family: sa_family_t = AF.INET,
|
||||
port: in_port_t,
|
||||
addr: u32,
|
||||
zero: [8]u8 = [8]u8{ 0, 0, 0, 0, 0, 0, 0, 0 },
|
||||
};
|
||||
pub const in6 = extern struct {
|
||||
len: u8 = @sizeOf(in6),
|
||||
family: sa_family_t = AF.INET6,
|
||||
port: in_port_t,
|
||||
flowinfo: u32,
|
||||
addr: [16]u8,
|
||||
scope_id: u32,
|
||||
};
|
||||
|
||||
/// UNIX domain socket
|
||||
pub const un = extern struct {
|
||||
len: u8 = @sizeOf(un),
|
||||
family: sa_family_t = AF.UNIX,
|
||||
path: [104]u8,
|
||||
};
|
||||
};
|
||||
pub const timeval = extern struct {
|
||||
tv_sec: c_long,
|
||||
tv_usec: i32,
|
||||
@ -521,30 +520,25 @@ pub const PROT_WRITE = 0x02;
|
||||
/// [MC2] pages can be executed
|
||||
pub const PROT_EXEC = 0x04;
|
||||
|
||||
/// allocated from memory, swap space
|
||||
pub const MAP_ANONYMOUS = 0x1000;
|
||||
|
||||
/// map from file (default)
|
||||
pub const MAP_FILE = 0x0000;
|
||||
|
||||
/// interpret addr exactly
|
||||
pub const MAP_FIXED = 0x0010;
|
||||
|
||||
/// region may contain semaphores
|
||||
pub const MAP_HASSEMAPHORE = 0x0200;
|
||||
|
||||
/// changes are private
|
||||
pub const MAP_PRIVATE = 0x0002;
|
||||
|
||||
/// share changes
|
||||
pub const MAP_SHARED = 0x0001;
|
||||
|
||||
/// don't cache pages for this mapping
|
||||
pub const MAP_NOCACHE = 0x0400;
|
||||
|
||||
/// don't reserve needed swap area
|
||||
pub const MAP_NORESERVE = 0x0040;
|
||||
pub const MAP_FAILED = @intToPtr(*c_void, maxInt(usize));
|
||||
pub const MAP = struct {
|
||||
/// allocated from memory, swap space
|
||||
pub const ANONYMOUS = 0x1000;
|
||||
/// map from file (default)
|
||||
pub const FILE = 0x0000;
|
||||
/// interpret addr exactly
|
||||
pub const FIXED = 0x0010;
|
||||
/// region may contain semaphores
|
||||
pub const HASSEMAPHORE = 0x0200;
|
||||
/// changes are private
|
||||
pub const PRIVATE = 0x0002;
|
||||
/// share changes
|
||||
pub const SHARED = 0x0001;
|
||||
/// don't cache pages for this mapping
|
||||
pub const NOCACHE = 0x0400;
|
||||
/// don't reserve needed swap area
|
||||
pub const NORESERVE = 0x0040;
|
||||
pub const FAILED = @intToPtr(*c_void, maxInt(usize));
|
||||
};
|
||||
|
||||
/// [XSI] no hang in wait/no child to reap
|
||||
pub const WNOHANG = 0x00000001;
|
||||
@ -980,136 +974,148 @@ pub const NOTE_MACH_CONTINUOUS_TIME = 0x00000080;
|
||||
/// data is mach absolute time units
|
||||
pub const NOTE_MACHTIME = 0x00000100;
|
||||
|
||||
pub const AF_UNSPEC = 0;
|
||||
pub const AF_LOCAL = 1;
|
||||
pub const AF_UNIX = AF_LOCAL;
|
||||
pub const AF_INET = 2;
|
||||
pub const AF_SYS_CONTROL = 2;
|
||||
pub const AF_IMPLINK = 3;
|
||||
pub const AF_PUP = 4;
|
||||
pub const AF_CHAOS = 5;
|
||||
pub const AF_NS = 6;
|
||||
pub const AF_ISO = 7;
|
||||
pub const AF_OSI = AF_ISO;
|
||||
pub const AF_ECMA = 8;
|
||||
pub const AF_DATAKIT = 9;
|
||||
pub const AF_CCITT = 10;
|
||||
pub const AF_SNA = 11;
|
||||
pub const AF_DECnet = 12;
|
||||
pub const AF_DLI = 13;
|
||||
pub const AF_LAT = 14;
|
||||
pub const AF_HYLINK = 15;
|
||||
pub const AF_APPLETALK = 16;
|
||||
pub const AF_ROUTE = 17;
|
||||
pub const AF_LINK = 18;
|
||||
pub const AF_XTP = 19;
|
||||
pub const AF_COIP = 20;
|
||||
pub const AF_CNT = 21;
|
||||
pub const AF_RTIP = 22;
|
||||
pub const AF_IPX = 23;
|
||||
pub const AF_SIP = 24;
|
||||
pub const AF_PIP = 25;
|
||||
pub const AF_ISDN = 28;
|
||||
pub const AF_E164 = AF_ISDN;
|
||||
pub const AF_KEY = 29;
|
||||
pub const AF_INET6 = 30;
|
||||
pub const AF_NATM = 31;
|
||||
pub const AF_SYSTEM = 32;
|
||||
pub const AF_NETBIOS = 33;
|
||||
pub const AF_PPP = 34;
|
||||
pub const AF_MAX = 40;
|
||||
pub const AF = struct {
|
||||
pub const UNSPEC = 0;
|
||||
pub const LOCAL = 1;
|
||||
pub const UNIX = LOCAL;
|
||||
pub const INET = 2;
|
||||
pub const SYS_CONTROL = 2;
|
||||
pub const IMPLINK = 3;
|
||||
pub const PUP = 4;
|
||||
pub const CHAOS = 5;
|
||||
pub const NS = 6;
|
||||
pub const ISO = 7;
|
||||
pub const OSI = ISO;
|
||||
pub const ECMA = 8;
|
||||
pub const DATAKIT = 9;
|
||||
pub const CCITT = 10;
|
||||
pub const SNA = 11;
|
||||
pub const DECnet = 12;
|
||||
pub const DLI = 13;
|
||||
pub const LAT = 14;
|
||||
pub const HYLINK = 15;
|
||||
pub const APPLETALK = 16;
|
||||
pub const ROUTE = 17;
|
||||
pub const LINK = 18;
|
||||
pub const XTP = 19;
|
||||
pub const COIP = 20;
|
||||
pub const CNT = 21;
|
||||
pub const RTIP = 22;
|
||||
pub const IPX = 23;
|
||||
pub const SIP = 24;
|
||||
pub const PIP = 25;
|
||||
pub const ISDN = 28;
|
||||
pub const E164 = ISDN;
|
||||
pub const KEY = 29;
|
||||
pub const INET6 = 30;
|
||||
pub const NATM = 31;
|
||||
pub const SYSTEM = 32;
|
||||
pub const NETBIOS = 33;
|
||||
pub const PPP = 34;
|
||||
pub const MAX = 40;
|
||||
};
|
||||
|
||||
pub const PF_UNSPEC = AF_UNSPEC;
|
||||
pub const PF_LOCAL = AF_LOCAL;
|
||||
pub const PF_UNIX = PF_LOCAL;
|
||||
pub const PF_INET = AF_INET;
|
||||
pub const PF_IMPLINK = AF_IMPLINK;
|
||||
pub const PF_PUP = AF_PUP;
|
||||
pub const PF_CHAOS = AF_CHAOS;
|
||||
pub const PF_NS = AF_NS;
|
||||
pub const PF_ISO = AF_ISO;
|
||||
pub const PF_OSI = AF_ISO;
|
||||
pub const PF_ECMA = AF_ECMA;
|
||||
pub const PF_DATAKIT = AF_DATAKIT;
|
||||
pub const PF_CCITT = AF_CCITT;
|
||||
pub const PF_SNA = AF_SNA;
|
||||
pub const PF_DECnet = AF_DECnet;
|
||||
pub const PF_DLI = AF_DLI;
|
||||
pub const PF_LAT = AF_LAT;
|
||||
pub const PF_HYLINK = AF_HYLINK;
|
||||
pub const PF_APPLETALK = AF_APPLETALK;
|
||||
pub const PF_ROUTE = AF_ROUTE;
|
||||
pub const PF_LINK = AF_LINK;
|
||||
pub const PF_XTP = AF_XTP;
|
||||
pub const PF_COIP = AF_COIP;
|
||||
pub const PF_CNT = AF_CNT;
|
||||
pub const PF_SIP = AF_SIP;
|
||||
pub const PF_IPX = AF_IPX;
|
||||
pub const PF_RTIP = AF_RTIP;
|
||||
pub const PF_PIP = AF_PIP;
|
||||
pub const PF_ISDN = AF_ISDN;
|
||||
pub const PF_KEY = AF_KEY;
|
||||
pub const PF_INET6 = AF_INET6;
|
||||
pub const PF_NATM = AF_NATM;
|
||||
pub const PF_SYSTEM = AF_SYSTEM;
|
||||
pub const PF_NETBIOS = AF_NETBIOS;
|
||||
pub const PF_PPP = AF_PPP;
|
||||
pub const PF_MAX = AF_MAX;
|
||||
pub const PF = struct {
|
||||
pub const UNSPEC = AF.UNSPEC;
|
||||
pub const LOCAL = AF.LOCAL;
|
||||
pub const UNIX = PF.LOCAL;
|
||||
pub const INET = AF.INET;
|
||||
pub const IMPLINK = AF.IMPLINK;
|
||||
pub const PUP = AF.PUP;
|
||||
pub const CHAOS = AF.CHAOS;
|
||||
pub const NS = AF.NS;
|
||||
pub const ISO = AF.ISO;
|
||||
pub const OSI = AF.ISO;
|
||||
pub const ECMA = AF.ECMA;
|
||||
pub const DATAKIT = AF.DATAKIT;
|
||||
pub const CCITT = AF.CCITT;
|
||||
pub const SNA = AF.SNA;
|
||||
pub const DECnet = AF.DECnet;
|
||||
pub const DLI = AF.DLI;
|
||||
pub const LAT = AF.LAT;
|
||||
pub const HYLINK = AF.HYLINK;
|
||||
pub const APPLETALK = AF.APPLETALK;
|
||||
pub const ROUTE = AF.ROUTE;
|
||||
pub const LINK = AF.LINK;
|
||||
pub const XTP = AF.XTP;
|
||||
pub const COIP = AF.COIP;
|
||||
pub const CNT = AF.CNT;
|
||||
pub const SIP = AF.SIP;
|
||||
pub const IPX = AF.IPX;
|
||||
pub const RTIP = AF.RTIP;
|
||||
pub const PIP = AF.PIP;
|
||||
pub const ISDN = AF.ISDN;
|
||||
pub const KEY = AF.KEY;
|
||||
pub const INET6 = AF.INET6;
|
||||
pub const NATM = AF.NATM;
|
||||
pub const SYSTEM = AF.SYSTEM;
|
||||
pub const NETBIOS = AF.NETBIOS;
|
||||
pub const PPP = AF.PPP;
|
||||
pub const MAX = AF.MAX;
|
||||
};
|
||||
|
||||
pub const SYSPROTO_EVENT = 1;
|
||||
pub const SYSPROTO_CONTROL = 2;
|
||||
|
||||
pub const SOCK_STREAM = 1;
|
||||
pub const SOCK_DGRAM = 2;
|
||||
pub const SOCK_RAW = 3;
|
||||
pub const SOCK_RDM = 4;
|
||||
pub const SOCK_SEQPACKET = 5;
|
||||
pub const SOCK_MAXADDRLEN = 255;
|
||||
pub const SOCK = struct {
|
||||
pub const STREAM = 1;
|
||||
pub const DGRAM = 2;
|
||||
pub const RAW = 3;
|
||||
pub const RDM = 4;
|
||||
pub const SEQPACKET = 5;
|
||||
pub const MAXADDRLEN = 255;
|
||||
|
||||
/// Not actually supported by Darwin, but Zig supplies a shim.
|
||||
/// This numerical value is not ABI-stable. It need only not conflict
|
||||
/// with any other "SOCK_" bits.
|
||||
pub const SOCK_CLOEXEC = 1 << 15;
|
||||
/// Not actually supported by Darwin, but Zig supplies a shim.
|
||||
/// This numerical value is not ABI-stable. It need only not conflict
|
||||
/// with any other "SOCK_" bits.
|
||||
pub const SOCK_NONBLOCK = 1 << 16;
|
||||
/// Not actually supported by Darwin, but Zig supplies a shim.
|
||||
/// This numerical value is not ABI-stable. It need only not conflict
|
||||
/// with any other `SOCK` bits.
|
||||
pub const CLOEXEC = 1 << 15;
|
||||
/// Not actually supported by Darwin, but Zig supplies a shim.
|
||||
/// This numerical value is not ABI-stable. It need only not conflict
|
||||
/// with any other `SOCK` bits.
|
||||
pub const NONBLOCK = 1 << 16;
|
||||
};
|
||||
|
||||
pub const IPPROTO_ICMP = 1;
|
||||
pub const IPPROTO_ICMPV6 = 58;
|
||||
pub const IPPROTO_TCP = 6;
|
||||
pub const IPPROTO_UDP = 17;
|
||||
pub const IPPROTO_IP = 0;
|
||||
pub const IPPROTO_IPV6 = 41;
|
||||
pub const IPPROTO = struct {
|
||||
pub const ICMP = 1;
|
||||
pub const ICMPV6 = 58;
|
||||
pub const TCP = 6;
|
||||
pub const UDP = 17;
|
||||
pub const IP = 0;
|
||||
pub const IPV6 = 41;
|
||||
};
|
||||
|
||||
pub const SOL_SOCKET = 0xffff;
|
||||
pub const SOL = struct {
|
||||
pub const SOCKET = 0xffff;
|
||||
};
|
||||
|
||||
pub const SO_DEBUG = 0x0001;
|
||||
pub const SO_ACCEPTCONN = 0x0002;
|
||||
pub const SO_REUSEADDR = 0x0004;
|
||||
pub const SO_KEEPALIVE = 0x0008;
|
||||
pub const SO_DONTROUTE = 0x0010;
|
||||
pub const SO_BROADCAST = 0x0020;
|
||||
pub const SO_USELOOPBACK = 0x0040;
|
||||
pub const SO_LINGER = 0x1080;
|
||||
pub const SO_OOBINLINE = 0x0100;
|
||||
pub const SO_REUSEPORT = 0x0200;
|
||||
pub const SO_ACCEPTFILTER = 0x1000;
|
||||
pub const SO_SNDBUF = 0x1001;
|
||||
pub const SO_RCVBUF = 0x1002;
|
||||
pub const SO_SNDLOWAT = 0x1003;
|
||||
pub const SO_RCVLOWAT = 0x1004;
|
||||
pub const SO_SNDTIMEO = 0x1005;
|
||||
pub const SO_RCVTIMEO = 0x1006;
|
||||
pub const SO_ERROR = 0x1007;
|
||||
pub const SO_TYPE = 0x1008;
|
||||
pub const SO = struct {
|
||||
pub const DEBUG = 0x0001;
|
||||
pub const ACCEPTCONN = 0x0002;
|
||||
pub const REUSEADDR = 0x0004;
|
||||
pub const KEEPALIVE = 0x0008;
|
||||
pub const DONTROUTE = 0x0010;
|
||||
pub const BROADCAST = 0x0020;
|
||||
pub const USELOOPBACK = 0x0040;
|
||||
pub const LINGER = 0x1080;
|
||||
pub const OOBINLINE = 0x0100;
|
||||
pub const REUSEPORT = 0x0200;
|
||||
pub const ACCEPTFILTER = 0x1000;
|
||||
pub const SNDBUF = 0x1001;
|
||||
pub const RCVBUF = 0x1002;
|
||||
pub const SNDLOWAT = 0x1003;
|
||||
pub const RCVLOWAT = 0x1004;
|
||||
pub const SNDTIMEO = 0x1005;
|
||||
pub const RCVTIMEO = 0x1006;
|
||||
pub const ERROR = 0x1007;
|
||||
pub const TYPE = 0x1008;
|
||||
|
||||
pub const SO_NREAD = 0x1020;
|
||||
pub const SO_NKE = 0x1021;
|
||||
pub const SO_NOSIGPIPE = 0x1022;
|
||||
pub const SO_NOADDRERR = 0x1023;
|
||||
pub const SO_NWRITE = 0x1024;
|
||||
pub const SO_REUSESHAREUID = 0x1025;
|
||||
pub const NREAD = 0x1020;
|
||||
pub const NKE = 0x1021;
|
||||
pub const NOSIGPIPE = 0x1022;
|
||||
pub const NOADDRERR = 0x1023;
|
||||
pub const NWRITE = 0x1024;
|
||||
pub const REUSESHAREUID = 0x1025;
|
||||
};
|
||||
|
||||
fn wstatus(x: u32) u32 {
|
||||
return x & 0o177;
|
||||
@ -1569,18 +1575,20 @@ pub const addrinfo = extern struct {
|
||||
next: ?*addrinfo,
|
||||
};
|
||||
|
||||
pub const RTLD_LAZY = 0x1;
|
||||
pub const RTLD_NOW = 0x2;
|
||||
pub const RTLD_LOCAL = 0x4;
|
||||
pub const RTLD_GLOBAL = 0x8;
|
||||
pub const RTLD_NOLOAD = 0x10;
|
||||
pub const RTLD_NODELETE = 0x80;
|
||||
pub const RTLD_FIRST = 0x100;
|
||||
pub const RTLD = struct {
|
||||
pub const LAZY = 0x1;
|
||||
pub const NOW = 0x2;
|
||||
pub const LOCAL = 0x4;
|
||||
pub const GLOBAL = 0x8;
|
||||
pub const NOLOAD = 0x10;
|
||||
pub const NODELETE = 0x80;
|
||||
pub const FIRST = 0x100;
|
||||
|
||||
pub const RTLD_NEXT = @intToPtr(*c_void, @bitCast(usize, @as(isize, -1)));
|
||||
pub const RTLD_DEFAULT = @intToPtr(*c_void, @bitCast(usize, @as(isize, -2)));
|
||||
pub const RTLD_SELF = @intToPtr(*c_void, @bitCast(usize, @as(isize, -3)));
|
||||
pub const RTLD_MAIN_ONLY = @intToPtr(*c_void, @bitCast(usize, @as(isize, -5)));
|
||||
pub const NEXT = @intToPtr(*c_void, @bitCast(usize, @as(isize, -1)));
|
||||
pub const DEFAULT = @intToPtr(*c_void, @bitCast(usize, @as(isize, -2)));
|
||||
pub const SELF = @intToPtr(*c_void, @bitCast(usize, @as(isize, -3)));
|
||||
pub const MAIN_ONLY = @intToPtr(*c_void, @bitCast(usize, @as(isize, -5)));
|
||||
};
|
||||
|
||||
/// duplicate file descriptor
|
||||
pub const F_DUPFD = 0;
|
||||
@ -1740,10 +1748,12 @@ pub const F_UNLCK = 2;
|
||||
/// exclusive or write lock
|
||||
pub const F_WRLCK = 3;
|
||||
|
||||
pub const LOCK_SH = 1;
|
||||
pub const LOCK_EX = 2;
|
||||
pub const LOCK_UN = 8;
|
||||
pub const LOCK_NB = 4;
|
||||
pub const LOCK = struct {
|
||||
pub const SH = 1;
|
||||
pub const EX = 2;
|
||||
pub const UN = 8;
|
||||
pub const NB = 4;
|
||||
};
|
||||
|
||||
pub const nfds_t = u32;
|
||||
pub const pollfd = extern struct {
|
||||
@ -1752,33 +1762,37 @@ pub const pollfd = extern struct {
|
||||
revents: i16,
|
||||
};
|
||||
|
||||
pub const POLLIN = 0x001;
|
||||
pub const POLLPRI = 0x002;
|
||||
pub const POLLOUT = 0x004;
|
||||
pub const POLLRDNORM = 0x040;
|
||||
pub const POLLWRNORM = POLLOUT;
|
||||
pub const POLLRDBAND = 0x080;
|
||||
pub const POLLWRBAND = 0x100;
|
||||
pub const POLL = struct {
|
||||
pub const IN = 0x001;
|
||||
pub const PRI = 0x002;
|
||||
pub const OUT = 0x004;
|
||||
pub const RDNORM = 0x040;
|
||||
pub const WRNORM = OUT;
|
||||
pub const RDBAND = 0x080;
|
||||
pub const WRBAND = 0x100;
|
||||
|
||||
pub const POLLEXTEND = 0x0200;
|
||||
pub const POLLATTRIB = 0x0400;
|
||||
pub const POLLNLINK = 0x0800;
|
||||
pub const POLLWRITE = 0x1000;
|
||||
pub const EXTEND = 0x0200;
|
||||
pub const ATTRIB = 0x0400;
|
||||
pub const NLINK = 0x0800;
|
||||
pub const WRITE = 0x1000;
|
||||
|
||||
pub const POLLERR = 0x008;
|
||||
pub const POLLHUP = 0x010;
|
||||
pub const POLLNVAL = 0x020;
|
||||
pub const ERR = 0x008;
|
||||
pub const HUP = 0x010;
|
||||
pub const NVAL = 0x020;
|
||||
|
||||
pub const POLLSTANDARD = POLLIN | POLLPRI | POLLOUT | POLLRDNORM | POLLRDBAND | POLLWRBAND | POLLERR | POLLHUP | POLLNVAL;
|
||||
pub const STANDARD = IN | PRI | OUT | RDNORM | RDBAND | WRBAND | ERR | HUP | NVAL;
|
||||
};
|
||||
|
||||
pub const CLOCK_REALTIME = 0;
|
||||
pub const CLOCK_MONOTONIC = 6;
|
||||
pub const CLOCK_MONOTONIC_RAW = 4;
|
||||
pub const CLOCK_MONOTONIC_RAW_APPROX = 5;
|
||||
pub const CLOCK_UPTIME_RAW = 8;
|
||||
pub const CLOCK_UPTIME_RAW_APPROX = 9;
|
||||
pub const CLOCK_PROCESS_CPUTIME_ID = 12;
|
||||
pub const CLOCK_THREAD_CPUTIME_ID = 16;
|
||||
pub const CLOCK = struct {
|
||||
pub const REALTIME = 0;
|
||||
pub const MONOTONIC = 6;
|
||||
pub const MONOTONIC_RAW = 4;
|
||||
pub const MONOTONIC_RAW_APPROX = 5;
|
||||
pub const UPTIME_RAW = 8;
|
||||
pub const UPTIME_RAW_APPROX = 9;
|
||||
pub const PROCESS_CPUTIME_ID = 12;
|
||||
pub const THREAD_CPUTIME_ID = 16;
|
||||
};
|
||||
|
||||
/// Max open files per process
|
||||
/// https://opensource.apple.com/source/xnu/xnu-4903.221.2/bsd/sys/syslimits.h.auto.html
|
||||
@ -1822,11 +1836,13 @@ pub const rlimit_resource = enum(c_int) {
|
||||
|
||||
pub const rlim_t = u64;
|
||||
|
||||
/// No limit
|
||||
pub const RLIM_INFINITY: rlim_t = (1 << 63) - 1;
|
||||
pub const RLIM = struct {
|
||||
/// No limit
|
||||
pub const INFINITY: rlim_t = (1 << 63) - 1;
|
||||
|
||||
pub const RLIM_SAVED_MAX = RLIM_INFINITY;
|
||||
pub const RLIM_SAVED_CUR = RLIM_INFINITY;
|
||||
pub const SAVED_MAX = INFINITY;
|
||||
pub const SAVED_CUR = INFINITY;
|
||||
};
|
||||
|
||||
pub const rlimit = extern struct {
|
||||
/// Soft limit
|
||||
|
||||
@ -161,25 +161,27 @@ pub const PROT_READ = 1;
|
||||
pub const PROT_WRITE = 2;
|
||||
pub const PROT_EXEC = 4;
|
||||
|
||||
pub const MAP_FILE = 0;
|
||||
pub const MAP_FAILED = @intToPtr(*c_void, maxInt(usize));
|
||||
pub const MAP_ANONYMOUS = MAP_ANON;
|
||||
pub const MAP_COPY = MAP_PRIVATE;
|
||||
pub const MAP_SHARED = 1;
|
||||
pub const MAP_PRIVATE = 2;
|
||||
pub const MAP_FIXED = 16;
|
||||
pub const MAP_RENAME = 32;
|
||||
pub const MAP_NORESERVE = 64;
|
||||
pub const MAP_INHERIT = 128;
|
||||
pub const MAP_NOEXTEND = 256;
|
||||
pub const MAP_HASSEMAPHORE = 512;
|
||||
pub const MAP_STACK = 1024;
|
||||
pub const MAP_NOSYNC = 2048;
|
||||
pub const MAP_ANON = 4096;
|
||||
pub const MAP_VPAGETABLE = 8192;
|
||||
pub const MAP_TRYFIXED = 65536;
|
||||
pub const MAP_NOCORE = 131072;
|
||||
pub const MAP_SIZEALIGN = 262144;
|
||||
pub const MAP = struct {
|
||||
pub const FILE = 0;
|
||||
pub const FAILED = @intToPtr(*c_void, maxInt(usize));
|
||||
pub const ANONYMOUS = ANON;
|
||||
pub const COPY = PRIVATE;
|
||||
pub const SHARED = 1;
|
||||
pub const PRIVATE = 2;
|
||||
pub const FIXED = 16;
|
||||
pub const RENAME = 32;
|
||||
pub const NORESERVE = 64;
|
||||
pub const INHERIT = 128;
|
||||
pub const NOEXTEND = 256;
|
||||
pub const HASSEMAPHORE = 512;
|
||||
pub const STACK = 1024;
|
||||
pub const NOSYNC = 2048;
|
||||
pub const ANON = 4096;
|
||||
pub const VPAGETABLE = 8192;
|
||||
pub const TRYFIXED = 65536;
|
||||
pub const NOCORE = 131072;
|
||||
pub const SIZEALIGN = 262144;
|
||||
};
|
||||
|
||||
pub const WNOHANG = 0x0001;
|
||||
pub const WUNTRACED = 0x0002;
|
||||
@ -407,28 +409,47 @@ pub const DT_SOCK = 12;
|
||||
pub const DT_WHT = 14;
|
||||
pub const DT_DBF = 15;
|
||||
|
||||
pub const CLOCK_REALTIME = 0;
|
||||
pub const CLOCK_VIRTUAL = 1;
|
||||
pub const CLOCK_PROF = 2;
|
||||
pub const CLOCK_MONOTONIC = 4;
|
||||
pub const CLOCK_UPTIME = 5;
|
||||
pub const CLOCK_UPTIME_PRECISE = 7;
|
||||
pub const CLOCK_UPTIME_FAST = 8;
|
||||
pub const CLOCK_REALTIME_PRECISE = 9;
|
||||
pub const CLOCK_REALTIME_FAST = 10;
|
||||
pub const CLOCK_MONOTONIC_PRECISE = 11;
|
||||
pub const CLOCK_MONOTONIC_FAST = 12;
|
||||
pub const CLOCK_SECOND = 13;
|
||||
pub const CLOCK_THREAD_CPUTIME_ID = 14;
|
||||
pub const CLOCK_PROCESS_CPUTIME_ID = 15;
|
||||
pub const CLOCK = struct {
|
||||
pub const REALTIME = 0;
|
||||
pub const VIRTUAL = 1;
|
||||
pub const PROF = 2;
|
||||
pub const MONOTONIC = 4;
|
||||
pub const UPTIME = 5;
|
||||
pub const UPTIME_PRECISE = 7;
|
||||
pub const UPTIME_FAST = 8;
|
||||
pub const REALTIME_PRECISE = 9;
|
||||
pub const REALTIME_FAST = 10;
|
||||
pub const MONOTONIC_PRECISE = 11;
|
||||
pub const MONOTONIC_FAST = 12;
|
||||
pub const SECOND = 13;
|
||||
pub const THREAD_CPUTIME_ID = 14;
|
||||
pub const PROCESS_CPUTIME_ID = 15;
|
||||
};
|
||||
|
||||
pub const sockaddr = extern struct {
|
||||
len: u8,
|
||||
family: u8,
|
||||
data: [14]u8,
|
||||
};
|
||||
|
||||
pub const sockaddr_storage = std.x.os.Socket.Address.Native.Storage;
|
||||
pub const storage = std.x.os.Socket.Address.Native.Storage;
|
||||
|
||||
pub const in = extern struct {
|
||||
len: u8 = @sizeOf(in),
|
||||
family: sa_family_t = AF.INET,
|
||||
port: in_port_t,
|
||||
addr: u32,
|
||||
zero: [8]u8 = [8]u8{ 0, 0, 0, 0, 0, 0, 0, 0 },
|
||||
};
|
||||
|
||||
pub const in6 = extern struct {
|
||||
len: u8 = @sizeOf(in6),
|
||||
family: sa_family_t = AF.INET6,
|
||||
port: in_port_t,
|
||||
flowinfo: u32,
|
||||
addr: [16]u8,
|
||||
scope_id: u32,
|
||||
};
|
||||
};
|
||||
|
||||
pub const Kevent = extern struct {
|
||||
ident: usize,
|
||||
@ -616,135 +637,128 @@ pub const Sigaction = extern struct {
|
||||
|
||||
pub const sig_t = [*c]fn (c_int) callconv(.C) void;
|
||||
|
||||
pub const SOCK_STREAM = 1;
|
||||
pub const SOCK_DGRAM = 2;
|
||||
pub const SOCK_RAW = 3;
|
||||
pub const SOCK_RDM = 4;
|
||||
pub const SOCK_SEQPACKET = 5;
|
||||
pub const SOCK_MAXADDRLEN = 255;
|
||||
pub const SOCK_CLOEXEC = 0x10000000;
|
||||
pub const SOCK_NONBLOCK = 0x20000000;
|
||||
pub const SOCK = struct {
|
||||
pub const STREAM = 1;
|
||||
pub const DGRAM = 2;
|
||||
pub const RAW = 3;
|
||||
pub const RDM = 4;
|
||||
pub const SEQPACKET = 5;
|
||||
pub const MAXADDRLEN = 255;
|
||||
pub const CLOEXEC = 0x10000000;
|
||||
pub const NONBLOCK = 0x20000000;
|
||||
};
|
||||
|
||||
pub const SO_DEBUG = 0x0001;
|
||||
pub const SO_ACCEPTCONN = 0x0002;
|
||||
pub const SO_REUSEADDR = 0x0004;
|
||||
pub const SO_KEEPALIVE = 0x0008;
|
||||
pub const SO_DONTROUTE = 0x0010;
|
||||
pub const SO_BROADCAST = 0x0020;
|
||||
pub const SO_USELOOPBACK = 0x0040;
|
||||
pub const SO_LINGER = 0x0080;
|
||||
pub const SO_OOBINLINE = 0x0100;
|
||||
pub const SO_REUSEPORT = 0x0200;
|
||||
pub const SO_TIMESTAMP = 0x0400;
|
||||
pub const SO_NOSIGPIPE = 0x0800;
|
||||
pub const SO_ACCEPTFILTER = 0x1000;
|
||||
pub const SO_RERROR = 0x2000;
|
||||
pub const SO_PASSCRED = 0x4000;
|
||||
pub const SO = struct {
|
||||
pub const DEBUG = 0x0001;
|
||||
pub const ACCEPTCONN = 0x0002;
|
||||
pub const REUSEADDR = 0x0004;
|
||||
pub const KEEPALIVE = 0x0008;
|
||||
pub const DONTROUTE = 0x0010;
|
||||
pub const BROADCAST = 0x0020;
|
||||
pub const USELOOPBACK = 0x0040;
|
||||
pub const LINGER = 0x0080;
|
||||
pub const OOBINLINE = 0x0100;
|
||||
pub const REUSEPORT = 0x0200;
|
||||
pub const TIMESTAMP = 0x0400;
|
||||
pub const NOSIGPIPE = 0x0800;
|
||||
pub const ACCEPTFILTER = 0x1000;
|
||||
pub const RERROR = 0x2000;
|
||||
pub const PASSCRED = 0x4000;
|
||||
|
||||
pub const SO_SNDBUF = 0x1001;
|
||||
pub const SO_RCVBUF = 0x1002;
|
||||
pub const SO_SNDLOWAT = 0x1003;
|
||||
pub const SO_RCVLOWAT = 0x1004;
|
||||
pub const SO_SNDTIMEO = 0x1005;
|
||||
pub const SO_RCVTIMEO = 0x1006;
|
||||
pub const SO_ERROR = 0x1007;
|
||||
pub const SO_TYPE = 0x1008;
|
||||
pub const SO_SNDSPACE = 0x100a;
|
||||
pub const SO_CPUHINT = 0x1030;
|
||||
pub const SNDBUF = 0x1001;
|
||||
pub const RCVBUF = 0x1002;
|
||||
pub const SNDLOWAT = 0x1003;
|
||||
pub const RCVLOWAT = 0x1004;
|
||||
pub const SNDTIMEO = 0x1005;
|
||||
pub const RCVTIMEO = 0x1006;
|
||||
pub const ERROR = 0x1007;
|
||||
pub const TYPE = 0x1008;
|
||||
pub const SNDSPACE = 0x100a;
|
||||
pub const CPUHINT = 0x1030;
|
||||
};
|
||||
|
||||
pub const SOL_SOCKET = 0xffff;
|
||||
pub const SOL = struct {
|
||||
pub const SOCKET = 0xffff;
|
||||
};
|
||||
|
||||
pub const PF_INET6 = AF_INET6;
|
||||
pub const PF_IMPLINK = AF_IMPLINK;
|
||||
pub const PF_ROUTE = AF_ROUTE;
|
||||
pub const PF_ISO = AF_ISO;
|
||||
pub const PF_PIP = pseudo_AF_PIP;
|
||||
pub const PF_CHAOS = AF_CHAOS;
|
||||
pub const PF_DATAKIT = AF_DATAKIT;
|
||||
pub const PF_INET = AF_INET;
|
||||
pub const PF_APPLETALK = AF_APPLETALK;
|
||||
pub const PF_SIP = AF_SIP;
|
||||
pub const PF_OSI = AF_ISO;
|
||||
pub const PF_CNT = AF_CNT;
|
||||
pub const PF_LINK = AF_LINK;
|
||||
pub const PF_HYLINK = AF_HYLINK;
|
||||
pub const PF_MAX = AF_MAX;
|
||||
pub const PF_KEY = pseudo_AF_KEY;
|
||||
pub const PF_PUP = AF_PUP;
|
||||
pub const PF_COIP = AF_COIP;
|
||||
pub const PF_SNA = AF_SNA;
|
||||
pub const PF_LOCAL = AF_LOCAL;
|
||||
pub const PF_NETBIOS = AF_NETBIOS;
|
||||
pub const PF_NATM = AF_NATM;
|
||||
pub const PF_BLUETOOTH = AF_BLUETOOTH;
|
||||
pub const PF_UNSPEC = AF_UNSPEC;
|
||||
pub const PF_NETGRAPH = AF_NETGRAPH;
|
||||
pub const PF_ECMA = AF_ECMA;
|
||||
pub const PF_IPX = AF_IPX;
|
||||
pub const PF_DLI = AF_DLI;
|
||||
pub const PF_ATM = AF_ATM;
|
||||
pub const PF_CCITT = AF_CCITT;
|
||||
pub const PF_ISDN = AF_ISDN;
|
||||
pub const PF_RTIP = pseudo_AF_RTIP;
|
||||
pub const PF_LAT = AF_LAT;
|
||||
pub const PF_UNIX = PF_LOCAL;
|
||||
pub const PF_XTP = pseudo_AF_XTP;
|
||||
pub const PF_DECnet = AF_DECnet;
|
||||
pub const PF = struct {
|
||||
pub const INET6 = AF.INET6;
|
||||
pub const IMPLINK = AF.IMPLINK;
|
||||
pub const ROUTE = AF.ROUTE;
|
||||
pub const ISO = AF.ISO;
|
||||
pub const PIP = AF.pseudo_PIP;
|
||||
pub const CHAOS = AF.CHAOS;
|
||||
pub const DATAKIT = AF.DATAKIT;
|
||||
pub const INET = AF.INET;
|
||||
pub const APPLETALK = AF.APPLETALK;
|
||||
pub const SIP = AF.SIP;
|
||||
pub const OSI = AF.ISO;
|
||||
pub const CNT = AF.CNT;
|
||||
pub const LINK = AF.LINK;
|
||||
pub const HYLINK = AF.HYLINK;
|
||||
pub const MAX = AF.MAX;
|
||||
pub const KEY = AF.pseudo_KEY;
|
||||
pub const PUP = AF.PUP;
|
||||
pub const COIP = AF.COIP;
|
||||
pub const SNA = AF.SNA;
|
||||
pub const LOCAL = AF.LOCAL;
|
||||
pub const NETBIOS = AF.NETBIOS;
|
||||
pub const NATM = AF.NATM;
|
||||
pub const BLUETOOTH = AF.BLUETOOTH;
|
||||
pub const UNSPEC = AF.UNSPEC;
|
||||
pub const NETGRAPH = AF.NETGRAPH;
|
||||
pub const ECMA = AF.ECMA;
|
||||
pub const IPX = AF.IPX;
|
||||
pub const DLI = AF.DLI;
|
||||
pub const ATM = AF.ATM;
|
||||
pub const CCITT = AF.CCITT;
|
||||
pub const ISDN = AF.ISDN;
|
||||
pub const RTIP = AF.pseudo_RTIP;
|
||||
pub const LAT = AF.LAT;
|
||||
pub const UNIX = PF_LOCAL;
|
||||
pub const XTP = AF.pseudo_XTP;
|
||||
pub const DECnet = AF.DECnet;
|
||||
};
|
||||
|
||||
pub const AF_UNSPEC = 0;
|
||||
pub const AF_OSI = AF_ISO;
|
||||
pub const AF_UNIX = AF_LOCAL;
|
||||
pub const AF_LOCAL = 1;
|
||||
pub const AF_INET = 2;
|
||||
pub const AF_IMPLINK = 3;
|
||||
pub const AF_PUP = 4;
|
||||
pub const AF_CHAOS = 5;
|
||||
pub const AF_NETBIOS = 6;
|
||||
pub const AF_ISO = 7;
|
||||
pub const AF_ECMA = 8;
|
||||
pub const AF_DATAKIT = 9;
|
||||
pub const AF_CCITT = 10;
|
||||
pub const AF_SNA = 11;
|
||||
pub const AF_DLI = 13;
|
||||
pub const AF_LAT = 14;
|
||||
pub const AF_HYLINK = 15;
|
||||
pub const AF_APPLETALK = 16;
|
||||
pub const AF_ROUTE = 17;
|
||||
pub const AF_LINK = 18;
|
||||
pub const AF_COIP = 20;
|
||||
pub const AF_CNT = 21;
|
||||
pub const AF_IPX = 23;
|
||||
pub const AF_SIP = 24;
|
||||
pub const AF_ISDN = 26;
|
||||
pub const AF_INET6 = 28;
|
||||
pub const AF_NATM = 29;
|
||||
pub const AF_ATM = 30;
|
||||
pub const AF_NETGRAPH = 32;
|
||||
pub const AF_BLUETOOTH = 33;
|
||||
pub const AF_MPLS = 34;
|
||||
pub const AF_MAX = 36;
|
||||
pub const AF = struct {
|
||||
pub const UNSPEC = 0;
|
||||
pub const OSI = ISO;
|
||||
pub const UNIX = LOCAL;
|
||||
pub const LOCAL = 1;
|
||||
pub const INET = 2;
|
||||
pub const IMPLINK = 3;
|
||||
pub const PUP = 4;
|
||||
pub const CHAOS = 5;
|
||||
pub const NETBIOS = 6;
|
||||
pub const ISO = 7;
|
||||
pub const ECMA = 8;
|
||||
pub const DATAKIT = 9;
|
||||
pub const CCITT = 10;
|
||||
pub const SNA = 11;
|
||||
pub const DLI = 13;
|
||||
pub const LAT = 14;
|
||||
pub const HYLINK = 15;
|
||||
pub const APPLETALK = 16;
|
||||
pub const ROUTE = 17;
|
||||
pub const LINK = 18;
|
||||
pub const COIP = 20;
|
||||
pub const CNT = 21;
|
||||
pub const IPX = 23;
|
||||
pub const SIP = 24;
|
||||
pub const ISDN = 26;
|
||||
pub const INET6 = 28;
|
||||
pub const NATM = 29;
|
||||
pub const ATM = 30;
|
||||
pub const NETGRAPH = 32;
|
||||
pub const BLUETOOTH = 33;
|
||||
pub const MPLS = 34;
|
||||
pub const MAX = 36;
|
||||
};
|
||||
|
||||
pub const in_port_t = u16;
|
||||
pub const sa_family_t = u8;
|
||||
pub const socklen_t = u32;
|
||||
|
||||
pub const sockaddr_in = extern struct {
|
||||
len: u8 = @sizeOf(sockaddr_in),
|
||||
family: sa_family_t = AF_INET,
|
||||
port: in_port_t,
|
||||
addr: u32,
|
||||
zero: [8]u8 = [8]u8{ 0, 0, 0, 0, 0, 0, 0, 0 },
|
||||
};
|
||||
|
||||
pub const sockaddr_in6 = extern struct {
|
||||
len: u8 = @sizeOf(sockaddr_in6),
|
||||
family: sa_family_t = AF_INET6,
|
||||
port: in_port_t,
|
||||
flowinfo: u32,
|
||||
addr: [16]u8,
|
||||
scope_id: u32,
|
||||
};
|
||||
|
||||
pub const EAI = enum(c_int) {
|
||||
ADDRFAMILY = 1,
|
||||
AGAIN = 2,
|
||||
@ -763,30 +777,34 @@ pub const EAI = enum(c_int) {
|
||||
_,
|
||||
};
|
||||
|
||||
pub const AI_PASSIVE = 0x00000001;
|
||||
pub const AI_CANONNAME = 0x00000002;
|
||||
pub const AI_NUMERICHOST = 0x00000004;
|
||||
pub const AI_NUMERICSERV = 0x00000008;
|
||||
pub const AI_MASK = AI_PASSIVE | AI_CANONNAME | AI_NUMERICHOST | AI_NUMERICSERV | AI_ADDRCONFIG;
|
||||
pub const AI_ALL = 0x00000100;
|
||||
pub const AI_V4MAPPED_CFG = 0x00000200;
|
||||
pub const AI_ADDRCONFIG = 0x00000400;
|
||||
pub const AI_V4MAPPED = 0x00000800;
|
||||
pub const AI_DEFAULT = AI_V4MAPPED_CFG | AI_ADDRCONFIG;
|
||||
pub const AI = struct {
|
||||
pub const PASSIVE = 0x00000001;
|
||||
pub const CANONNAME = 0x00000002;
|
||||
pub const NUMERICHOST = 0x00000004;
|
||||
pub const NUMERICSERV = 0x00000008;
|
||||
pub const MASK = PASSIVE | CANONNAME | NUMERICHOST | NUMERICSERV | ADDRCONFIG;
|
||||
pub const ALL = 0x00000100;
|
||||
pub const V4MAPPED_CFG = 0x00000200;
|
||||
pub const ADDRCONFIG = 0x00000400;
|
||||
pub const V4MAPPED = 0x00000800;
|
||||
pub const DEFAULT = V4MAPPED_CFG | ADDRCONFIG;
|
||||
};
|
||||
|
||||
pub const RTLD_LAZY = 1;
|
||||
pub const RTLD_NOW = 2;
|
||||
pub const RTLD_MODEMASK = 0x3;
|
||||
pub const RTLD_GLOBAL = 0x100;
|
||||
pub const RTLD_LOCAL = 0;
|
||||
pub const RTLD_TRACE = 0x200;
|
||||
pub const RTLD_NODELETE = 0x01000;
|
||||
pub const RTLD_NOLOAD = 0x02000;
|
||||
pub const RTLD = struct {
|
||||
pub const LAZY = 1;
|
||||
pub const NOW = 2;
|
||||
pub const MODEMASK = 0x3;
|
||||
pub const GLOBAL = 0x100;
|
||||
pub const LOCAL = 0;
|
||||
pub const TRACE = 0x200;
|
||||
pub const NODELETE = 0x01000;
|
||||
pub const NOLOAD = 0x02000;
|
||||
|
||||
pub const RTLD_NEXT = @intToPtr(*c_void, @bitCast(usize, @as(isize, -1)));
|
||||
pub const RTLD_DEFAULT = @intToPtr(*c_void, @bitCast(usize, @as(isize, -2)));
|
||||
pub const RTLD_SELF = @intToPtr(*c_void, @bitCast(usize, @as(isize, -3)));
|
||||
pub const RTLD_ALL = @intToPtr(*c_void, @bitCast(usize, @as(isize, -4)));
|
||||
pub const NEXT = @intToPtr(*c_void, @bitCast(usize, @as(isize, -1)));
|
||||
pub const DEFAULT = @intToPtr(*c_void, @bitCast(usize, @as(isize, -2)));
|
||||
pub const SELF = @intToPtr(*c_void, @bitCast(usize, @as(isize, -3)));
|
||||
pub const ALL = @intToPtr(*c_void, @bitCast(usize, @as(isize, -4)));
|
||||
};
|
||||
|
||||
pub const dl_phdr_info = extern struct {
|
||||
dlpi_addr: usize,
|
||||
@ -833,20 +851,22 @@ pub const POSIX_MADV_DONTNEED = 4;
|
||||
pub const POSIX_MADV_NORMAL = 0;
|
||||
pub const POSIX_MADV_WILLNEED = 3;
|
||||
|
||||
pub const MADV_SEQUENTIAL = 2;
|
||||
pub const MADV_CONTROL_END = MADV_SETMAP;
|
||||
pub const MADV_DONTNEED = 4;
|
||||
pub const MADV_RANDOM = 1;
|
||||
pub const MADV_WILLNEED = 3;
|
||||
pub const MADV_NORMAL = 0;
|
||||
pub const MADV_CONTROL_START = MADV_INVAL;
|
||||
pub const MADV_FREE = 5;
|
||||
pub const MADV_NOSYNC = 6;
|
||||
pub const MADV_AUTOSYNC = 7;
|
||||
pub const MADV_NOCORE = 8;
|
||||
pub const MADV_CORE = 9;
|
||||
pub const MADV_INVAL = 10;
|
||||
pub const MADV_SETMAP = 11;
|
||||
pub const MADV = struct {
|
||||
pub const SEQUENTIAL = 2;
|
||||
pub const CONTROL_END = SETMAP;
|
||||
pub const DONTNEED = 4;
|
||||
pub const RANDOM = 1;
|
||||
pub const WILLNEED = 3;
|
||||
pub const NORMAL = 0;
|
||||
pub const CONTROL_START = INVAL;
|
||||
pub const FREE = 5;
|
||||
pub const NOSYNC = 6;
|
||||
pub const AUTOSYNC = 7;
|
||||
pub const NOCORE = 8;
|
||||
pub const CORE = 9;
|
||||
pub const INVAL = 10;
|
||||
pub const SETMAP = 11;
|
||||
};
|
||||
|
||||
pub const F_DUPFD = 0;
|
||||
pub const F_GETFD = 1;
|
||||
@ -865,10 +885,12 @@ pub const F_DUP2FD = 10;
|
||||
pub const F_DUPFD_CLOEXEC = 17;
|
||||
pub const F_DUP2FD_CLOEXEC = 18;
|
||||
|
||||
pub const LOCK_SH = 1;
|
||||
pub const LOCK_EX = 2;
|
||||
pub const LOCK_UN = 8;
|
||||
pub const LOCK_NB = 4;
|
||||
pub const LOCK = struct {
|
||||
pub const SH = 1;
|
||||
pub const EX = 2;
|
||||
pub const UN = 8;
|
||||
pub const NB = 4;
|
||||
};
|
||||
|
||||
pub const Flock = extern struct {
|
||||
l_start: off_t,
|
||||
@ -889,118 +911,120 @@ pub const addrinfo = extern struct {
|
||||
next: ?*addrinfo,
|
||||
};
|
||||
|
||||
pub const IPPROTO_IP = 0;
|
||||
pub const IPPROTO_ICMP = 1;
|
||||
pub const IPPROTO_TCP = 6;
|
||||
pub const IPPROTO_UDP = 17;
|
||||
pub const IPPROTO_IPV6 = 41;
|
||||
pub const IPPROTO_RAW = 255;
|
||||
pub const IPPROTO_HOPOPTS = 0;
|
||||
pub const IPPROTO_IGMP = 2;
|
||||
pub const IPPROTO_GGP = 3;
|
||||
pub const IPPROTO_IPV4 = 4;
|
||||
pub const IPPROTO_IPIP = IPPROTO_IPV4;
|
||||
pub const IPPROTO_ST = 7;
|
||||
pub const IPPROTO_EGP = 8;
|
||||
pub const IPPROTO_PIGP = 9;
|
||||
pub const IPPROTO_RCCMON = 10;
|
||||
pub const IPPROTO_NVPII = 11;
|
||||
pub const IPPROTO_PUP = 12;
|
||||
pub const IPPROTO_ARGUS = 13;
|
||||
pub const IPPROTO_EMCON = 14;
|
||||
pub const IPPROTO_XNET = 15;
|
||||
pub const IPPROTO_CHAOS = 16;
|
||||
pub const IPPROTO_MUX = 18;
|
||||
pub const IPPROTO_MEAS = 19;
|
||||
pub const IPPROTO_HMP = 20;
|
||||
pub const IPPROTO_PRM = 21;
|
||||
pub const IPPROTO_IDP = 22;
|
||||
pub const IPPROTO_TRUNK1 = 23;
|
||||
pub const IPPROTO_TRUNK2 = 24;
|
||||
pub const IPPROTO_LEAF1 = 25;
|
||||
pub const IPPROTO_LEAF2 = 26;
|
||||
pub const IPPROTO_RDP = 27;
|
||||
pub const IPPROTO_IRTP = 28;
|
||||
pub const IPPROTO_TP = 29;
|
||||
pub const IPPROTO_BLT = 30;
|
||||
pub const IPPROTO_NSP = 31;
|
||||
pub const IPPROTO_INP = 32;
|
||||
pub const IPPROTO_SEP = 33;
|
||||
pub const IPPROTO_3PC = 34;
|
||||
pub const IPPROTO_IDPR = 35;
|
||||
pub const IPPROTO_XTP = 36;
|
||||
pub const IPPROTO_DDP = 37;
|
||||
pub const IPPROTO_CMTP = 38;
|
||||
pub const IPPROTO_TPXX = 39;
|
||||
pub const IPPROTO_IL = 40;
|
||||
pub const IPPROTO_SDRP = 42;
|
||||
pub const IPPROTO_ROUTING = 43;
|
||||
pub const IPPROTO_FRAGMENT = 44;
|
||||
pub const IPPROTO_IDRP = 45;
|
||||
pub const IPPROTO_RSVP = 46;
|
||||
pub const IPPROTO_GRE = 47;
|
||||
pub const IPPROTO_MHRP = 48;
|
||||
pub const IPPROTO_BHA = 49;
|
||||
pub const IPPROTO_ESP = 50;
|
||||
pub const IPPROTO_AH = 51;
|
||||
pub const IPPROTO_INLSP = 52;
|
||||
pub const IPPROTO_SWIPE = 53;
|
||||
pub const IPPROTO_NHRP = 54;
|
||||
pub const IPPROTO_MOBILE = 55;
|
||||
pub const IPPROTO_TLSP = 56;
|
||||
pub const IPPROTO_SKIP = 57;
|
||||
pub const IPPROTO_ICMPV6 = 58;
|
||||
pub const IPPROTO_NONE = 59;
|
||||
pub const IPPROTO_DSTOPTS = 60;
|
||||
pub const IPPROTO_AHIP = 61;
|
||||
pub const IPPROTO_CFTP = 62;
|
||||
pub const IPPROTO_HELLO = 63;
|
||||
pub const IPPROTO_SATEXPAK = 64;
|
||||
pub const IPPROTO_KRYPTOLAN = 65;
|
||||
pub const IPPROTO_RVD = 66;
|
||||
pub const IPPROTO_IPPC = 67;
|
||||
pub const IPPROTO_ADFS = 68;
|
||||
pub const IPPROTO_SATMON = 69;
|
||||
pub const IPPROTO_VISA = 70;
|
||||
pub const IPPROTO_IPCV = 71;
|
||||
pub const IPPROTO_CPNX = 72;
|
||||
pub const IPPROTO_CPHB = 73;
|
||||
pub const IPPROTO_WSN = 74;
|
||||
pub const IPPROTO_PVP = 75;
|
||||
pub const IPPROTO_BRSATMON = 76;
|
||||
pub const IPPROTO_ND = 77;
|
||||
pub const IPPROTO_WBMON = 78;
|
||||
pub const IPPROTO_WBEXPAK = 79;
|
||||
pub const IPPROTO_EON = 80;
|
||||
pub const IPPROTO_VMTP = 81;
|
||||
pub const IPPROTO_SVMTP = 82;
|
||||
pub const IPPROTO_VINES = 83;
|
||||
pub const IPPROTO_TTP = 84;
|
||||
pub const IPPROTO_IGP = 85;
|
||||
pub const IPPROTO_DGP = 86;
|
||||
pub const IPPROTO_TCF = 87;
|
||||
pub const IPPROTO_IGRP = 88;
|
||||
pub const IPPROTO_OSPFIGP = 89;
|
||||
pub const IPPROTO_SRPC = 90;
|
||||
pub const IPPROTO_LARP = 91;
|
||||
pub const IPPROTO_MTP = 92;
|
||||
pub const IPPROTO_AX25 = 93;
|
||||
pub const IPPROTO_IPEIP = 94;
|
||||
pub const IPPROTO_MICP = 95;
|
||||
pub const IPPROTO_SCCSP = 96;
|
||||
pub const IPPROTO_ETHERIP = 97;
|
||||
pub const IPPROTO_ENCAP = 98;
|
||||
pub const IPPROTO_APES = 99;
|
||||
pub const IPPROTO_GMTP = 100;
|
||||
pub const IPPROTO_IPCOMP = 108;
|
||||
pub const IPPROTO_PIM = 103;
|
||||
pub const IPPROTO_CARP = 112;
|
||||
pub const IPPROTO_PGM = 113;
|
||||
pub const IPPROTO_PFSYNC = 240;
|
||||
pub const IPPROTO_DIVERT = 254;
|
||||
pub const IPPROTO_MAX = 256;
|
||||
pub const IPPROTO_DONE = 257;
|
||||
pub const IPPROTO_UNKNOWN = 258;
|
||||
pub const IPPROTO = struct {
|
||||
pub const IP = 0;
|
||||
pub const ICMP = 1;
|
||||
pub const TCP = 6;
|
||||
pub const UDP = 17;
|
||||
pub const IPV6 = 41;
|
||||
pub const RAW = 255;
|
||||
pub const HOPOPTS = 0;
|
||||
pub const IGMP = 2;
|
||||
pub const GGP = 3;
|
||||
pub const IPV4 = 4;
|
||||
pub const IPIP = IPV4;
|
||||
pub const ST = 7;
|
||||
pub const EGP = 8;
|
||||
pub const PIGP = 9;
|
||||
pub const RCCMON = 10;
|
||||
pub const NVPII = 11;
|
||||
pub const PUP = 12;
|
||||
pub const ARGUS = 13;
|
||||
pub const EMCON = 14;
|
||||
pub const XNET = 15;
|
||||
pub const CHAOS = 16;
|
||||
pub const MUX = 18;
|
||||
pub const MEAS = 19;
|
||||
pub const HMP = 20;
|
||||
pub const PRM = 21;
|
||||
pub const IDP = 22;
|
||||
pub const TRUNK1 = 23;
|
||||
pub const TRUNK2 = 24;
|
||||
pub const LEAF1 = 25;
|
||||
pub const LEAF2 = 26;
|
||||
pub const RDP = 27;
|
||||
pub const IRTP = 28;
|
||||
pub const TP = 29;
|
||||
pub const BLT = 30;
|
||||
pub const NSP = 31;
|
||||
pub const INP = 32;
|
||||
pub const SEP = 33;
|
||||
pub const @"3PC" = 34;
|
||||
pub const IDPR = 35;
|
||||
pub const XTP = 36;
|
||||
pub const DDP = 37;
|
||||
pub const CMTP = 38;
|
||||
pub const TPXX = 39;
|
||||
pub const IL = 40;
|
||||
pub const SDRP = 42;
|
||||
pub const ROUTING = 43;
|
||||
pub const FRAGMENT = 44;
|
||||
pub const IDRP = 45;
|
||||
pub const RSVP = 46;
|
||||
pub const GRE = 47;
|
||||
pub const MHRP = 48;
|
||||
pub const BHA = 49;
|
||||
pub const ESP = 50;
|
||||
pub const AH = 51;
|
||||
pub const INLSP = 52;
|
||||
pub const SWIPE = 53;
|
||||
pub const NHRP = 54;
|
||||
pub const MOBILE = 55;
|
||||
pub const TLSP = 56;
|
||||
pub const SKIP = 57;
|
||||
pub const ICMPV6 = 58;
|
||||
pub const NONE = 59;
|
||||
pub const DSTOPTS = 60;
|
||||
pub const AHIP = 61;
|
||||
pub const CFTP = 62;
|
||||
pub const HELLO = 63;
|
||||
pub const SATEXPAK = 64;
|
||||
pub const KRYPTOLAN = 65;
|
||||
pub const RVD = 66;
|
||||
pub const IPPC = 67;
|
||||
pub const ADFS = 68;
|
||||
pub const SATMON = 69;
|
||||
pub const VISA = 70;
|
||||
pub const IPCV = 71;
|
||||
pub const CPNX = 72;
|
||||
pub const CPHB = 73;
|
||||
pub const WSN = 74;
|
||||
pub const PVP = 75;
|
||||
pub const BRSATMON = 76;
|
||||
pub const ND = 77;
|
||||
pub const WBMON = 78;
|
||||
pub const WBEXPAK = 79;
|
||||
pub const EON = 80;
|
||||
pub const VMTP = 81;
|
||||
pub const SVMTP = 82;
|
||||
pub const VINES = 83;
|
||||
pub const TTP = 84;
|
||||
pub const IGP = 85;
|
||||
pub const DGP = 86;
|
||||
pub const TCF = 87;
|
||||
pub const IGRP = 88;
|
||||
pub const OSPFIGP = 89;
|
||||
pub const SRPC = 90;
|
||||
pub const LARP = 91;
|
||||
pub const MTP = 92;
|
||||
pub const AX25 = 93;
|
||||
pub const IPEIP = 94;
|
||||
pub const MICP = 95;
|
||||
pub const SCCSP = 96;
|
||||
pub const ETHERIP = 97;
|
||||
pub const ENCAP = 98;
|
||||
pub const APES = 99;
|
||||
pub const GMTP = 100;
|
||||
pub const IPCOMP = 108;
|
||||
pub const PIM = 103;
|
||||
pub const CARP = 112;
|
||||
pub const PGM = 113;
|
||||
pub const PFSYNC = 240;
|
||||
pub const DIVERT = 254;
|
||||
pub const MAX = 256;
|
||||
pub const DONE = 257;
|
||||
pub const UNKNOWN = 258;
|
||||
};
|
||||
|
||||
pub const rlimit_resource = enum(c_int) {
|
||||
CPU = 0,
|
||||
@ -1022,11 +1046,13 @@ pub const rlimit_resource = enum(c_int) {
|
||||
|
||||
pub const rlim_t = i64;
|
||||
|
||||
/// No limit
|
||||
pub const RLIM_INFINITY: rlim_t = (1 << 63) - 1;
|
||||
pub const RLIM = struct {
|
||||
/// No limit
|
||||
pub const INFINITY: rlim_t = (1 << 63) - 1;
|
||||
|
||||
pub const RLIM_SAVED_MAX = RLIM_INFINITY;
|
||||
pub const RLIM_SAVED_CUR = RLIM_INFINITY;
|
||||
pub const SAVED_MAX = INFINITY;
|
||||
pub const SAVED_CUR = INFINITY;
|
||||
};
|
||||
|
||||
pub const rlimit = extern struct {
|
||||
/// Soft limit
|
||||
@ -1047,16 +1073,18 @@ pub const pollfd = extern struct {
|
||||
revents: i16,
|
||||
};
|
||||
|
||||
/// Requestable events.
|
||||
pub const POLLIN = 0x0001;
|
||||
pub const POLLPRI = 0x0002;
|
||||
pub const POLLOUT = 0x0004;
|
||||
pub const POLLRDNORM = 0x0040;
|
||||
pub const POLLWRNORM = POLLOUT;
|
||||
pub const POLLRDBAND = 0x0080;
|
||||
pub const POLLWRBAND = 0x0100;
|
||||
pub const POLL = struct {
|
||||
/// Requestable events.
|
||||
pub const IN = 0x0001;
|
||||
pub const PRI = 0x0002;
|
||||
pub const OUT = 0x0004;
|
||||
pub const RDNORM = 0x0040;
|
||||
pub const WRNORM = OUT;
|
||||
pub const RDBAND = 0x0080;
|
||||
pub const WRBAND = 0x0100;
|
||||
|
||||
/// These events are set if they occur regardless of whether they were requested.
|
||||
pub const POLLERR = 0x0008;
|
||||
pub const POLLHUP = 0x0010;
|
||||
pub const POLLNVAL = 0x0020;
|
||||
/// These events are set if they occur regardless of whether they were requested.
|
||||
pub const ERR = 0x0008;
|
||||
pub const HUP = 0x0010;
|
||||
pub const NVAL = 0x0020;
|
||||
};
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
1007
lib/std/c/haiku.zig
1007
lib/std/c/haiku.zig
File diff suppressed because it is too large
Load Diff
@ -4,61 +4,93 @@ const maxInt = std.math.maxInt;
|
||||
const native_abi = builtin.abi;
|
||||
const native_arch = builtin.cpu.arch;
|
||||
const linux = std.os.linux;
|
||||
const iovec = std.os.iovec;
|
||||
const iovec_const = std.os.iovec_const;
|
||||
|
||||
pub const E = linux.E;
|
||||
pub const Sigaction = linux.Sigaction;
|
||||
pub const dl_phdr_info = linux.dl_phdr_info;
|
||||
pub const fd_t = linux.fd_t;
|
||||
pub const rlimit = linux.rlimit;
|
||||
pub const rlimit_resource = linux.rlimit_resource;
|
||||
pub const timespec = linux.timespec;
|
||||
pub const NAME_MAX = linux.NAME_MAX;
|
||||
pub const PATH_MAX = linux.PATH_MAX;
|
||||
pub const IOV_MAX = linux.IOV_MAX;
|
||||
pub const STDIN_FILENO = linux.STDIN_FILENO;
|
||||
pub const STDOUT_FILENO = linux.STDIN_FILENO;
|
||||
pub const STDERR_FILENO = linux.STDIN_FILENO;
|
||||
pub const AT = linux.AT;
|
||||
pub const PROT = linux.PROT;
|
||||
pub const CLOCK = linux.CLOCK;
|
||||
pub const SIG = linux.SIG;
|
||||
pub const empty_sigset = linux.empty_sigset;
|
||||
pub const S = linux.S;
|
||||
pub const siginfo_t = linux.siginfo_t;
|
||||
pub const SA = linux.SA;
|
||||
pub const pollfd = linux.pollfd;
|
||||
pub const sigset_t = linux.sigset_t;
|
||||
pub const AF = linux.AF;
|
||||
pub const ARCH = linux.ARCH;
|
||||
pub const AT = linux.AT;
|
||||
pub const CLOCK = linux.CLOCK;
|
||||
pub const CPU_COUNT = linux.CPU_COUNT;
|
||||
pub const E = linux.E;
|
||||
pub const Elf_Symndx = linux.Elf_Symndx;
|
||||
pub const F = linux.F;
|
||||
pub const FD_CLOEXEC = linux.FD_CLOEXEC;
|
||||
pub const F_OK = linux.F_OK;
|
||||
pub const Flock = linux.Flock;
|
||||
pub const HOST_NAME_MAX = linux.HOST_NAME_MAX;
|
||||
pub const IFNAMESIZE = linux.IFNAMESIZE;
|
||||
pub const IOV_MAX = linux.IOV_MAX;
|
||||
pub const IPPROTO = linux.IPPROTO;
|
||||
pub const LOCK = linux.LOCK;
|
||||
pub const MADV = linux.MADV;
|
||||
pub const MAP = linux.MAP;
|
||||
pub const MMAP2_UNIT = linux.MMAP2_UNIT;
|
||||
pub const NAME_MAX = linux.NAME_MAX;
|
||||
pub const O = linux.O;
|
||||
pub const PATH_MAX = linux.PATH_MAX;
|
||||
pub const POLL = linux.POLL;
|
||||
pub const PROT = linux.PROT;
|
||||
pub const REG = linux.REG;
|
||||
pub const RLIM = linux.RLIM;
|
||||
pub const R_OK = linux.R_OK;
|
||||
pub const S = linux.S;
|
||||
pub const SA = linux.SA;
|
||||
pub const SC = linux.SC;
|
||||
pub const SEEK = linux.SEEK;
|
||||
pub const SHUT = linux.SHUT;
|
||||
pub const SIG = linux.SIG;
|
||||
pub const SIOCGIFINDEX = linux.SIOCGIFINDEX;
|
||||
pub const SO = linux.SO;
|
||||
pub const SOCK = linux.SOCK;
|
||||
pub const SOL = linux.SOL;
|
||||
pub const STDERR_FILENO = linux.STDIN_FILENO;
|
||||
pub const STDIN_FILENO = linux.STDIN_FILENO;
|
||||
pub const STDOUT_FILENO = linux.STDIN_FILENO;
|
||||
pub const SYS = linux.SYS;
|
||||
pub const Sigaction = linux.Sigaction;
|
||||
pub const VDSO = linux.VDSO;
|
||||
pub const W = linux.W;
|
||||
pub const W_OK = linux.W_OK;
|
||||
pub const X_OK = linux.X_OK;
|
||||
pub const addrinfo = linux.addrinfo;
|
||||
pub const blkcnt_t = linux.blkcnt_t;
|
||||
pub const blksize_t = linux.blksize_t;
|
||||
pub const clock_t = linux.clock_t;
|
||||
pub const cpu_set_t = linux.cpu_set_t;
|
||||
pub const dev_t = linux.dev_t;
|
||||
pub const dl_phdr_info = linux.dl_phdr_info;
|
||||
pub const empty_sigset = linux.empty_sigset;
|
||||
pub const epoll_event = linux.epoll_event;
|
||||
pub const fd_t = linux.fd_t;
|
||||
pub const gid_t = linux.gid_t;
|
||||
pub const ifreq = linux.ifreq;
|
||||
pub const ino_t = linux.ino_t;
|
||||
pub const mcontext_t = linux.mcontext_t;
|
||||
pub const mode_t = linux.mode_t;
|
||||
pub const msghdr = linux.msghdr;
|
||||
pub const msghdr_const = linux.msghdr_const;
|
||||
pub const nfds_t = linux.nfds_t;
|
||||
pub const nlink_t = linux.nlink_t;
|
||||
pub const off_t = linux.off_t;
|
||||
pub const pid_t = linux.pid_t;
|
||||
pub const pollfd = linux.pollfd;
|
||||
pub const rlim_t = linux.rlim_t;
|
||||
pub const rlimit = linux.rlimit;
|
||||
pub const rlimit_resource = linux.rlimit_resource;
|
||||
pub const siginfo_t = linux.siginfo_t;
|
||||
pub const sigset_t = linux.sigset_t;
|
||||
pub const sockaddr = linux.sockaddr;
|
||||
pub const socklen_t = linux.socklen_t;
|
||||
pub const stack_t = linux.stack_t;
|
||||
pub const time_t = linux.time_t;
|
||||
pub const timespec = linux.timespec;
|
||||
pub const timeval = linux.timeval;
|
||||
pub const timezone = linux.timezone;
|
||||
pub const ucontext_t = linux.ucontext_t;
|
||||
pub const user_desc = linux.user_desc;
|
||||
pub const pid_t = linux.pid_t;
|
||||
pub const uid_t = linux.uid_t;
|
||||
pub const gid_t = linux.gid_t;
|
||||
pub const clock_t = linux.clock_t;
|
||||
pub const user_desc = linux.user_desc;
|
||||
pub const utsname = linux.utsname;
|
||||
|
||||
pub const _errno = switch (native_abi) {
|
||||
.android => struct {
|
||||
@ -140,8 +172,6 @@ pub const Stat = switch (native_arch) {
|
||||
else => std.os.linux.Stat, // libc stat is the same as kernel stat.
|
||||
};
|
||||
|
||||
pub const MAP_FAILED = @intToPtr(*c_void, maxInt(usize));
|
||||
|
||||
pub const AI = struct {
|
||||
pub const PASSIVE = 0x01;
|
||||
pub const CANONNAME = 0x02;
|
||||
|
||||
@ -135,16 +135,18 @@ pub const Kevent = extern struct {
|
||||
udata: usize,
|
||||
};
|
||||
|
||||
pub const RTLD_LAZY = 1;
|
||||
pub const RTLD_NOW = 2;
|
||||
pub const RTLD_GLOBAL = 0x100;
|
||||
pub const RTLD_LOCAL = 0x200;
|
||||
pub const RTLD_NODELETE = 0x01000;
|
||||
pub const RTLD_NOLOAD = 0x02000;
|
||||
pub const RTLD = struct {
|
||||
pub const LAZY = 1;
|
||||
pub const NOW = 2;
|
||||
pub const GLOBAL = 0x100;
|
||||
pub const LOCAL = 0x200;
|
||||
pub const NODELETE = 0x01000;
|
||||
pub const NOLOAD = 0x02000;
|
||||
|
||||
pub const RTLD_NEXT = @intToPtr(*c_void, @bitCast(usize, @as(isize, -1)));
|
||||
pub const RTLD_DEFAULT = @intToPtr(*c_void, @bitCast(usize, @as(isize, -2)));
|
||||
pub const RTLD_SELF = @intToPtr(*c_void, @bitCast(usize, @as(isize, -3)));
|
||||
pub const NEXT = @intToPtr(*c_void, @bitCast(usize, @as(isize, -1)));
|
||||
pub const DEFAULT = @intToPtr(*c_void, @bitCast(usize, @as(isize, -2)));
|
||||
pub const SELF = @intToPtr(*c_void, @bitCast(usize, @as(isize, -3)));
|
||||
};
|
||||
|
||||
pub const dl_phdr_info = extern struct {
|
||||
dlpi_addr: usize,
|
||||
@ -325,120 +327,130 @@ pub const dirent = extern struct {
|
||||
}
|
||||
};
|
||||
|
||||
pub const SOCK_STREAM = 1;
|
||||
pub const SOCK_DGRAM = 2;
|
||||
pub const SOCK_RAW = 3;
|
||||
pub const SOCK_RDM = 4;
|
||||
pub const SOCK_SEQPACKET = 5;
|
||||
pub const SOCK_CONN_DGRAM = 6;
|
||||
pub const SOCK_DCCP = SOCK_CONN_DGRAM;
|
||||
pub const SOCK = struct {
|
||||
pub const STREAM = 1;
|
||||
pub const DGRAM = 2;
|
||||
pub const RAW = 3;
|
||||
pub const RDM = 4;
|
||||
pub const SEQPACKET = 5;
|
||||
pub const CONN_DGRAM = 6;
|
||||
pub const DCCP = CONN_DGRAM;
|
||||
|
||||
pub const SOCK_CLOEXEC = 0x10000000;
|
||||
pub const SOCK_NONBLOCK = 0x20000000;
|
||||
pub const SOCK_NOSIGPIPE = 0x40000000;
|
||||
pub const SOCK_FLAGS_MASK = 0xf0000000;
|
||||
pub const CLOEXEC = 0x10000000;
|
||||
pub const NONBLOCK = 0x20000000;
|
||||
pub const NOSIGPIPE = 0x40000000;
|
||||
pub const FLAGS_MASK = 0xf0000000;
|
||||
};
|
||||
|
||||
pub const SO_DEBUG = 0x0001;
|
||||
pub const SO_ACCEPTCONN = 0x0002;
|
||||
pub const SO_REUSEADDR = 0x0004;
|
||||
pub const SO_KEEPALIVE = 0x0008;
|
||||
pub const SO_DONTROUTE = 0x0010;
|
||||
pub const SO_BROADCAST = 0x0020;
|
||||
pub const SO_USELOOPBACK = 0x0040;
|
||||
pub const SO_LINGER = 0x0080;
|
||||
pub const SO_OOBINLINE = 0x0100;
|
||||
pub const SO_REUSEPORT = 0x0200;
|
||||
pub const SO_NOSIGPIPE = 0x0800;
|
||||
pub const SO_ACCEPTFILTER = 0x1000;
|
||||
pub const SO_TIMESTAMP = 0x2000;
|
||||
pub const SO_RERROR = 0x4000;
|
||||
pub const SO = struct {
|
||||
pub const DEBUG = 0x0001;
|
||||
pub const ACCEPTCONN = 0x0002;
|
||||
pub const REUSEADDR = 0x0004;
|
||||
pub const KEEPALIVE = 0x0008;
|
||||
pub const DONTROUTE = 0x0010;
|
||||
pub const BROADCAST = 0x0020;
|
||||
pub const USELOOPBACK = 0x0040;
|
||||
pub const LINGER = 0x0080;
|
||||
pub const OOBINLINE = 0x0100;
|
||||
pub const REUSEPORT = 0x0200;
|
||||
pub const NOSIGPIPE = 0x0800;
|
||||
pub const ACCEPTFILTER = 0x1000;
|
||||
pub const TIMESTAMP = 0x2000;
|
||||
pub const RERROR = 0x4000;
|
||||
|
||||
pub const SO_SNDBUF = 0x1001;
|
||||
pub const SO_RCVBUF = 0x1002;
|
||||
pub const SO_SNDLOWAT = 0x1003;
|
||||
pub const SO_RCVLOWAT = 0x1004;
|
||||
pub const SO_ERROR = 0x1007;
|
||||
pub const SO_TYPE = 0x1008;
|
||||
pub const SO_OVERFLOWED = 0x1009;
|
||||
pub const SNDBUF = 0x1001;
|
||||
pub const RCVBUF = 0x1002;
|
||||
pub const SNDLOWAT = 0x1003;
|
||||
pub const RCVLOWAT = 0x1004;
|
||||
pub const ERROR = 0x1007;
|
||||
pub const TYPE = 0x1008;
|
||||
pub const OVERFLOWED = 0x1009;
|
||||
|
||||
pub const SO_NOHEADER = 0x100a;
|
||||
pub const SO_SNDTIMEO = 0x100b;
|
||||
pub const SO_RCVTIMEO = 0x100c;
|
||||
pub const NOHEADER = 0x100a;
|
||||
pub const SNDTIMEO = 0x100b;
|
||||
pub const RCVTIMEO = 0x100c;
|
||||
};
|
||||
|
||||
pub const SOL_SOCKET = 0xffff;
|
||||
pub const SOL = struct {
|
||||
pub const SOCKET = 0xffff;
|
||||
};
|
||||
|
||||
pub const PF_UNSPEC = AF_UNSPEC;
|
||||
pub const PF_LOCAL = AF_LOCAL;
|
||||
pub const PF_UNIX = PF_LOCAL;
|
||||
pub const PF_INET = AF_INET;
|
||||
pub const PF_IMPLINK = AF_IMPLINK;
|
||||
pub const PF_PUP = AF_PUP;
|
||||
pub const PF_CHAOS = AF_CHAOS;
|
||||
pub const PF_NS = AF_NS;
|
||||
pub const PF_ISO = AF_ISO;
|
||||
pub const PF_OSI = AF_ISO;
|
||||
pub const PF_ECMA = AF_ECMA;
|
||||
pub const PF_DATAKIT = AF_DATAKIT;
|
||||
pub const PF_CCITT = AF_CCITT;
|
||||
pub const PF_SNA = AF_SNA;
|
||||
pub const PF_DECnet = AF_DECnet;
|
||||
pub const PF_DLI = AF_DLI;
|
||||
pub const PF_LAT = AF_LAT;
|
||||
pub const PF_HYLINK = AF_HYLINK;
|
||||
pub const PF_APPLETALK = AF_APPLETALK;
|
||||
pub const PF_OROUTE = AF_OROUTE;
|
||||
pub const PF_LINK = AF_LINK;
|
||||
pub const PF_COIP = AF_COIP;
|
||||
pub const PF_CNT = AF_CNT;
|
||||
pub const PF_INET6 = AF_INET6;
|
||||
pub const PF_IPX = AF_IPX;
|
||||
pub const PF_ISDN = AF_ISDN;
|
||||
pub const PF_E164 = AF_E164;
|
||||
pub const PF_NATM = AF_NATM;
|
||||
pub const PF_ARP = AF_ARP;
|
||||
pub const PF_BLUETOOTH = AF_BLUETOOTH;
|
||||
pub const PF_MPLS = AF_MPLS;
|
||||
pub const PF_ROUTE = AF_ROUTE;
|
||||
pub const PF_CAN = AF_CAN;
|
||||
pub const PF_ETHER = AF_ETHER;
|
||||
pub const PF_MAX = AF_MAX;
|
||||
pub const PF = struct {
|
||||
pub const UNSPEC = AF.UNSPEC;
|
||||
pub const LOCAL = AF.LOCAL;
|
||||
pub const UNIX = PF.LOCAL;
|
||||
pub const INET = AF.INET;
|
||||
pub const IMPLINK = AF.IMPLINK;
|
||||
pub const PUP = AF.PUP;
|
||||
pub const CHAOS = AF.CHAOS;
|
||||
pub const NS = AF.NS;
|
||||
pub const ISO = AF.ISO;
|
||||
pub const OSI = AF.ISO;
|
||||
pub const ECMA = AF.ECMA;
|
||||
pub const DATAKIT = AF.DATAKIT;
|
||||
pub const CCITT = AF.CCITT;
|
||||
pub const SNA = AF.SNA;
|
||||
pub const DECnet = AF.DECnet;
|
||||
pub const DLI = AF.DLI;
|
||||
pub const LAT = AF.LAT;
|
||||
pub const HYLINK = AF.HYLINK;
|
||||
pub const APPLETALK = AF.APPLETALK;
|
||||
pub const OROUTE = AF.OROUTE;
|
||||
pub const LINK = AF.LINK;
|
||||
pub const COIP = AF.COIP;
|
||||
pub const CNT = AF.CNT;
|
||||
pub const INET6 = AF.INET6;
|
||||
pub const IPX = AF.IPX;
|
||||
pub const ISDN = AF.ISDN;
|
||||
pub const E164 = AF.E164;
|
||||
pub const NATM = AF.NATM;
|
||||
pub const ARP = AF.ARP;
|
||||
pub const BLUETOOTH = AF.BLUETOOTH;
|
||||
pub const MPLS = AF.MPLS;
|
||||
pub const ROUTE = AF.ROUTE;
|
||||
pub const CAN = AF.CAN;
|
||||
pub const ETHER = AF.ETHER;
|
||||
pub const MAX = AF.MAX;
|
||||
};
|
||||
|
||||
pub const AF_UNSPEC = 0;
|
||||
pub const AF_LOCAL = 1;
|
||||
pub const AF_UNIX = AF_LOCAL;
|
||||
pub const AF_INET = 2;
|
||||
pub const AF_IMPLINK = 3;
|
||||
pub const AF_PUP = 4;
|
||||
pub const AF_CHAOS = 5;
|
||||
pub const AF_NS = 6;
|
||||
pub const AF_ISO = 7;
|
||||
pub const AF_OSI = AF_ISO;
|
||||
pub const AF_ECMA = 8;
|
||||
pub const AF_DATAKIT = 9;
|
||||
pub const AF_CCITT = 10;
|
||||
pub const AF_SNA = 11;
|
||||
pub const AF_DECnet = 12;
|
||||
pub const AF_DLI = 13;
|
||||
pub const AF_LAT = 14;
|
||||
pub const AF_HYLINK = 15;
|
||||
pub const AF_APPLETALK = 16;
|
||||
pub const AF_OROUTE = 17;
|
||||
pub const AF_LINK = 18;
|
||||
pub const AF_COIP = 20;
|
||||
pub const AF_CNT = 21;
|
||||
pub const AF_IPX = 23;
|
||||
pub const AF_INET6 = 24;
|
||||
pub const AF_ISDN = 26;
|
||||
pub const AF_E164 = AF_ISDN;
|
||||
pub const AF_NATM = 27;
|
||||
pub const AF_ARP = 28;
|
||||
pub const AF_BLUETOOTH = 31;
|
||||
pub const AF_IEEE80211 = 32;
|
||||
pub const AF_MPLS = 33;
|
||||
pub const AF_ROUTE = 34;
|
||||
pub const AF_CAN = 35;
|
||||
pub const AF_ETHER = 36;
|
||||
pub const AF_MAX = 37;
|
||||
pub const AF = struct {
|
||||
pub const UNSPEC = 0;
|
||||
pub const LOCAL = 1;
|
||||
pub const UNIX = LOCAL;
|
||||
pub const INET = 2;
|
||||
pub const IMPLINK = 3;
|
||||
pub const PUP = 4;
|
||||
pub const CHAOS = 5;
|
||||
pub const NS = 6;
|
||||
pub const ISO = 7;
|
||||
pub const OSI = ISO;
|
||||
pub const ECMA = 8;
|
||||
pub const DATAKIT = 9;
|
||||
pub const CCITT = 10;
|
||||
pub const SNA = 11;
|
||||
pub const DECnet = 12;
|
||||
pub const DLI = 13;
|
||||
pub const LAT = 14;
|
||||
pub const HYLINK = 15;
|
||||
pub const APPLETALK = 16;
|
||||
pub const OROUTE = 17;
|
||||
pub const LINK = 18;
|
||||
pub const COIP = 20;
|
||||
pub const CNT = 21;
|
||||
pub const IPX = 23;
|
||||
pub const INET6 = 24;
|
||||
pub const ISDN = 26;
|
||||
pub const E164 = ISDN;
|
||||
pub const NATM = 27;
|
||||
pub const ARP = 28;
|
||||
pub const BLUETOOTH = 31;
|
||||
pub const IEEE80211 = 32;
|
||||
pub const MPLS = 33;
|
||||
pub const ROUTE = 34;
|
||||
pub const CAN = 35;
|
||||
pub const ETHER = 36;
|
||||
pub const MAX = 37;
|
||||
};
|
||||
|
||||
pub const in_port_t = u16;
|
||||
pub const sa_family_t = u8;
|
||||
@ -446,60 +458,55 @@ pub const sa_family_t = u8;
|
||||
pub const sockaddr = extern struct {
|
||||
/// total length
|
||||
len: u8,
|
||||
|
||||
/// address family
|
||||
family: sa_family_t,
|
||||
|
||||
/// actually longer; address value
|
||||
data: [14]u8,
|
||||
|
||||
pub const storage = std.x.os.Socket.Address.Native.Storage;
|
||||
|
||||
pub const in = extern struct {
|
||||
len: u8 = @sizeOf(in),
|
||||
family: sa_family_t = AF.INET,
|
||||
port: in_port_t,
|
||||
addr: u32,
|
||||
zero: [8]u8 = [8]u8{ 0, 0, 0, 0, 0, 0, 0, 0 },
|
||||
};
|
||||
|
||||
pub const in6 = extern struct {
|
||||
len: u8 = @sizeOf(in6),
|
||||
family: sa_family_t = AF.INET6,
|
||||
port: in_port_t,
|
||||
flowinfo: u32,
|
||||
addr: [16]u8,
|
||||
scope_id: u32,
|
||||
};
|
||||
|
||||
/// Definitions for UNIX IPC domain.
|
||||
pub const un = extern struct {
|
||||
/// total sockaddr length
|
||||
len: u8 = @sizeOf(un),
|
||||
|
||||
family: sa_family_t = AF.LOCAL,
|
||||
|
||||
/// path name
|
||||
path: [104]u8,
|
||||
};
|
||||
};
|
||||
|
||||
pub const sockaddr_storage = std.x.os.Socket.Address.Native.Storage;
|
||||
|
||||
pub const sockaddr_in = extern struct {
|
||||
len: u8 = @sizeOf(sockaddr_in),
|
||||
family: sa_family_t = AF_INET,
|
||||
port: in_port_t,
|
||||
addr: u32,
|
||||
zero: [8]u8 = [8]u8{ 0, 0, 0, 0, 0, 0, 0, 0 },
|
||||
pub const AI = struct {
|
||||
/// get address to use bind()
|
||||
pub const PASSIVE = 0x00000001;
|
||||
/// fill ai_canonname
|
||||
pub const CANONNAME = 0x00000002;
|
||||
/// prevent host name resolution
|
||||
pub const NUMERICHOST = 0x00000004;
|
||||
/// prevent service name resolution
|
||||
pub const NUMERICSERV = 0x00000008;
|
||||
/// only if any address is assigned
|
||||
pub const ADDRCONFIG = 0x00000400;
|
||||
};
|
||||
|
||||
pub const sockaddr_in6 = extern struct {
|
||||
len: u8 = @sizeOf(sockaddr_in6),
|
||||
family: sa_family_t = AF_INET6,
|
||||
port: in_port_t,
|
||||
flowinfo: u32,
|
||||
addr: [16]u8,
|
||||
scope_id: u32,
|
||||
};
|
||||
|
||||
/// Definitions for UNIX IPC domain.
|
||||
pub const sockaddr_un = extern struct {
|
||||
/// total sockaddr length
|
||||
len: u8 = @sizeOf(sockaddr_un),
|
||||
|
||||
/// AF_LOCAL
|
||||
family: sa_family_t = AF_LOCAL,
|
||||
|
||||
/// path name
|
||||
path: [104]u8,
|
||||
};
|
||||
|
||||
/// 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 = 0x00000008;
|
||||
|
||||
/// only if any address is assigned
|
||||
pub const AI_ADDRCONFIG = 0x00000400;
|
||||
|
||||
pub const CTL_KERN = 1;
|
||||
pub const CTL_DEBUG = 5;
|
||||
|
||||
@ -519,31 +526,34 @@ pub const PROT_READ = 1;
|
||||
pub const PROT_WRITE = 2;
|
||||
pub const PROT_EXEC = 4;
|
||||
|
||||
pub const CLOCK_REALTIME = 0;
|
||||
pub const CLOCK_VIRTUAL = 1;
|
||||
pub const CLOCK_PROF = 2;
|
||||
pub const CLOCK_MONOTONIC = 3;
|
||||
pub const CLOCK_THREAD_CPUTIME_ID = 0x20000000;
|
||||
pub const CLOCK_PROCESS_CPUTIME_ID = 0x40000000;
|
||||
pub const CLOCK = struct {
|
||||
pub const REALTIME = 0;
|
||||
pub const VIRTUAL = 1;
|
||||
pub const PROF = 2;
|
||||
pub const MONOTONIC = 3;
|
||||
pub const THREAD_CPUTIME_ID = 0x20000000;
|
||||
pub const PROCESS_CPUTIME_ID = 0x40000000;
|
||||
};
|
||||
|
||||
pub const MAP_FAILED = @intToPtr(*c_void, maxInt(usize));
|
||||
pub const MAP_SHARED = 0x0001;
|
||||
pub const MAP_PRIVATE = 0x0002;
|
||||
pub const MAP_REMAPDUP = 0x0004;
|
||||
pub const MAP_FIXED = 0x0010;
|
||||
pub const MAP_RENAME = 0x0020;
|
||||
pub const MAP_NORESERVE = 0x0040;
|
||||
pub const MAP_INHERIT = 0x0080;
|
||||
pub const MAP_HASSEMAPHORE = 0x0200;
|
||||
pub const MAP_TRYFIXED = 0x0400;
|
||||
pub const MAP_WIRED = 0x0800;
|
||||
|
||||
pub const MAP_FILE = 0x0000;
|
||||
pub const MAP_NOSYNC = 0x0800;
|
||||
pub const MAP_ANON = 0x1000;
|
||||
pub const MAP_ANONYMOUS = MAP_ANON;
|
||||
pub const MAP_STACK = 0x2000;
|
||||
pub const MAP = struct {
|
||||
pub const FAILED = @intToPtr(*c_void, maxInt(usize));
|
||||
pub const SHARED = 0x0001;
|
||||
pub const PRIVATE = 0x0002;
|
||||
pub const REMAPDUP = 0x0004;
|
||||
pub const FIXED = 0x0010;
|
||||
pub const RENAME = 0x0020;
|
||||
pub const NORESERVE = 0x0040;
|
||||
pub const INHERIT = 0x0080;
|
||||
pub const HASSEMAPHORE = 0x0200;
|
||||
pub const TRYFIXED = 0x0400;
|
||||
pub const WIRED = 0x0800;
|
||||
|
||||
pub const FILE = 0x0000;
|
||||
pub const NOSYNC = 0x0800;
|
||||
pub const ANON = 0x1000;
|
||||
pub const ANONYMOUS = ANON;
|
||||
pub const STACK = 0x2000;
|
||||
};
|
||||
pub const WNOHANG = 0x00000001;
|
||||
pub const WUNTRACED = 0x00000002;
|
||||
pub const WSTOPPED = WUNTRACED;
|
||||
@ -686,10 +696,12 @@ pub const F_RDLCK = 1;
|
||||
pub const F_WRLCK = 3;
|
||||
pub const F_UNLCK = 2;
|
||||
|
||||
pub const LOCK_SH = 1;
|
||||
pub const LOCK_EX = 2;
|
||||
pub const LOCK_UN = 8;
|
||||
pub const LOCK_NB = 4;
|
||||
pub const LOCK = struct {
|
||||
pub const SH = 1;
|
||||
pub const EX = 2;
|
||||
pub const UN = 8;
|
||||
pub const NB = 4;
|
||||
};
|
||||
|
||||
pub const FD_CLOEXEC = 1;
|
||||
|
||||
@ -1262,116 +1274,82 @@ pub const AT_REMOVEDIR = 0x0800;
|
||||
|
||||
pub const HOST_NAME_MAX = 255;
|
||||
|
||||
/// dummy for IP
|
||||
pub const IPPROTO_IP = 0;
|
||||
|
||||
/// IP6 hop-by-hop options
|
||||
pub const IPPROTO_HOPOPTS = 0;
|
||||
|
||||
/// control message protocol
|
||||
pub const IPPROTO_ICMP = 1;
|
||||
|
||||
/// group mgmt protocol
|
||||
pub const IPPROTO_IGMP = 2;
|
||||
|
||||
/// gateway^2 (deprecated)
|
||||
pub const IPPROTO_GGP = 3;
|
||||
|
||||
/// IP header
|
||||
pub const IPPROTO_IPV4 = 4;
|
||||
|
||||
/// IP inside IP
|
||||
pub const IPPROTO_IPIP = 4;
|
||||
|
||||
/// tcp
|
||||
pub const IPPROTO_TCP = 6;
|
||||
|
||||
/// exterior gateway protocol
|
||||
pub const IPPROTO_EGP = 8;
|
||||
|
||||
/// pup
|
||||
pub const IPPROTO_PUP = 12;
|
||||
|
||||
/// user datagram protocol
|
||||
pub const IPPROTO_UDP = 17;
|
||||
|
||||
/// xns idp
|
||||
pub const IPPROTO_IDP = 22;
|
||||
|
||||
/// tp-4 w/ class negotiation
|
||||
pub const IPPROTO_TP = 29;
|
||||
|
||||
/// DCCP
|
||||
pub const IPPROTO_DCCP = 33;
|
||||
|
||||
/// IP6 header
|
||||
pub const IPPROTO_IPV6 = 41;
|
||||
|
||||
/// IP6 routing header
|
||||
pub const IPPROTO_ROUTING = 43;
|
||||
|
||||
/// IP6 fragmentation header
|
||||
pub const IPPROTO_FRAGMENT = 44;
|
||||
|
||||
/// resource reservation
|
||||
pub const IPPROTO_RSVP = 46;
|
||||
|
||||
/// GRE encaps RFC 1701
|
||||
pub const IPPROTO_GRE = 47;
|
||||
|
||||
/// encap. security payload
|
||||
pub const IPPROTO_ESP = 50;
|
||||
|
||||
/// authentication header
|
||||
pub const IPPROTO_AH = 51;
|
||||
|
||||
/// IP Mobility RFC 2004
|
||||
pub const IPPROTO_MOBILE = 55;
|
||||
|
||||
/// IPv6 ICMP
|
||||
pub const IPPROTO_IPV6_ICMP = 58;
|
||||
|
||||
/// ICMP6
|
||||
pub const IPPROTO_ICMPV6 = 58;
|
||||
|
||||
/// IP6 no next header
|
||||
pub const IPPROTO_NONE = 59;
|
||||
|
||||
/// IP6 destination option
|
||||
pub const IPPROTO_DSTOPTS = 60;
|
||||
|
||||
/// ISO cnlp
|
||||
pub const IPPROTO_EON = 80;
|
||||
|
||||
/// Ethernet-in-IP
|
||||
pub const IPPROTO_ETHERIP = 97;
|
||||
|
||||
/// encapsulation header
|
||||
pub const IPPROTO_ENCAP = 98;
|
||||
|
||||
/// Protocol indep. multicast
|
||||
pub const IPPROTO_PIM = 103;
|
||||
|
||||
/// IP Payload Comp. Protocol
|
||||
pub const IPPROTO_IPCOMP = 108;
|
||||
|
||||
/// VRRP RFC 2338
|
||||
pub const IPPROTO_VRRP = 112;
|
||||
|
||||
/// Common Address Resolution Protocol
|
||||
pub const IPPROTO_CARP = 112;
|
||||
|
||||
/// L2TPv3
|
||||
pub const IPPROTO_L2TP = 115;
|
||||
|
||||
/// SCTP
|
||||
pub const IPPROTO_SCTP = 132;
|
||||
|
||||
/// PFSYNC
|
||||
pub const IPPROTO_PFSYNC = 240;
|
||||
|
||||
/// raw IP packet
|
||||
pub const IPPROTO_RAW = 255;
|
||||
pub const IPPROTO = struct {
|
||||
/// dummy for IP
|
||||
pub const IP = 0;
|
||||
/// IP6 hop-by-hop options
|
||||
pub const HOPOPTS = 0;
|
||||
/// control message protocol
|
||||
pub const ICMP = 1;
|
||||
/// group mgmt protocol
|
||||
pub const IGMP = 2;
|
||||
/// gateway^2 (deprecated)
|
||||
pub const GGP = 3;
|
||||
/// IP header
|
||||
pub const IPV4 = 4;
|
||||
/// IP inside IP
|
||||
pub const IPIP = 4;
|
||||
/// tcp
|
||||
pub const TCP = 6;
|
||||
/// exterior gateway protocol
|
||||
pub const EGP = 8;
|
||||
/// pup
|
||||
pub const PUP = 12;
|
||||
/// user datagram protocol
|
||||
pub const UDP = 17;
|
||||
/// xns idp
|
||||
pub const IDP = 22;
|
||||
/// tp-4 w/ class negotiation
|
||||
pub const TP = 29;
|
||||
/// DCCP
|
||||
pub const DCCP = 33;
|
||||
/// IP6 header
|
||||
pub const IPV6 = 41;
|
||||
/// IP6 routing header
|
||||
pub const ROUTING = 43;
|
||||
/// IP6 fragmentation header
|
||||
pub const FRAGMENT = 44;
|
||||
/// resource reservation
|
||||
pub const RSVP = 46;
|
||||
/// GRE encaps RFC 1701
|
||||
pub const GRE = 47;
|
||||
/// encap. security payload
|
||||
pub const ESP = 50;
|
||||
/// authentication header
|
||||
pub const AH = 51;
|
||||
/// IP Mobility RFC 2004
|
||||
pub const MOBILE = 55;
|
||||
/// IPv6 ICMP
|
||||
pub const IPV6_ICMP = 58;
|
||||
/// ICMP6
|
||||
pub const ICMPV6 = 58;
|
||||
/// IP6 no next header
|
||||
pub const NONE = 59;
|
||||
/// IP6 destination option
|
||||
pub const DSTOPTS = 60;
|
||||
/// ISO cnlp
|
||||
pub const EON = 80;
|
||||
/// Ethernet-in-IP
|
||||
pub const ETHERIP = 97;
|
||||
/// encapsulation header
|
||||
pub const ENCAP = 98;
|
||||
/// Protocol indep. multicast
|
||||
pub const PIM = 103;
|
||||
/// IP Payload Comp. Protocol
|
||||
pub const IPCOMP = 108;
|
||||
/// VRRP RFC 2338
|
||||
pub const VRRP = 112;
|
||||
/// Common Address Resolution Protocol
|
||||
pub const CARP = 112;
|
||||
/// L2TPv3
|
||||
pub const L2TP = 115;
|
||||
/// SCTP
|
||||
pub const SCTP = 132;
|
||||
/// PFSYNC
|
||||
pub const PFSYNC = 240;
|
||||
/// raw IP packet
|
||||
pub const RAW = 255;
|
||||
};
|
||||
|
||||
pub const rlimit_resource = enum(c_int) {
|
||||
CPU = 0,
|
||||
@ -1393,11 +1371,13 @@ pub const rlimit_resource = enum(c_int) {
|
||||
|
||||
pub const rlim_t = u64;
|
||||
|
||||
/// No limit
|
||||
pub const RLIM_INFINITY: rlim_t = (1 << 63) - 1;
|
||||
pub const RLIM = struct {
|
||||
/// No limit
|
||||
pub const INFINITY: rlim_t = (1 << 63) - 1;
|
||||
|
||||
pub const RLIM_SAVED_MAX = RLIM_INFINITY;
|
||||
pub const RLIM_SAVED_CUR = RLIM_INFINITY;
|
||||
pub const SAVED_MAX = INFINITY;
|
||||
pub const SAVED_CUR = INFINITY;
|
||||
};
|
||||
|
||||
pub const rlimit = extern struct {
|
||||
/// Soft limit
|
||||
@ -1418,16 +1398,18 @@ pub const pollfd = extern struct {
|
||||
revents: i16,
|
||||
};
|
||||
|
||||
/// Testable events (may be specified in events field).
|
||||
pub const POLLIN = 0x0001;
|
||||
pub const POLLPRI = 0x0002;
|
||||
pub const POLLOUT = 0x0004;
|
||||
pub const POLLRDNORM = 0x0040;
|
||||
pub const POLLWRNORM = POLLOUT;
|
||||
pub const POLLRDBAND = 0x0080;
|
||||
pub const POLLWRBAND = 0x0100;
|
||||
pub const POLL = struct {
|
||||
/// Testable events (may be specified in events field).
|
||||
pub const IN = 0x0001;
|
||||
pub const PRI = 0x0002;
|
||||
pub const OUT = 0x0004;
|
||||
pub const RDNORM = 0x0040;
|
||||
pub const WRNORM = OUT;
|
||||
pub const RDBAND = 0x0080;
|
||||
pub const WRBAND = 0x0100;
|
||||
|
||||
/// Non-testable events (may not be specified in events field).
|
||||
pub const POLLERR = 0x0008;
|
||||
pub const POLLHUP = 0x0010;
|
||||
pub const POLLNVAL = 0x0020;
|
||||
/// Non-testable events (may not be specified in events field).
|
||||
pub const ERR = 0x0008;
|
||||
pub const HUP = 0x0010;
|
||||
pub const NVAL = 0x0020;
|
||||
};
|
||||
|
||||
@ -71,20 +71,18 @@ pub const Kevent = extern struct {
|
||||
// Modes and flags for dlopen()
|
||||
// include/dlfcn.h
|
||||
|
||||
/// Bind function calls lazily.
|
||||
pub const RTLD_LAZY = 1;
|
||||
|
||||
/// Bind function calls immediately.
|
||||
pub const RTLD_NOW = 2;
|
||||
|
||||
/// Make symbols globally available.
|
||||
pub const RTLD_GLOBAL = 0x100;
|
||||
|
||||
/// Opposite of RTLD_GLOBAL, and the default.
|
||||
pub const RTLD_LOCAL = 0x000;
|
||||
|
||||
/// Trace loaded objects and exit.
|
||||
pub const RTLD_TRACE = 0x200;
|
||||
pub const RTLD = struct {
|
||||
/// Bind function calls lazily.
|
||||
pub const LAZY = 1;
|
||||
/// Bind function calls immediately.
|
||||
pub const NOW = 2;
|
||||
/// Make symbols globally available.
|
||||
pub const GLOBAL = 0x100;
|
||||
/// Opposite of GLOBAL, and the default.
|
||||
pub const LOCAL = 0x000;
|
||||
/// Trace loaded objects and exit.
|
||||
pub const TRACE = 0x200;
|
||||
};
|
||||
|
||||
pub const dl_phdr_info = extern struct {
|
||||
dlpi_addr: std.elf.Addr,
|
||||
@ -274,60 +272,55 @@ pub const sa_family_t = u8;
|
||||
pub const sockaddr = extern struct {
|
||||
/// total length
|
||||
len: u8,
|
||||
|
||||
/// address family
|
||||
family: sa_family_t,
|
||||
|
||||
/// actually longer; address value
|
||||
data: [14]u8,
|
||||
|
||||
pub const storage = std.x.os.Socket.Address.Native.Storage;
|
||||
|
||||
pub const in = extern struct {
|
||||
len: u8 = @sizeOf(in),
|
||||
family: sa_family_t = AF.INET,
|
||||
port: in_port_t,
|
||||
addr: u32,
|
||||
zero: [8]u8 = [8]u8{ 0, 0, 0, 0, 0, 0, 0, 0 },
|
||||
};
|
||||
|
||||
pub const in6 = extern struct {
|
||||
len: u8 = @sizeOf(in6),
|
||||
family: sa_family_t = AF.INET6,
|
||||
port: in_port_t,
|
||||
flowinfo: u32,
|
||||
addr: [16]u8,
|
||||
scope_id: u32,
|
||||
};
|
||||
|
||||
/// Definitions for UNIX IPC domain.
|
||||
pub const un = extern struct {
|
||||
/// total sockaddr length
|
||||
len: u8 = @sizeOf(un),
|
||||
|
||||
family: sa_family_t = AF.LOCAL,
|
||||
|
||||
/// path name
|
||||
path: [104]u8,
|
||||
};
|
||||
};
|
||||
|
||||
pub const sockaddr_storage = std.x.os.Socket.Address.Native.Storage;
|
||||
|
||||
pub const sockaddr_in = extern struct {
|
||||
len: u8 = @sizeOf(sockaddr_in),
|
||||
family: sa_family_t = AF_INET,
|
||||
port: in_port_t,
|
||||
addr: u32,
|
||||
zero: [8]u8 = [8]u8{ 0, 0, 0, 0, 0, 0, 0, 0 },
|
||||
pub const AI = struct {
|
||||
/// get address to use bind()
|
||||
pub const PASSIVE = 1;
|
||||
/// fill ai_canonname
|
||||
pub const CANONNAME = 2;
|
||||
/// prevent host name resolution
|
||||
pub const NUMERICHOST = 4;
|
||||
/// prevent service name resolution
|
||||
pub const NUMERICSERV = 16;
|
||||
/// only if any address is assigned
|
||||
pub const ADDRCONFIG = 64;
|
||||
};
|
||||
|
||||
pub const sockaddr_in6 = extern struct {
|
||||
len: u8 = @sizeOf(sockaddr_in6),
|
||||
family: sa_family_t = AF_INET6,
|
||||
port: in_port_t,
|
||||
flowinfo: u32,
|
||||
addr: [16]u8,
|
||||
scope_id: u32,
|
||||
};
|
||||
|
||||
/// Definitions for UNIX IPC domain.
|
||||
pub const sockaddr_un = extern struct {
|
||||
/// total sockaddr length
|
||||
len: u8 = @sizeOf(sockaddr_un),
|
||||
|
||||
/// AF_LOCAL
|
||||
family: sa_family_t = AF_LOCAL,
|
||||
|
||||
/// path name
|
||||
path: [104]u8,
|
||||
};
|
||||
|
||||
/// get address to use bind()
|
||||
pub const AI_PASSIVE = 1;
|
||||
|
||||
/// fill ai_canonname
|
||||
pub const AI_CANONNAME = 2;
|
||||
|
||||
/// prevent host name resolution
|
||||
pub const AI_NUMERICHOST = 4;
|
||||
|
||||
/// prevent service name resolution
|
||||
pub const AI_NUMERICSERV = 16;
|
||||
|
||||
/// only if any address is assigned
|
||||
pub const AI_ADDRCONFIG = 64;
|
||||
|
||||
pub const PATH_MAX = 1024;
|
||||
pub const IOV_MAX = 1024;
|
||||
|
||||
@ -340,27 +333,30 @@ pub const PROT_READ = 1;
|
||||
pub const PROT_WRITE = 2;
|
||||
pub const PROT_EXEC = 4;
|
||||
|
||||
pub const CLOCK_REALTIME = 0;
|
||||
pub const CLOCK_PROCESS_CPUTIME_ID = 2;
|
||||
pub const CLOCK_MONOTONIC = 3;
|
||||
pub const CLOCK_THREAD_CPUTIME_ID = 4;
|
||||
pub const CLOCK = struct {
|
||||
pub const REALTIME = 0;
|
||||
pub const PROCESS_CPUTIME_ID = 2;
|
||||
pub const MONOTONIC = 3;
|
||||
pub const THREAD_CPUTIME_ID = 4;
|
||||
};
|
||||
|
||||
pub const MAP_FAILED = @intToPtr(*c_void, maxInt(usize));
|
||||
pub const MAP_SHARED = 0x0001;
|
||||
pub const MAP_PRIVATE = 0x0002;
|
||||
pub const MAP_FIXED = 0x0010;
|
||||
pub const MAP_RENAME = 0;
|
||||
pub const MAP_NORESERVE = 0;
|
||||
pub const MAP_INHERIT = 0;
|
||||
pub const MAP_HASSEMAPHORE = 0;
|
||||
pub const MAP_TRYFIXED = 0;
|
||||
|
||||
pub const MAP_FILE = 0;
|
||||
pub const MAP_ANON = 0x1000;
|
||||
pub const MAP_ANONYMOUS = MAP_ANON;
|
||||
pub const MAP_STACK = 0x4000;
|
||||
pub const MAP_CONCEAL = 0x8000;
|
||||
pub const MAP = struct {
|
||||
pub const FAILED = @intToPtr(*c_void, maxInt(usize));
|
||||
pub const SHARED = 0x0001;
|
||||
pub const PRIVATE = 0x0002;
|
||||
pub const FIXED = 0x0010;
|
||||
pub const RENAME = 0;
|
||||
pub const NORESERVE = 0;
|
||||
pub const INHERIT = 0;
|
||||
pub const HASSEMAPHORE = 0;
|
||||
pub const TRYFIXED = 0;
|
||||
|
||||
pub const FILE = 0;
|
||||
pub const ANON = 0x1000;
|
||||
pub const ANONYMOUS = ANON;
|
||||
pub const STACK = 0x4000;
|
||||
pub const CONCEAL = 0x8000;
|
||||
};
|
||||
pub const WNOHANG = 1;
|
||||
pub const WUNTRACED = 2;
|
||||
pub const WCONTINUED = 8;
|
||||
@ -487,10 +483,12 @@ pub const F_RDLCK = 1;
|
||||
pub const F_UNLCK = 2;
|
||||
pub const F_WRLCK = 3;
|
||||
|
||||
pub const LOCK_SH = 0x01;
|
||||
pub const LOCK_EX = 0x02;
|
||||
pub const LOCK_NB = 0x04;
|
||||
pub const LOCK_UN = 0x08;
|
||||
pub const LOCK = struct {
|
||||
pub const SH = 0x01;
|
||||
pub const EX = 0x02;
|
||||
pub const NB = 0x04;
|
||||
pub const UN = 0x08;
|
||||
};
|
||||
|
||||
pub const FD_CLOEXEC = 1;
|
||||
|
||||
@ -502,73 +500,83 @@ pub const SIG_BLOCK = 1;
|
||||
pub const SIG_UNBLOCK = 2;
|
||||
pub const SIG_SETMASK = 3;
|
||||
|
||||
pub const SOCK_STREAM = 1;
|
||||
pub const SOCK_DGRAM = 2;
|
||||
pub const SOCK_RAW = 3;
|
||||
pub const SOCK_RDM = 4;
|
||||
pub const SOCK_SEQPACKET = 5;
|
||||
pub const SOCK = struct {
|
||||
pub const STREAM = 1;
|
||||
pub const DGRAM = 2;
|
||||
pub const RAW = 3;
|
||||
pub const RDM = 4;
|
||||
pub const SEQPACKET = 5;
|
||||
|
||||
pub const SOCK_CLOEXEC = 0x8000;
|
||||
pub const SOCK_NONBLOCK = 0x4000;
|
||||
pub const CLOEXEC = 0x8000;
|
||||
pub const NONBLOCK = 0x4000;
|
||||
};
|
||||
|
||||
pub const SO_DEBUG = 0x0001;
|
||||
pub const SO_ACCEPTCONN = 0x0002;
|
||||
pub const SO_REUSEADDR = 0x0004;
|
||||
pub const SO_KEEPALIVE = 0x0008;
|
||||
pub const SO_DONTROUTE = 0x0010;
|
||||
pub const SO_BROADCAST = 0x0020;
|
||||
pub const SO_USELOOPBACK = 0x0040;
|
||||
pub const SO_LINGER = 0x0080;
|
||||
pub const SO_OOBINLINE = 0x0100;
|
||||
pub const SO_REUSEPORT = 0x0200;
|
||||
pub const SO_TIMESTAMP = 0x0800;
|
||||
pub const SO_BINDANY = 0x1000;
|
||||
pub const SO_ZEROIZE = 0x2000;
|
||||
pub const SO_SNDBUF = 0x1001;
|
||||
pub const SO_RCVBUF = 0x1002;
|
||||
pub const SO_SNDLOWAT = 0x1003;
|
||||
pub const SO_RCVLOWAT = 0x1004;
|
||||
pub const SO_SNDTIMEO = 0x1005;
|
||||
pub const SO_RCVTIMEO = 0x1006;
|
||||
pub const SO_ERROR = 0x1007;
|
||||
pub const SO_TYPE = 0x1008;
|
||||
pub const SO_NETPROC = 0x1020;
|
||||
pub const SO_RTABLE = 0x1021;
|
||||
pub const SO_PEERCRED = 0x1022;
|
||||
pub const SO_SPLICE = 0x1023;
|
||||
pub const SO_DOMAIN = 0x1024;
|
||||
pub const SO_PROTOCOL = 0x1025;
|
||||
pub const SO = struct {
|
||||
pub const DEBUG = 0x0001;
|
||||
pub const ACCEPTCONN = 0x0002;
|
||||
pub const REUSEADDR = 0x0004;
|
||||
pub const KEEPALIVE = 0x0008;
|
||||
pub const DONTROUTE = 0x0010;
|
||||
pub const BROADCAST = 0x0020;
|
||||
pub const USELOOPBACK = 0x0040;
|
||||
pub const LINGER = 0x0080;
|
||||
pub const OOBINLINE = 0x0100;
|
||||
pub const REUSEPORT = 0x0200;
|
||||
pub const TIMESTAMP = 0x0800;
|
||||
pub const BINDANY = 0x1000;
|
||||
pub const ZEROIZE = 0x2000;
|
||||
pub const SNDBUF = 0x1001;
|
||||
pub const RCVBUF = 0x1002;
|
||||
pub const SNDLOWAT = 0x1003;
|
||||
pub const RCVLOWAT = 0x1004;
|
||||
pub const SNDTIMEO = 0x1005;
|
||||
pub const RCVTIMEO = 0x1006;
|
||||
pub const ERROR = 0x1007;
|
||||
pub const TYPE = 0x1008;
|
||||
pub const NETPROC = 0x1020;
|
||||
pub const RTABLE = 0x1021;
|
||||
pub const PEERCRED = 0x1022;
|
||||
pub const SPLICE = 0x1023;
|
||||
pub const DOMAIN = 0x1024;
|
||||
pub const PROTOCOL = 0x1025;
|
||||
};
|
||||
|
||||
pub const SOL_SOCKET = 0xffff;
|
||||
pub const SOL = struct {
|
||||
pub const SOCKET = 0xffff;
|
||||
};
|
||||
|
||||
pub const PF_UNSPEC = AF_UNSPEC;
|
||||
pub const PF_LOCAL = AF_LOCAL;
|
||||
pub const PF_UNIX = AF_UNIX;
|
||||
pub const PF_INET = AF_INET;
|
||||
pub const PF_APPLETALK = AF_APPLETALK;
|
||||
pub const PF_INET6 = AF_INET6;
|
||||
pub const PF_DECnet = AF_DECnet;
|
||||
pub const PF_KEY = AF_KEY;
|
||||
pub const PF_ROUTE = AF_ROUTE;
|
||||
pub const PF_SNA = AF_SNA;
|
||||
pub const PF_MPLS = AF_MPLS;
|
||||
pub const PF_BLUETOOTH = AF_BLUETOOTH;
|
||||
pub const PF_ISDN = AF_ISDN;
|
||||
pub const PF_MAX = AF_MAX;
|
||||
pub const PF = struct {
|
||||
pub const UNSPEC = AF.UNSPEC;
|
||||
pub const LOCAL = AF.LOCAL;
|
||||
pub const UNIX = AF.UNIX;
|
||||
pub const INET = AF.INET;
|
||||
pub const APPLETALK = AF.APPLETALK;
|
||||
pub const INET6 = AF.INET6;
|
||||
pub const DECnet = AF.DECnet;
|
||||
pub const KEY = AF.KEY;
|
||||
pub const ROUTE = AF.ROUTE;
|
||||
pub const SNA = AF.SNA;
|
||||
pub const MPLS = AF.MPLS;
|
||||
pub const BLUETOOTH = AF.BLUETOOTH;
|
||||
pub const ISDN = AF.ISDN;
|
||||
pub const MAX = AF.MAX;
|
||||
};
|
||||
|
||||
pub const AF_UNSPEC = 0;
|
||||
pub const AF_UNIX = 1;
|
||||
pub const AF_LOCAL = AF_UNIX;
|
||||
pub const AF_INET = 2;
|
||||
pub const AF_APPLETALK = 16;
|
||||
pub const AF_INET6 = 24;
|
||||
pub const AF_KEY = 30;
|
||||
pub const AF_ROUTE = 17;
|
||||
pub const AF_SNA = 11;
|
||||
pub const AF_MPLS = 33;
|
||||
pub const AF_BLUETOOTH = 32;
|
||||
pub const AF_ISDN = 26;
|
||||
pub const AF_MAX = 36;
|
||||
pub const AF = struct {
|
||||
pub const UNSPEC = 0;
|
||||
pub const UNIX = 1;
|
||||
pub const LOCAL = UNIX;
|
||||
pub const INET = 2;
|
||||
pub const APPLETALK = 16;
|
||||
pub const INET6 = 24;
|
||||
pub const KEY = 30;
|
||||
pub const ROUTE = 17;
|
||||
pub const SNA = 11;
|
||||
pub const MPLS = 33;
|
||||
pub const BLUETOOTH = 32;
|
||||
pub const ISDN = 26;
|
||||
pub const MAX = 36;
|
||||
};
|
||||
|
||||
pub const DT_UNKNOWN = 0;
|
||||
pub const DT_FIFO = 1;
|
||||
@ -1072,107 +1080,76 @@ pub const AT_REMOVEDIR = 0x08;
|
||||
|
||||
pub const HOST_NAME_MAX = 255;
|
||||
|
||||
/// dummy for IP
|
||||
pub const IPPROTO_IP = 0;
|
||||
|
||||
/// IP6 hop-by-hop options
|
||||
pub const IPPROTO_HOPOPTS = IPPROTO_IP;
|
||||
|
||||
/// control message protocol
|
||||
pub const IPPROTO_ICMP = 1;
|
||||
|
||||
/// group mgmt protocol
|
||||
pub const IPPROTO_IGMP = 2;
|
||||
|
||||
/// gateway^2 (deprecated)
|
||||
pub const IPPROTO_GGP = 3;
|
||||
|
||||
/// IP header
|
||||
pub const IPPROTO_IPV4 = IPPROTO_IPIP;
|
||||
|
||||
/// IP inside IP
|
||||
pub const IPPROTO_IPIP = 4;
|
||||
|
||||
/// tcp
|
||||
pub const IPPROTO_TCP = 6;
|
||||
|
||||
/// exterior gateway protocol
|
||||
pub const IPPROTO_EGP = 8;
|
||||
|
||||
/// pup
|
||||
pub const IPPROTO_PUP = 12;
|
||||
|
||||
/// user datagram protocol
|
||||
pub const IPPROTO_UDP = 17;
|
||||
|
||||
/// xns idp
|
||||
pub const IPPROTO_IDP = 22;
|
||||
|
||||
/// tp-4 w/ class negotiation
|
||||
pub const IPPROTO_TP = 29;
|
||||
|
||||
/// IP6 header
|
||||
pub const IPPROTO_IPV6 = 41;
|
||||
|
||||
/// IP6 routing header
|
||||
pub const IPPROTO_ROUTING = 43;
|
||||
|
||||
/// IP6 fragmentation header
|
||||
pub const IPPROTO_FRAGMENT = 44;
|
||||
|
||||
/// resource reservation
|
||||
pub const IPPROTO_RSVP = 46;
|
||||
|
||||
/// GRE encaps RFC 1701
|
||||
pub const IPPROTO_GRE = 47;
|
||||
|
||||
/// encap. security payload
|
||||
pub const IPPROTO_ESP = 50;
|
||||
|
||||
/// authentication header
|
||||
pub const IPPROTO_AH = 51;
|
||||
|
||||
/// IP Mobility RFC 2004
|
||||
pub const IPPROTO_MOBILE = 55;
|
||||
|
||||
/// IPv6 ICMP
|
||||
pub const IPPROTO_IPV6_ICMP = 58;
|
||||
|
||||
/// ICMP6
|
||||
pub const IPPROTO_ICMPV6 = 58;
|
||||
|
||||
/// IP6 no next header
|
||||
pub const IPPROTO_NONE = 59;
|
||||
|
||||
/// IP6 destination option
|
||||
pub const IPPROTO_DSTOPTS = 60;
|
||||
|
||||
/// ISO cnlp
|
||||
pub const IPPROTO_EON = 80;
|
||||
|
||||
/// Ethernet-in-IP
|
||||
pub const IPPROTO_ETHERIP = 97;
|
||||
|
||||
/// encapsulation header
|
||||
pub const IPPROTO_ENCAP = 98;
|
||||
|
||||
/// Protocol indep. multicast
|
||||
pub const IPPROTO_PIM = 103;
|
||||
|
||||
/// IP Payload Comp. Protocol
|
||||
pub const IPPROTO_IPCOMP = 108;
|
||||
|
||||
/// VRRP RFC 2338
|
||||
pub const IPPROTO_VRRP = 112;
|
||||
|
||||
/// Common Address Resolution Protocol
|
||||
pub const IPPROTO_CARP = 112;
|
||||
|
||||
/// PFSYNC
|
||||
pub const IPPROTO_PFSYNC = 240;
|
||||
|
||||
/// raw IP packet
|
||||
pub const IPPROTO_RAW = 255;
|
||||
pub const IPPROTO = struct {
|
||||
/// dummy for IP
|
||||
pub const IP = 0;
|
||||
/// IP6 hop-by-hop options
|
||||
pub const HOPOPTS = IP;
|
||||
/// control message protocol
|
||||
pub const ICMP = 1;
|
||||
/// group mgmt protocol
|
||||
pub const IGMP = 2;
|
||||
/// gateway^2 (deprecated)
|
||||
pub const GGP = 3;
|
||||
/// IP header
|
||||
pub const IPV4 = IPIP;
|
||||
/// IP inside IP
|
||||
pub const IPIP = 4;
|
||||
/// tcp
|
||||
pub const TCP = 6;
|
||||
/// exterior gateway protocol
|
||||
pub const EGP = 8;
|
||||
/// pup
|
||||
pub const PUP = 12;
|
||||
/// user datagram protocol
|
||||
pub const UDP = 17;
|
||||
/// xns idp
|
||||
pub const IDP = 22;
|
||||
/// tp-4 w/ class negotiation
|
||||
pub const TP = 29;
|
||||
/// IP6 header
|
||||
pub const IPV6 = 41;
|
||||
/// IP6 routing header
|
||||
pub const ROUTING = 43;
|
||||
/// IP6 fragmentation header
|
||||
pub const FRAGMENT = 44;
|
||||
/// resource reservation
|
||||
pub const RSVP = 46;
|
||||
/// GRE encaps RFC 1701
|
||||
pub const GRE = 47;
|
||||
/// encap. security payload
|
||||
pub const ESP = 50;
|
||||
/// authentication header
|
||||
pub const AH = 51;
|
||||
/// IP Mobility RFC 2004
|
||||
pub const MOBILE = 55;
|
||||
/// IPv6 ICMP
|
||||
pub const IPV6_ICMP = 58;
|
||||
/// ICMP6
|
||||
pub const ICMPV6 = 58;
|
||||
/// IP6 no next header
|
||||
pub const NONE = 59;
|
||||
/// IP6 destination option
|
||||
pub const DSTOPTS = 60;
|
||||
/// ISO cnlp
|
||||
pub const EON = 80;
|
||||
/// Ethernet-in-IP
|
||||
pub const ETHERIP = 97;
|
||||
/// encapsulation header
|
||||
pub const ENCAP = 98;
|
||||
/// Protocol indep. multicast
|
||||
pub const PIM = 103;
|
||||
/// IP Payload Comp. Protocol
|
||||
pub const IPCOMP = 108;
|
||||
/// VRRP RFC 2338
|
||||
pub const VRRP = 112;
|
||||
/// Common Address Resolution Protocol
|
||||
pub const CARP = 112;
|
||||
/// PFSYNC
|
||||
pub const PFSYNC = 240;
|
||||
/// raw IP packet
|
||||
pub const RAW = 255;
|
||||
};
|
||||
|
||||
pub const rlimit_resource = enum(c_int) {
|
||||
CPU,
|
||||
@ -1190,11 +1167,13 @@ pub const rlimit_resource = enum(c_int) {
|
||||
|
||||
pub const rlim_t = u64;
|
||||
|
||||
/// No limit
|
||||
pub const RLIM_INFINITY: rlim_t = (1 << 63) - 1;
|
||||
pub const RLIM = struct {
|
||||
/// No limit
|
||||
pub const INFINITY: rlim_t = (1 << 63) - 1;
|
||||
|
||||
pub const RLIM_SAVED_MAX = RLIM_INFINITY;
|
||||
pub const RLIM_SAVED_CUR = RLIM_INFINITY;
|
||||
pub const SAVED_MAX = INFINITY;
|
||||
pub const SAVED_CUR = INFINITY;
|
||||
};
|
||||
|
||||
pub const rlimit = extern struct {
|
||||
/// Soft limit
|
||||
@ -1215,17 +1194,19 @@ pub const pollfd = extern struct {
|
||||
revents: c_short,
|
||||
};
|
||||
|
||||
pub const POLLIN = 0x0001;
|
||||
pub const POLLPRI = 0x0002;
|
||||
pub const POLLOUT = 0x0004;
|
||||
pub const POLLERR = 0x0008;
|
||||
pub const POLLHUP = 0x0010;
|
||||
pub const POLLNVAL = 0x0020;
|
||||
pub const POLLRDNORM = 0x0040;
|
||||
pub const POLLNORM = POLLRDNORM;
|
||||
pub const POLLWRNORM = POLLOUT;
|
||||
pub const POLLRDBAND = 0x0080;
|
||||
pub const POLLWRBAND = 0x0100;
|
||||
pub const POLL = struct {
|
||||
pub const IN = 0x0001;
|
||||
pub const PRI = 0x0002;
|
||||
pub const OUT = 0x0004;
|
||||
pub const ERR = 0x0008;
|
||||
pub const HUP = 0x0010;
|
||||
pub const NVAL = 0x0020;
|
||||
pub const RDNORM = 0x0040;
|
||||
pub const NORM = RDNORM;
|
||||
pub const WRNORM = OUT;
|
||||
pub const RDBAND = 0x0080;
|
||||
pub const WRBAND = 0x0100;
|
||||
};
|
||||
|
||||
// sysctl mib
|
||||
pub const CTL_UNSPEC = 0;
|
||||
|
||||
@ -198,121 +198,22 @@ pub const sa_family_t = ws2_32.ADDRESS_FAMILY;
|
||||
pub const socklen_t = ws2_32.socklen_t;
|
||||
|
||||
pub const sockaddr = ws2_32.sockaddr;
|
||||
pub const sockaddr_in = ws2_32.sockaddr_in;
|
||||
pub const sockaddr_in6 = ws2_32.sockaddr_in6;
|
||||
pub const sockaddr_un = ws2_32.sockaddr_un;
|
||||
|
||||
pub const in6_addr = [16]u8;
|
||||
pub const in_addr = u32;
|
||||
|
||||
pub const addrinfo = ws2_32.addrinfo;
|
||||
|
||||
pub const AF_UNSPEC = ws2_32.AF_UNSPEC;
|
||||
pub const AF_UNIX = ws2_32.AF_UNIX;
|
||||
pub const AF_INET = ws2_32.AF_INET;
|
||||
pub const AF_IMPLINK = ws2_32.AF_IMPLINK;
|
||||
pub const AF_PUP = ws2_32.AF_PUP;
|
||||
pub const AF_CHAOS = ws2_32.AF_CHAOS;
|
||||
pub const AF_NS = ws2_32.AF_NS;
|
||||
pub const AF_IPX = ws2_32.AF_IPX;
|
||||
pub const AF_ISO = ws2_32.AF_ISO;
|
||||
pub const AF_OSI = ws2_32.AF_OSI;
|
||||
pub const AF_ECMA = ws2_32.AF_ECMA;
|
||||
pub const AF_DATAKIT = ws2_32.AF_DATAKIT;
|
||||
pub const AF_CCITT = ws2_32.AF_CCITT;
|
||||
pub const AF_SNA = ws2_32.AF_SNA;
|
||||
pub const AF_DECnet = ws2_32.AF_DECnet;
|
||||
pub const AF_DLI = ws2_32.AF_DLI;
|
||||
pub const AF_LAT = ws2_32.AF_LAT;
|
||||
pub const AF_HYLINK = ws2_32.AF_HYLINK;
|
||||
pub const AF_APPLETALK = ws2_32.AF_APPLETALK;
|
||||
pub const AF_NETBIOS = ws2_32.AF_NETBIOS;
|
||||
pub const AF_VOICEVIEW = ws2_32.AF_VOICEVIEW;
|
||||
pub const AF_FIREFOX = ws2_32.AF_FIREFOX;
|
||||
pub const AF_UNKNOWN1 = ws2_32.AF_UNKNOWN1;
|
||||
pub const AF_BAN = ws2_32.AF_BAN;
|
||||
pub const AF_ATM = ws2_32.AF_ATM;
|
||||
pub const AF_INET6 = ws2_32.AF_INET6;
|
||||
pub const AF_CLUSTER = ws2_32.AF_CLUSTER;
|
||||
pub const AF_12844 = ws2_32.AF_12844;
|
||||
pub const AF_IRDA = ws2_32.AF_IRDA;
|
||||
pub const AF_NETDES = ws2_32.AF_NETDES;
|
||||
pub const AF_TCNPROCESS = ws2_32.AF_TCNPROCESS;
|
||||
pub const AF_TCNMESSAGE = ws2_32.AF_TCNMESSAGE;
|
||||
pub const AF_ICLFXBM = ws2_32.AF_ICLFXBM;
|
||||
pub const AF_BTH = ws2_32.AF_BTH;
|
||||
pub const AF_MAX = ws2_32.AF_MAX;
|
||||
|
||||
pub const SOCK_STREAM = ws2_32.SOCK_STREAM;
|
||||
pub const SOCK_DGRAM = ws2_32.SOCK_DGRAM;
|
||||
pub const SOCK_RAW = ws2_32.SOCK_RAW;
|
||||
pub const SOCK_RDM = ws2_32.SOCK_RDM;
|
||||
pub const SOCK_SEQPACKET = ws2_32.SOCK_SEQPACKET;
|
||||
|
||||
/// WARNING: this flag is not supported by windows socket functions directly,
|
||||
/// it is only supported by std.os.socket. Be sure that this value does
|
||||
/// not share any bits with any of the SOCK_* values.
|
||||
pub const SOCK_CLOEXEC = 0x10000;
|
||||
/// WARNING: this flag is not supported by windows socket functions directly,
|
||||
/// it is only supported by std.os.socket. Be sure that this value does
|
||||
/// not share any bits with any of the SOCK_* values.
|
||||
pub const SOCK_NONBLOCK = 0x20000;
|
||||
|
||||
pub const IPPROTO_ICMP = ws2_32.IPPROTO_ICMP;
|
||||
pub const IPPROTO_IGMP = ws2_32.IPPROTO_IGMP;
|
||||
pub const AF = ws2_32.AF;
|
||||
pub const SOCK = ws2_32.SOCK;
|
||||
pub const IPPROTO = ws2_32.IPPROTOP;
|
||||
pub const BTHPROTO_RFCOMM = ws2_32.BTHPROTO_RFCOMM;
|
||||
pub const IPPROTO_TCP = ws2_32.IPPROTO_TCP;
|
||||
pub const IPPROTO_UDP = ws2_32.IPPROTO_UDP;
|
||||
pub const IPPROTO_ICMPV6 = ws2_32.IPPROTO_ICMPV6;
|
||||
pub const IPPROTO_RM = ws2_32.IPPROTO_RM;
|
||||
|
||||
pub const nfds_t = c_ulong;
|
||||
pub const pollfd = ws2_32.pollfd;
|
||||
|
||||
pub const POLLRDNORM = ws2_32.POLLRDNORM;
|
||||
pub const POLLRDBAND = ws2_32.POLLRDBAND;
|
||||
pub const POLLIN = ws2_32.POLLIN;
|
||||
pub const POLLPRI = ws2_32.POLLPRI;
|
||||
pub const POLLWRNORM = ws2_32.POLLWRNORM;
|
||||
pub const POLLOUT = ws2_32.POLLOUT;
|
||||
pub const POLLWRBAND = ws2_32.POLLWRBAND;
|
||||
pub const POLLERR = ws2_32.POLLERR;
|
||||
pub const POLLHUP = ws2_32.POLLHUP;
|
||||
pub const POLLNVAL = ws2_32.POLLNVAL;
|
||||
|
||||
pub const SOL_SOCKET = ws2_32.SOL_SOCKET;
|
||||
|
||||
pub const SO_DEBUG = ws2_32.SO_DEBUG;
|
||||
pub const SO_ACCEPTCONN = ws2_32.SO_ACCEPTCONN;
|
||||
pub const SO_REUSEADDR = ws2_32.SO_REUSEADDR;
|
||||
pub const SO_KEEPALIVE = ws2_32.SO_KEEPALIVE;
|
||||
pub const SO_DONTROUTE = ws2_32.SO_DONTROUTE;
|
||||
pub const SO_BROADCAST = ws2_32.SO_BROADCAST;
|
||||
pub const SO_USELOOPBACK = ws2_32.SO_USELOOPBACK;
|
||||
pub const SO_LINGER = ws2_32.SO_LINGER;
|
||||
pub const SO_OOBINLINE = ws2_32.SO_OOBINLINE;
|
||||
|
||||
pub const SO_DONTLINGER = ws2_32.SO_DONTLINGER;
|
||||
pub const SO_EXCLUSIVEADDRUSE = ws2_32.SO_EXCLUSIVEADDRUSE;
|
||||
|
||||
pub const SO_SNDBUF = ws2_32.SO_SNDBUF;
|
||||
pub const SO_RCVBUF = ws2_32.SO_RCVBUF;
|
||||
pub const SO_SNDLOWAT = ws2_32.SO_SNDLOWAT;
|
||||
pub const SO_RCVLOWAT = ws2_32.SO_RCVLOWAT;
|
||||
pub const SO_SNDTIMEO = ws2_32.SO_SNDTIMEO;
|
||||
pub const SO_RCVTIMEO = ws2_32.SO_RCVTIMEO;
|
||||
pub const SO_ERROR = ws2_32.SO_ERROR;
|
||||
pub const SO_TYPE = ws2_32.SO_TYPE;
|
||||
|
||||
pub const SO_GROUP_ID = ws2_32.SO_GROUP_ID;
|
||||
pub const SO_GROUP_PRIORITY = ws2_32.SO_GROUP_PRIORITY;
|
||||
pub const SO_MAX_MSG_SIZE = ws2_32.SO_MAX_MSG_SIZE;
|
||||
pub const SO_PROTOCOL_INFOA = ws2_32.SO_PROTOCOL_INFOA;
|
||||
pub const SO_PROTOCOL_INFOW = ws2_32.SO_PROTOCOL_INFOW;
|
||||
|
||||
pub const POLL = ws2_32.POLL;
|
||||
pub const SOL = ws2_32.SOL;
|
||||
pub const SO = ws2_32.SO;
|
||||
pub const PVD_CONFIG = ws2_32.PVD_CONFIG;
|
||||
pub const SO_CONDITIONAL_ACCEPT = ws2_32.SO_CONDITIONAL_ACCEPT;
|
||||
|
||||
pub const TCP_NODELAY = ws2_32.TCP_NODELAY;
|
||||
|
||||
pub const O_RDONLY = 0o0;
|
||||
|
||||
@ -7,6 +7,7 @@ const os = std.os;
|
||||
const process = std.process;
|
||||
const File = std.fs.File;
|
||||
const windows = os.windows;
|
||||
const linux = os.linux;
|
||||
const mem = std.mem;
|
||||
const math = std.math;
|
||||
const debug = std.debug;
|
||||
@ -189,8 +190,8 @@ pub const ChildProcess = struct {
|
||||
max_output_bytes: usize,
|
||||
) !void {
|
||||
var poll_fds = [_]os.pollfd{
|
||||
.{ .fd = child.stdout.?.handle, .events = os.POLLIN, .revents = undefined },
|
||||
.{ .fd = child.stderr.?.handle, .events = os.POLLIN, .revents = undefined },
|
||||
.{ .fd = child.stdout.?.handle, .events = os.POLL.IN, .revents = undefined },
|
||||
.{ .fd = child.stderr.?.handle, .events = os.POLL.IN, .revents = undefined },
|
||||
};
|
||||
|
||||
var dead_fds: usize = 0;
|
||||
@ -199,7 +200,7 @@ pub const ChildProcess = struct {
|
||||
// of space an ArrayList will allocate grows exponentially.
|
||||
const bump_amt = 512;
|
||||
|
||||
const err_mask = os.POLLERR | os.POLLNVAL | os.POLLHUP;
|
||||
const err_mask = os.POLL.ERR | os.POLL.NVAL | os.POLL.HUP;
|
||||
|
||||
while (dead_fds < poll_fds.len) {
|
||||
const events = try os.poll(&poll_fds, std.math.maxInt(i32));
|
||||
@ -209,9 +210,9 @@ pub const ChildProcess = struct {
|
||||
var remove_stderr = false;
|
||||
// Try reading whatever is available before checking the error
|
||||
// conditions.
|
||||
// It's still possible to read after a POLLHUP is received, always
|
||||
// It's still possible to read after a POLL.HUP is received, always
|
||||
// check if there's some data waiting to be read first.
|
||||
if (poll_fds[0].revents & os.POLLIN != 0) {
|
||||
if (poll_fds[0].revents & os.POLL.IN != 0) {
|
||||
// stdout is ready.
|
||||
const new_capacity = std.math.min(stdout.items.len + bump_amt, max_output_bytes);
|
||||
try stdout.ensureCapacity(new_capacity);
|
||||
@ -226,7 +227,7 @@ pub const ChildProcess = struct {
|
||||
remove_stdout = poll_fds[0].revents & err_mask != 0;
|
||||
}
|
||||
|
||||
if (poll_fds[1].revents & os.POLLIN != 0) {
|
||||
if (poll_fds[1].revents & os.POLL.IN != 0) {
|
||||
// stderr is ready.
|
||||
const new_capacity = std.math.min(stderr.items.len + bump_amt, max_output_bytes);
|
||||
try stderr.ensureCapacity(new_capacity);
|
||||
@ -461,7 +462,7 @@ pub const ChildProcess = struct {
|
||||
if (builtin.os.tag == .linux) {
|
||||
var fd = [1]std.os.pollfd{std.os.pollfd{
|
||||
.fd = self.err_pipe[0],
|
||||
.events = std.os.POLLIN,
|
||||
.events = std.os.POLL.IN,
|
||||
.revents = undefined,
|
||||
}};
|
||||
|
||||
@ -471,7 +472,7 @@ pub const ChildProcess = struct {
|
||||
|
||||
// According to eventfd(2) the descriptro is readable if the counter
|
||||
// has a value greater than 0
|
||||
if ((fd[0].revents & std.os.POLLIN) != 0) {
|
||||
if ((fd[0].revents & std.os.POLL.IN) != 0) {
|
||||
const err_int = try readIntFd(self.err_pipe[0]);
|
||||
return @errSetCast(SpawnError, @intToError(err_int));
|
||||
}
|
||||
@ -494,18 +495,18 @@ pub const ChildProcess = struct {
|
||||
}
|
||||
|
||||
fn statusToTerm(status: u32) Term {
|
||||
return if (os.WIFEXITED(status))
|
||||
Term{ .Exited = os.WEXITSTATUS(status) }
|
||||
else if (os.WIFSIGNALED(status))
|
||||
Term{ .Signal = os.WTERMSIG(status) }
|
||||
else if (os.WIFSTOPPED(status))
|
||||
Term{ .Stopped = os.WSTOPSIG(status) }
|
||||
return if (os.W.IFEXITED(status))
|
||||
Term{ .Exited = os.W.EXITSTATUS(status) }
|
||||
else if (os.W.IFSIGNALED(status))
|
||||
Term{ .Signal = os.W.TERMSIG(status) }
|
||||
else if (os.W.IFSTOPPED(status))
|
||||
Term{ .Stopped = os.W.STOPSIG(status) }
|
||||
else
|
||||
Term{ .Unknown = status };
|
||||
}
|
||||
|
||||
fn spawnPosix(self: *ChildProcess) SpawnError!void {
|
||||
const pipe_flags = if (io.is_async) os.O_NONBLOCK else 0;
|
||||
const pipe_flags = if (io.is_async) os.O.NONBLOCK else 0;
|
||||
const stdin_pipe = if (self.stdin_behavior == StdIo.Pipe) try os.pipe2(pipe_flags) else undefined;
|
||||
errdefer if (self.stdin_behavior == StdIo.Pipe) {
|
||||
destroyPipe(stdin_pipe);
|
||||
@ -523,7 +524,7 @@ pub const ChildProcess = struct {
|
||||
|
||||
const any_ignore = (self.stdin_behavior == StdIo.Ignore or self.stdout_behavior == StdIo.Ignore or self.stderr_behavior == StdIo.Ignore);
|
||||
const dev_null_fd = if (any_ignore)
|
||||
os.openZ("/dev/null", os.O_RDWR, 0) catch |err| switch (err) {
|
||||
os.openZ("/dev/null", os.O.RDWR, 0) catch |err| switch (err) {
|
||||
error.PathAlreadyExists => unreachable,
|
||||
error.NoSpaceLeft => unreachable,
|
||||
error.FileTooBig => unreachable,
|
||||
@ -575,12 +576,12 @@ pub const ChildProcess = struct {
|
||||
// and execve from the child process to the parent process.
|
||||
const err_pipe = blk: {
|
||||
if (builtin.os.tag == .linux) {
|
||||
const fd = try os.eventfd(0, os.EFD_CLOEXEC);
|
||||
const fd = try os.eventfd(0, linux.EFD.CLOEXEC);
|
||||
// There's no distinction between the readable and the writeable
|
||||
// end with eventfd
|
||||
break :blk [2]os.fd_t{ fd, fd };
|
||||
} else {
|
||||
break :blk try os.pipe2(os.O_CLOEXEC);
|
||||
break :blk try os.pipe2(os.O.CLOEXEC);
|
||||
}
|
||||
};
|
||||
errdefer destroyPipe(err_pipe);
|
||||
|
||||
@ -74,8 +74,8 @@ fn tlsCsprngFill(_: *const std.rand.Random, buffer: []u8) void {
|
||||
wipe_mem = os.mmap(
|
||||
null,
|
||||
@sizeOf(Context),
|
||||
os.PROT_READ | os.PROT_WRITE,
|
||||
os.MAP_PRIVATE | os.MAP_ANONYMOUS,
|
||||
os.PROT.READ | os.PROT.WRITE,
|
||||
os.MAP.PRIVATE | os.MAP.ANONYMOUS,
|
||||
-1,
|
||||
0,
|
||||
) catch {
|
||||
@ -111,7 +111,7 @@ fn tlsCsprngFill(_: *const std.rand.Random, buffer: []u8) void {
|
||||
break :wof;
|
||||
} else |_| {}
|
||||
|
||||
if (os.madvise(wipe_mem.ptr, wipe_mem.len, os.MADV_WIPEONFORK)) |_| {
|
||||
if (os.madvise(wipe_mem.ptr, wipe_mem.len, os.MADV.WIPEONFORK)) |_| {
|
||||
return initAndFill(buffer);
|
||||
} else |_| {}
|
||||
}
|
||||
|
||||
@ -115,7 +115,7 @@ pub const ElfDynLib = struct {
|
||||
|
||||
/// Trusts the file. Malicious file will be able to execute arbitrary code.
|
||||
pub fn open(path: []const u8) !ElfDynLib {
|
||||
const fd = try os.open(path, 0, os.O_RDONLY | os.O_CLOEXEC);
|
||||
const fd = try os.open(path, 0, os.O.RDONLY | os.O.CLOEXEC);
|
||||
defer os.close(fd);
|
||||
|
||||
const stat = try os.fstat(fd);
|
||||
@ -126,8 +126,8 @@ pub const ElfDynLib = struct {
|
||||
const file_bytes = try os.mmap(
|
||||
null,
|
||||
mem.alignForward(size, mem.page_size),
|
||||
os.PROT_READ,
|
||||
os.MAP_PRIVATE,
|
||||
os.PROT.READ,
|
||||
os.MAP.PRIVATE,
|
||||
fd,
|
||||
0,
|
||||
);
|
||||
@ -160,12 +160,12 @@ pub const ElfDynLib = struct {
|
||||
}
|
||||
const dynv = maybe_dynv orelse return error.MissingDynamicLinkingInformation;
|
||||
|
||||
// Reserve the entire range (with no permissions) so that we can do MAP_FIXED below.
|
||||
// Reserve the entire range (with no permissions) so that we can do MAP.FIXED below.
|
||||
const all_loaded_mem = try os.mmap(
|
||||
null,
|
||||
virt_addr_end,
|
||||
os.PROT_NONE,
|
||||
os.MAP_PRIVATE | os.MAP_ANONYMOUS,
|
||||
os.PROT.NONE,
|
||||
os.MAP.PRIVATE | os.MAP.ANONYMOUS,
|
||||
-1,
|
||||
0,
|
||||
);
|
||||
@ -197,7 +197,7 @@ pub const ElfDynLib = struct {
|
||||
ptr,
|
||||
extended_memsz,
|
||||
prot,
|
||||
os.MAP_PRIVATE | os.MAP_FIXED,
|
||||
os.MAP.PRIVATE | os.MAP.FIXED,
|
||||
fd,
|
||||
ph.p_offset - extra_bytes,
|
||||
);
|
||||
@ -206,7 +206,7 @@ pub const ElfDynLib = struct {
|
||||
ptr,
|
||||
extended_memsz,
|
||||
prot,
|
||||
os.MAP_PRIVATE | os.MAP_FIXED | os.MAP_ANONYMOUS,
|
||||
os.MAP.PRIVATE | os.MAP.FIXED | os.MAP.ANONYMOUS,
|
||||
-1,
|
||||
0,
|
||||
);
|
||||
@ -294,10 +294,10 @@ pub const ElfDynLib = struct {
|
||||
}
|
||||
|
||||
fn elfToMmapProt(elf_prot: u64) u32 {
|
||||
var result: u32 = os.PROT_NONE;
|
||||
if ((elf_prot & elf.PF_R) != 0) result |= os.PROT_READ;
|
||||
if ((elf_prot & elf.PF_W) != 0) result |= os.PROT_WRITE;
|
||||
if ((elf_prot & elf.PF_X) != 0) result |= os.PROT_EXEC;
|
||||
var result: u32 = os.PROT.NONE;
|
||||
if ((elf_prot & elf.PF_R) != 0) result |= os.PROT.READ;
|
||||
if ((elf_prot & elf.PF_W) != 0) result |= os.PROT.WRITE;
|
||||
if ((elf_prot & elf.PF_X) != 0) result |= os.PROT.EXEC;
|
||||
return result;
|
||||
}
|
||||
};
|
||||
@ -373,7 +373,7 @@ pub const DlDynlib = struct {
|
||||
|
||||
pub fn openZ(path_c: [*:0]const u8) !DlDynlib {
|
||||
return DlDynlib{
|
||||
.handle = system.dlopen(path_c, system.RTLD_LAZY) orelse {
|
||||
.handle = system.dlopen(path_c, system.RTLD.LAZY) orelse {
|
||||
return error.FileNotFound;
|
||||
},
|
||||
};
|
||||
|
||||
@ -457,8 +457,8 @@ pub const Loop = struct {
|
||||
// Fall back to a blocking poll(). Ideally this codepath is never hit, since
|
||||
// epoll should be just fine. But this is better than incorrect behavior.
|
||||
var poll_flags: i16 = 0;
|
||||
if ((flags & os.EPOLLIN) != 0) poll_flags |= os.POLLIN;
|
||||
if ((flags & os.EPOLLOUT) != 0) poll_flags |= os.POLLOUT;
|
||||
if ((flags & os.EPOLLIN) != 0) poll_flags |= os.POLL.IN;
|
||||
if ((flags & os.EPOLLOUT) != 0) poll_flags |= os.POLL.OUT;
|
||||
var pfd = [1]os.pollfd{os.pollfd{
|
||||
.fd = fd,
|
||||
.events = poll_flags,
|
||||
@ -903,12 +903,12 @@ pub const Loop = struct {
|
||||
/// will return a value greater than was supplied to the call.
|
||||
addr_size: *os.socklen_t,
|
||||
/// The following values can be bitwise ORed in flags to obtain different behavior:
|
||||
/// * `SOCK_CLOEXEC` - Set the close-on-exec (`FD_CLOEXEC`) flag on the new file descriptor. See the
|
||||
/// * `SOCK.CLOEXEC` - Set the close-on-exec (`FD_CLOEXEC`) flag on the new file descriptor. See the
|
||||
/// description of the `O_CLOEXEC` flag in `open` for reasons why this may be useful.
|
||||
flags: u32,
|
||||
) os.AcceptError!os.socket_t {
|
||||
while (true) {
|
||||
return os.accept(sockfd, addr, addr_size, flags | os.SOCK_NONBLOCK) catch |err| switch (err) {
|
||||
return os.accept(sockfd, addr, addr_size, flags | os.SOCK.NONBLOCK) catch |err| switch (err) {
|
||||
error.WouldBlock => {
|
||||
self.waitUntilFdReadable(sockfd);
|
||||
continue;
|
||||
|
||||
@ -500,13 +500,14 @@ pub const Dir = struct {
|
||||
},
|
||||
.linux => struct {
|
||||
dir: Dir,
|
||||
// The if guard is solely there to prevent compile errors from missing `os.linux.dirent64`
|
||||
// The if guard is solely there to prevent compile errors from missing `linux.dirent64`
|
||||
// definition when compiling for other OSes. It doesn't do anything when compiling for Linux.
|
||||
buf: [8192]u8 align(if (builtin.os.tag != .linux) 1 else @alignOf(os.linux.dirent64)),
|
||||
buf: [8192]u8 align(if (builtin.os.tag != .linux) 1 else @alignOf(linux.dirent64)),
|
||||
index: usize,
|
||||
end_index: usize,
|
||||
|
||||
const Self = @This();
|
||||
const linux = os.linux;
|
||||
|
||||
pub const Error = IteratorError;
|
||||
|
||||
@ -515,8 +516,8 @@ pub const Dir = struct {
|
||||
pub fn next(self: *Self) Error!?Entry {
|
||||
start_over: while (true) {
|
||||
if (self.index >= self.end_index) {
|
||||
const rc = os.linux.getdents64(self.dir.fd, &self.buf, self.buf.len);
|
||||
switch (os.linux.getErrno(rc)) {
|
||||
const rc = linux.getdents64(self.dir.fd, &self.buf, self.buf.len);
|
||||
switch (linux.getErrno(rc)) {
|
||||
.SUCCESS => {},
|
||||
.BADF => unreachable, // Dir is invalid or was opened without iteration ability
|
||||
.FAULT => unreachable,
|
||||
@ -528,7 +529,7 @@ pub const Dir = struct {
|
||||
self.index = 0;
|
||||
self.end_index = rc;
|
||||
}
|
||||
const linux_entry = @ptrCast(*align(1) os.dirent64, &self.buf[self.index]);
|
||||
const linux_entry = @ptrCast(*align(1) linux.dirent64, &self.buf[self.index]);
|
||||
const next_index = self.index + linux_entry.reclen();
|
||||
self.index = next_index;
|
||||
|
||||
@ -540,13 +541,13 @@ pub const Dir = struct {
|
||||
}
|
||||
|
||||
const entry_kind = switch (linux_entry.d_type) {
|
||||
os.DT_BLK => Entry.Kind.BlockDevice,
|
||||
os.DT_CHR => Entry.Kind.CharacterDevice,
|
||||
os.DT_DIR => Entry.Kind.Directory,
|
||||
os.DT_FIFO => Entry.Kind.NamedPipe,
|
||||
os.DT_LNK => Entry.Kind.SymLink,
|
||||
os.DT_REG => Entry.Kind.File,
|
||||
os.DT_SOCK => Entry.Kind.UnixDomainSocket,
|
||||
linux.DT.BLK => Entry.Kind.BlockDevice,
|
||||
linux.DT.CHR => Entry.Kind.CharacterDevice,
|
||||
linux.DT.DIR => Entry.Kind.Directory,
|
||||
linux.DT.FIFO => Entry.Kind.NamedPipe,
|
||||
linux.DT.LNK => Entry.Kind.SymLink,
|
||||
linux.DT.REG => Entry.Kind.File,
|
||||
linux.DT.SOCK => Entry.Kind.UnixDomainSocket,
|
||||
else => Entry.Kind.Unknown,
|
||||
};
|
||||
return Entry{
|
||||
@ -1537,7 +1538,7 @@ pub const Dir = struct {
|
||||
return self.deleteFileW(sub_path_w.span());
|
||||
} else if (builtin.os.tag == .wasi and !builtin.link_libc) {
|
||||
os.unlinkatWasi(self.fd, sub_path, 0) catch |err| switch (err) {
|
||||
error.DirNotEmpty => unreachable, // not passing AT_REMOVEDIR
|
||||
error.DirNotEmpty => unreachable, // not passing AT.REMOVEDIR
|
||||
else => |e| return e,
|
||||
};
|
||||
} else {
|
||||
@ -1551,13 +1552,13 @@ pub const Dir = struct {
|
||||
/// Same as `deleteFile` except the parameter is null-terminated.
|
||||
pub fn deleteFileZ(self: Dir, sub_path_c: [*:0]const u8) DeleteFileError!void {
|
||||
os.unlinkatZ(self.fd, sub_path_c, 0) catch |err| switch (err) {
|
||||
error.DirNotEmpty => unreachable, // not passing AT_REMOVEDIR
|
||||
error.DirNotEmpty => unreachable, // not passing AT.REMOVEDIR
|
||||
error.AccessDenied => |e| switch (builtin.os.tag) {
|
||||
// non-Linux POSIX systems return EPERM when trying to delete a directory, so
|
||||
// we need to handle that case specifically and translate the error
|
||||
.macos, .ios, .freebsd, .netbsd, .dragonfly, .openbsd => {
|
||||
// Don't follow symlinks to match unlinkat (which acts on symlinks rather than follows them)
|
||||
const fstat = os.fstatatZ(self.fd, sub_path_c, os.AT_SYMLINK_NOFOLLOW) catch return e;
|
||||
const fstat = os.fstatatZ(self.fd, sub_path_c, os.AT.SYMLINK_NOFOLLOW) catch return e;
|
||||
const is_dir = fstat.mode & os.S_IFMT == os.S_IFDIR;
|
||||
return if (is_dir) error.IsDir else e;
|
||||
},
|
||||
@ -1570,7 +1571,7 @@ pub const Dir = struct {
|
||||
/// Same as `deleteFile` except the parameter is WTF-16 encoded.
|
||||
pub fn deleteFileW(self: Dir, sub_path_w: []const u16) DeleteFileError!void {
|
||||
os.unlinkatW(self.fd, sub_path_w, 0) catch |err| switch (err) {
|
||||
error.DirNotEmpty => unreachable, // not passing AT_REMOVEDIR
|
||||
error.DirNotEmpty => unreachable, // not passing AT.REMOVEDIR
|
||||
else => |e| return e,
|
||||
};
|
||||
}
|
||||
@ -1599,8 +1600,8 @@ pub const Dir = struct {
|
||||
const sub_path_w = try os.windows.sliceToPrefixedFileW(sub_path);
|
||||
return self.deleteDirW(sub_path_w.span());
|
||||
} else if (builtin.os.tag == .wasi and !builtin.link_libc) {
|
||||
os.unlinkat(self.fd, sub_path, os.AT_REMOVEDIR) catch |err| switch (err) {
|
||||
error.IsDir => unreachable, // not possible since we pass AT_REMOVEDIR
|
||||
os.unlinkat(self.fd, sub_path, os.AT.REMOVEDIR) catch |err| switch (err) {
|
||||
error.IsDir => unreachable, // not possible since we pass AT.REMOVEDIR
|
||||
else => |e| return e,
|
||||
};
|
||||
} else {
|
||||
@ -1611,8 +1612,8 @@ pub const Dir = struct {
|
||||
|
||||
/// Same as `deleteDir` except the parameter is null-terminated.
|
||||
pub fn deleteDirZ(self: Dir, sub_path_c: [*:0]const u8) DeleteDirError!void {
|
||||
os.unlinkatZ(self.fd, sub_path_c, os.AT_REMOVEDIR) catch |err| switch (err) {
|
||||
error.IsDir => unreachable, // not possible since we pass AT_REMOVEDIR
|
||||
os.unlinkatZ(self.fd, sub_path_c, os.AT.REMOVEDIR) catch |err| switch (err) {
|
||||
error.IsDir => unreachable, // not possible since we pass AT.REMOVEDIR
|
||||
else => |e| return e,
|
||||
};
|
||||
}
|
||||
@ -1620,8 +1621,8 @@ pub const Dir = struct {
|
||||
/// Same as `deleteDir` except the parameter is UTF16LE, NT prefixed.
|
||||
/// This function is Windows-only.
|
||||
pub fn deleteDirW(self: Dir, sub_path_w: []const u16) DeleteDirError!void {
|
||||
os.unlinkatW(self.fd, sub_path_w, os.AT_REMOVEDIR) catch |err| switch (err) {
|
||||
error.IsDir => unreachable, // not possible since we pass AT_REMOVEDIR
|
||||
os.unlinkatW(self.fd, sub_path_w, os.AT.REMOVEDIR) catch |err| switch (err) {
|
||||
error.IsDir => unreachable, // not possible since we pass AT.REMOVEDIR
|
||||
else => |e| return e,
|
||||
};
|
||||
}
|
||||
|
||||
@ -883,9 +883,9 @@ pub const File = struct {
|
||||
};
|
||||
} else {
|
||||
return os.flock(file.handle, switch (l) {
|
||||
.None => os.LOCK_UN,
|
||||
.Shared => os.LOCK_SH,
|
||||
.Exclusive => os.LOCK_EX,
|
||||
.None => os.LOCK.UN,
|
||||
.Shared => os.LOCK.SH,
|
||||
.Exclusive => os.LOCK.EX,
|
||||
}) catch |err| switch (err) {
|
||||
error.WouldBlock => unreachable, // non-blocking=false
|
||||
else => |e| return e,
|
||||
@ -908,7 +908,7 @@ pub const File = struct {
|
||||
error.Unexpected => unreachable, // Resource deallocation must succeed.
|
||||
};
|
||||
} else {
|
||||
return os.flock(file.handle, os.LOCK_UN) catch |err| switch (err) {
|
||||
return os.flock(file.handle, os.LOCK.UN) catch |err| switch (err) {
|
||||
error.WouldBlock => unreachable, // unlocking can't block
|
||||
error.SystemResources => unreachable, // We are deallocating resources.
|
||||
error.Unexpected => unreachable, // Resource deallocation must succeed.
|
||||
@ -949,9 +949,9 @@ pub const File = struct {
|
||||
};
|
||||
} else {
|
||||
os.flock(file.handle, switch (l) {
|
||||
.None => os.LOCK_UN,
|
||||
.Shared => os.LOCK_SH | os.LOCK_NB,
|
||||
.Exclusive => os.LOCK_EX | os.LOCK_NB,
|
||||
.None => os.LOCK.UN,
|
||||
.Shared => os.LOCK.SH | os.LOCK.NB,
|
||||
.Exclusive => os.LOCK.EX | os.LOCK.NB,
|
||||
}) catch |err| switch (err) {
|
||||
error.WouldBlock => return false,
|
||||
else => |e| return e,
|
||||
@ -998,7 +998,7 @@ pub const File = struct {
|
||||
error.Unexpected => unreachable, // Resource deallocation must succeed.
|
||||
};
|
||||
} else {
|
||||
return os.flock(file.handle, os.LOCK_SH | os.LOCK_NB) catch |err| switch (err) {
|
||||
return os.flock(file.handle, os.LOCK.SH | os.LOCK.NB) catch |err| switch (err) {
|
||||
error.WouldBlock => unreachable, // File was not locked in exclusive mode.
|
||||
else => |e| return e,
|
||||
};
|
||||
|
||||
194
lib/std/net.zig
194
lib/std/net.zig
@ -10,7 +10,7 @@ const native_endian = builtin.target.cpu.arch.endian();
|
||||
|
||||
// Windows 10 added support for unix sockets in build 17063, redstone 4 is the
|
||||
// first release to support them.
|
||||
pub const has_unix_sockets = @hasDecl(os, "sockaddr_un") and
|
||||
pub const has_unix_sockets = @hasDecl(os.sockaddr, "un") and
|
||||
(builtin.target.os.tag != .windows or
|
||||
std.Target.current.os.version_range.windows.isAtLeast(.win10_rs4) orelse false);
|
||||
|
||||
@ -18,7 +18,7 @@ pub const Address = extern union {
|
||||
any: os.sockaddr,
|
||||
in: Ip4Address,
|
||||
in6: Ip6Address,
|
||||
un: if (has_unix_sockets) os.sockaddr_un else void,
|
||||
un: if (has_unix_sockets) os.sockaddr.un else void,
|
||||
|
||||
/// Parse the given IP address string into an Address value.
|
||||
/// It is recommended to use `resolveIp` instead, to handle
|
||||
@ -70,9 +70,9 @@ pub const Address = extern union {
|
||||
|
||||
pub fn parseExpectingFamily(name: []const u8, family: os.sa_family_t, port: u16) !Address {
|
||||
switch (family) {
|
||||
os.AF_INET => return parseIp4(name, port),
|
||||
os.AF_INET6 => return parseIp6(name, port),
|
||||
os.AF_UNSPEC => return parseIp(name, port),
|
||||
os.AF.INET => return parseIp4(name, port),
|
||||
os.AF.INET6 => return parseIp6(name, port),
|
||||
os.AF.UNSPEC => return parseIp(name, port),
|
||||
else => unreachable,
|
||||
}
|
||||
}
|
||||
@ -98,8 +98,8 @@ pub const Address = extern union {
|
||||
}
|
||||
|
||||
pub fn initUnix(path: []const u8) !Address {
|
||||
var sock_addr = os.sockaddr_un{
|
||||
.family = os.AF_UNIX,
|
||||
var sock_addr = os.sockaddr.un{
|
||||
.family = os.AF.UNIX,
|
||||
.path = undefined,
|
||||
};
|
||||
|
||||
@ -116,8 +116,8 @@ pub const Address = extern union {
|
||||
/// Asserts that the address is ip4 or ip6.
|
||||
pub fn getPort(self: Address) u16 {
|
||||
return switch (self.any.family) {
|
||||
os.AF_INET => self.in.getPort(),
|
||||
os.AF_INET6 => self.in6.getPort(),
|
||||
os.AF.INET => self.in.getPort(),
|
||||
os.AF.INET6 => self.in6.getPort(),
|
||||
else => unreachable,
|
||||
};
|
||||
}
|
||||
@ -126,8 +126,8 @@ pub const Address = extern union {
|
||||
/// Asserts that the address is ip4 or ip6.
|
||||
pub fn setPort(self: *Address, port: u16) void {
|
||||
switch (self.any.family) {
|
||||
os.AF_INET => self.in.setPort(port),
|
||||
os.AF_INET6 => self.in6.setPort(port),
|
||||
os.AF.INET => self.in.setPort(port),
|
||||
os.AF.INET6 => self.in6.setPort(port),
|
||||
else => unreachable,
|
||||
}
|
||||
}
|
||||
@ -137,8 +137,8 @@ pub const Address = extern union {
|
||||
/// on the address family.
|
||||
pub fn initPosix(addr: *align(4) const os.sockaddr) Address {
|
||||
switch (addr.family) {
|
||||
os.AF_INET => return Address{ .in = Ip4Address{ .sa = @ptrCast(*const os.sockaddr_in, addr).* } },
|
||||
os.AF_INET6 => return Address{ .in6 = Ip6Address{ .sa = @ptrCast(*const os.sockaddr_in6, addr).* } },
|
||||
os.AF.INET => return Address{ .in = Ip4Address{ .sa = @ptrCast(*const os.sockaddr.in, addr).* } },
|
||||
os.AF.INET6 => return Address{ .in6 = Ip6Address{ .sa = @ptrCast(*const os.sockaddr.in6, addr).* } },
|
||||
else => unreachable,
|
||||
}
|
||||
}
|
||||
@ -150,9 +150,9 @@ pub const Address = extern union {
|
||||
out_stream: anytype,
|
||||
) !void {
|
||||
switch (self.any.family) {
|
||||
os.AF_INET => try self.in.format(fmt, options, out_stream),
|
||||
os.AF_INET6 => try self.in6.format(fmt, options, out_stream),
|
||||
os.AF_UNIX => {
|
||||
os.AF.INET => try self.in.format(fmt, options, out_stream),
|
||||
os.AF.INET6 => try self.in6.format(fmt, options, out_stream),
|
||||
os.AF.UNIX => {
|
||||
if (!has_unix_sockets) {
|
||||
unreachable;
|
||||
}
|
||||
@ -171,15 +171,15 @@ pub const Address = extern union {
|
||||
|
||||
pub fn getOsSockLen(self: Address) os.socklen_t {
|
||||
switch (self.any.family) {
|
||||
os.AF_INET => return self.in.getOsSockLen(),
|
||||
os.AF_INET6 => return self.in6.getOsSockLen(),
|
||||
os.AF_UNIX => {
|
||||
os.AF.INET => return self.in.getOsSockLen(),
|
||||
os.AF.INET6 => return self.in6.getOsSockLen(),
|
||||
os.AF.UNIX => {
|
||||
if (!has_unix_sockets) {
|
||||
unreachable;
|
||||
}
|
||||
|
||||
const path_len = std.mem.len(std.meta.assumeSentinel(&self.un.path, 0));
|
||||
return @intCast(os.socklen_t, @sizeOf(os.sockaddr_un) - self.un.path.len + path_len);
|
||||
return @intCast(os.socklen_t, @sizeOf(os.sockaddr.un) - self.un.path.len + path_len);
|
||||
},
|
||||
else => unreachable,
|
||||
}
|
||||
@ -187,7 +187,7 @@ pub const Address = extern union {
|
||||
};
|
||||
|
||||
pub const Ip4Address = extern struct {
|
||||
sa: os.sockaddr_in,
|
||||
sa: os.sockaddr.in,
|
||||
|
||||
pub fn parse(buf: []const u8, port: u16) !Ip4Address {
|
||||
var result = Ip4Address{
|
||||
@ -249,7 +249,7 @@ pub const Ip4Address = extern struct {
|
||||
|
||||
pub fn init(addr: [4]u8, port: u16) Ip4Address {
|
||||
return Ip4Address{
|
||||
.sa = os.sockaddr_in{
|
||||
.sa = os.sockaddr.in{
|
||||
.port = mem.nativeToBig(u16, port),
|
||||
.addr = @ptrCast(*align(1) const u32, &addr).*,
|
||||
},
|
||||
@ -288,19 +288,19 @@ pub const Ip4Address = extern struct {
|
||||
|
||||
pub fn getOsSockLen(self: Ip4Address) os.socklen_t {
|
||||
_ = self;
|
||||
return @sizeOf(os.sockaddr_in);
|
||||
return @sizeOf(os.sockaddr.in);
|
||||
}
|
||||
};
|
||||
|
||||
pub const Ip6Address = extern struct {
|
||||
sa: os.sockaddr_in6,
|
||||
sa: os.sockaddr.in6,
|
||||
|
||||
/// Parse a given IPv6 address string into an Address.
|
||||
/// Assumes the Scope ID of the address is fully numeric.
|
||||
/// For non-numeric addresses, see `resolveIp6`.
|
||||
pub fn parse(buf: []const u8, port: u16) !Ip6Address {
|
||||
var result = Ip6Address{
|
||||
.sa = os.sockaddr_in6{
|
||||
.sa = os.sockaddr.in6{
|
||||
.scope_id = 0,
|
||||
.port = mem.nativeToBig(u16, port),
|
||||
.flowinfo = 0,
|
||||
@ -407,7 +407,7 @@ pub const Ip6Address = extern struct {
|
||||
pub fn resolve(buf: []const u8, port: u16) !Ip6Address {
|
||||
// TODO: Unify the implementations of resolveIp6 and parseIp6.
|
||||
var result = Ip6Address{
|
||||
.sa = os.sockaddr_in6{
|
||||
.sa = os.sockaddr.in6{
|
||||
.scope_id = 0,
|
||||
.port = mem.nativeToBig(u16, port),
|
||||
.flowinfo = 0,
|
||||
@ -536,7 +536,7 @@ pub const Ip6Address = extern struct {
|
||||
|
||||
pub fn init(addr: [16]u8, port: u16, flowinfo: u32, scope_id: u32) Ip6Address {
|
||||
return Ip6Address{
|
||||
.sa = os.sockaddr_in6{
|
||||
.sa = os.sockaddr.in6{
|
||||
.addr = addr,
|
||||
.port = mem.nativeToBig(u16, port),
|
||||
.flowinfo = flowinfo,
|
||||
@ -608,15 +608,15 @@ pub const Ip6Address = extern struct {
|
||||
|
||||
pub fn getOsSockLen(self: Ip6Address) os.socklen_t {
|
||||
_ = self;
|
||||
return @sizeOf(os.sockaddr_in6);
|
||||
return @sizeOf(os.sockaddr.in6);
|
||||
}
|
||||
};
|
||||
|
||||
pub fn connectUnixSocket(path: []const u8) !Stream {
|
||||
const opt_non_block = if (std.io.is_async) os.SOCK_NONBLOCK else 0;
|
||||
const opt_non_block = if (std.io.is_async) os.SOCK.NONBLOCK else 0;
|
||||
const sockfd = try os.socket(
|
||||
os.AF_UNIX,
|
||||
os.SOCK_STREAM | os.SOCK_CLOEXEC | opt_non_block,
|
||||
os.AF.UNIX,
|
||||
os.SOCK.STREAM | os.SOCK.CLOEXEC | opt_non_block,
|
||||
0,
|
||||
);
|
||||
errdefer os.closeSocket(sockfd);
|
||||
@ -637,7 +637,7 @@ pub fn connectUnixSocket(path: []const u8) !Stream {
|
||||
|
||||
fn if_nametoindex(name: []const u8) !u32 {
|
||||
var ifr: os.ifreq = undefined;
|
||||
var sockfd = try os.socket(os.AF_UNIX, os.SOCK_DGRAM | os.SOCK_CLOEXEC, 0);
|
||||
var sockfd = try os.socket(os.AF.UNIX, os.SOCK.DGRAM | os.SOCK.CLOEXEC, 0);
|
||||
defer os.closeSocket(sockfd);
|
||||
|
||||
std.mem.copy(u8, &ifr.ifrn.name, name);
|
||||
@ -682,10 +682,10 @@ pub fn tcpConnectToHost(allocator: *mem.Allocator, name: []const u8, port: u16)
|
||||
}
|
||||
|
||||
pub fn tcpConnectToAddress(address: Address) !Stream {
|
||||
const nonblock = if (std.io.is_async) os.SOCK_NONBLOCK else 0;
|
||||
const sock_flags = os.SOCK_STREAM | nonblock |
|
||||
(if (builtin.target.os.tag == .windows) 0 else os.SOCK_CLOEXEC);
|
||||
const sockfd = try os.socket(address.any.family, sock_flags, os.IPPROTO_TCP);
|
||||
const nonblock = if (std.io.is_async) os.SOCK.NONBLOCK else 0;
|
||||
const sock_flags = os.SOCK.STREAM | nonblock |
|
||||
(if (builtin.target.os.tag == .windows) 0 else os.SOCK.CLOEXEC);
|
||||
const sockfd = try os.socket(address.any.family, sock_flags, os.IPPROTO.TCP);
|
||||
errdefer os.closeSocket(sockfd);
|
||||
|
||||
if (std.io.is_async) {
|
||||
@ -724,10 +724,10 @@ pub fn getAddressList(allocator: *mem.Allocator, name: []const u8, port: u16) !*
|
||||
|
||||
const sys = if (builtin.target.os.tag == .windows) os.windows.ws2_32 else os.system;
|
||||
const hints = os.addrinfo{
|
||||
.flags = sys.AI_NUMERICSERV,
|
||||
.family = os.AF_UNSPEC,
|
||||
.socktype = os.SOCK_STREAM,
|
||||
.protocol = os.IPPROTO_TCP,
|
||||
.flags = sys.AI.NUMERICSERV,
|
||||
.family = os.AF.UNSPEC,
|
||||
.socktype = os.SOCK.STREAM,
|
||||
.protocol = os.IPPROTO.TCP,
|
||||
.canonname = null,
|
||||
.addr = null,
|
||||
.addrlen = 0,
|
||||
@ -794,8 +794,8 @@ pub fn getAddressList(allocator: *mem.Allocator, name: []const u8, port: u16) !*
|
||||
return result;
|
||||
}
|
||||
if (builtin.target.os.tag == .linux) {
|
||||
const flags = std.c.AI_NUMERICSERV;
|
||||
const family = os.AF_UNSPEC;
|
||||
const flags = std.c.AI.NUMERICSERV;
|
||||
const family = os.AF.UNSPEC;
|
||||
var lookup_addrs = std.ArrayList(LookupAddr).init(allocator);
|
||||
defer lookup_addrs.deinit();
|
||||
|
||||
@ -846,7 +846,7 @@ fn linuxLookupName(
|
||||
try canon.appendSlice(name);
|
||||
if (Address.parseExpectingFamily(name, family, port)) |addr| {
|
||||
try addrs.append(LookupAddr{ .addr = addr });
|
||||
} else |name_err| if ((flags & std.c.AI_NUMERICHOST) != 0) {
|
||||
} else |name_err| if ((flags & std.c.AI.NUMERICHOST) != 0) {
|
||||
return name_err;
|
||||
} else {
|
||||
try linuxLookupNameFromHosts(addrs, canon, name, family, port);
|
||||
@ -876,9 +876,9 @@ fn linuxLookupName(
|
||||
|
||||
// No further processing is needed if there are fewer than 2
|
||||
// results or if there are only IPv4 results.
|
||||
if (addrs.items.len == 1 or family == os.AF_INET) return;
|
||||
if (addrs.items.len == 1 or family == os.AF.INET) return;
|
||||
const all_ip4 = for (addrs.items) |addr| {
|
||||
if (addr.addr.any.family != os.AF_INET) break false;
|
||||
if (addr.addr.any.family != os.AF.INET) break false;
|
||||
} else true;
|
||||
if (all_ip4) return;
|
||||
|
||||
@ -891,19 +891,19 @@ fn linuxLookupName(
|
||||
// A more idiomatic "ziggy" implementation would be welcome.
|
||||
for (addrs.items) |*addr, i| {
|
||||
var key: i32 = 0;
|
||||
var sa6: os.sockaddr_in6 = undefined;
|
||||
@memset(@ptrCast([*]u8, &sa6), 0, @sizeOf(os.sockaddr_in6));
|
||||
var da6 = os.sockaddr_in6{
|
||||
.family = os.AF_INET6,
|
||||
var sa6: os.sockaddr.in6 = undefined;
|
||||
@memset(@ptrCast([*]u8, &sa6), 0, @sizeOf(os.sockaddr.in6));
|
||||
var da6 = os.sockaddr.in6{
|
||||
.family = os.AF.INET6,
|
||||
.scope_id = addr.addr.in6.sa.scope_id,
|
||||
.port = 65535,
|
||||
.flowinfo = 0,
|
||||
.addr = [1]u8{0} ** 16,
|
||||
};
|
||||
var sa4: os.sockaddr_in = undefined;
|
||||
@memset(@ptrCast([*]u8, &sa4), 0, @sizeOf(os.sockaddr_in));
|
||||
var da4 = os.sockaddr_in{
|
||||
.family = os.AF_INET,
|
||||
var sa4: os.sockaddr.in = undefined;
|
||||
@memset(@ptrCast([*]u8, &sa4), 0, @sizeOf(os.sockaddr.in));
|
||||
var da4 = os.sockaddr.in{
|
||||
.family = os.AF.INET,
|
||||
.port = 65535,
|
||||
.addr = 0,
|
||||
.zero = [1]u8{0} ** 8,
|
||||
@ -912,21 +912,21 @@ fn linuxLookupName(
|
||||
var da: *align(4) os.sockaddr = undefined;
|
||||
var salen: os.socklen_t = undefined;
|
||||
var dalen: os.socklen_t = undefined;
|
||||
if (addr.addr.any.family == os.AF_INET6) {
|
||||
if (addr.addr.any.family == os.AF.INET6) {
|
||||
mem.copy(u8, &da6.addr, &addr.addr.in6.sa.addr);
|
||||
da = @ptrCast(*os.sockaddr, &da6);
|
||||
dalen = @sizeOf(os.sockaddr_in6);
|
||||
dalen = @sizeOf(os.sockaddr.in6);
|
||||
sa = @ptrCast(*os.sockaddr, &sa6);
|
||||
salen = @sizeOf(os.sockaddr_in6);
|
||||
salen = @sizeOf(os.sockaddr.in6);
|
||||
} else {
|
||||
mem.copy(u8, &sa6.addr, "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff");
|
||||
mem.copy(u8, &da6.addr, "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff");
|
||||
mem.writeIntNative(u32, da6.addr[12..], addr.addr.in.sa.addr);
|
||||
da4.addr = addr.addr.in.sa.addr;
|
||||
da = @ptrCast(*os.sockaddr, &da4);
|
||||
dalen = @sizeOf(os.sockaddr_in);
|
||||
dalen = @sizeOf(os.sockaddr.in);
|
||||
sa = @ptrCast(*os.sockaddr, &sa4);
|
||||
salen = @sizeOf(os.sockaddr_in);
|
||||
salen = @sizeOf(os.sockaddr.in);
|
||||
}
|
||||
const dpolicy = policyOf(da6.addr);
|
||||
const dscope: i32 = scopeOf(da6.addr);
|
||||
@ -934,13 +934,13 @@ fn linuxLookupName(
|
||||
const dprec: i32 = dpolicy.prec;
|
||||
const MAXADDRS = 3;
|
||||
var prefixlen: i32 = 0;
|
||||
const sock_flags = os.SOCK_DGRAM | os.SOCK_CLOEXEC;
|
||||
if (os.socket(addr.addr.any.family, sock_flags, os.IPPROTO_UDP)) |fd| syscalls: {
|
||||
const sock_flags = os.SOCK.DGRAM | os.SOCK.CLOEXEC;
|
||||
if (os.socket(addr.addr.any.family, sock_flags, os.IPPROTO.UDP)) |fd| syscalls: {
|
||||
defer os.closeSocket(fd);
|
||||
os.connect(fd, da, dalen) catch break :syscalls;
|
||||
key |= DAS_USABLE;
|
||||
os.getsockname(fd, sa, &salen) catch break :syscalls;
|
||||
if (addr.addr.any.family == os.AF_INET) {
|
||||
if (addr.addr.any.family == os.AF.INET) {
|
||||
// TODO sa6.addr[12..16] should return *[4]u8, making this cast unnecessary.
|
||||
mem.writeIntNative(u32, @ptrCast(*[4]u8, &sa6.addr[12]), sa4.addr);
|
||||
}
|
||||
@ -1082,24 +1082,24 @@ fn linuxLookupNameFromNull(
|
||||
flags: u32,
|
||||
port: u16,
|
||||
) !void {
|
||||
if ((flags & std.c.AI_PASSIVE) != 0) {
|
||||
if (family != os.AF_INET6) {
|
||||
if ((flags & std.c.AI.PASSIVE) != 0) {
|
||||
if (family != os.AF.INET6) {
|
||||
(try addrs.addOne()).* = LookupAddr{
|
||||
.addr = Address.initIp4([1]u8{0} ** 4, port),
|
||||
};
|
||||
}
|
||||
if (family != os.AF_INET) {
|
||||
if (family != os.AF.INET) {
|
||||
(try addrs.addOne()).* = LookupAddr{
|
||||
.addr = Address.initIp6([1]u8{0} ** 16, port, 0, 0),
|
||||
};
|
||||
}
|
||||
} else {
|
||||
if (family != os.AF_INET6) {
|
||||
if (family != os.AF.INET6) {
|
||||
(try addrs.addOne()).* = LookupAddr{
|
||||
.addr = Address.initIp4([4]u8{ 127, 0, 0, 1 }, port),
|
||||
};
|
||||
}
|
||||
if (family != os.AF_INET) {
|
||||
if (family != os.AF.INET) {
|
||||
(try addrs.addOne()).* = LookupAddr{
|
||||
.addr = Address.initIp6(([1]u8{0} ** 15) ++ [1]u8{1}, port, 0, 0),
|
||||
};
|
||||
@ -1252,8 +1252,8 @@ fn linuxLookupNameFromDns(
|
||||
rr: u8,
|
||||
};
|
||||
const afrrs = [_]AfRr{
|
||||
AfRr{ .af = os.AF_INET6, .rr = os.RR_A },
|
||||
AfRr{ .af = os.AF_INET, .rr = os.RR_AAAA },
|
||||
AfRr{ .af = os.AF.INET6, .rr = os.RR.A },
|
||||
AfRr{ .af = os.AF.INET, .rr = os.RR.AAAA },
|
||||
};
|
||||
var qbuf: [2][280]u8 = undefined;
|
||||
var abuf: [2][512]u8 = undefined;
|
||||
@ -1386,8 +1386,8 @@ fn resMSendRc(
|
||||
const timeout = 1000 * rc.timeout;
|
||||
const attempts = rc.attempts;
|
||||
|
||||
var sl: os.socklen_t = @sizeOf(os.sockaddr_in);
|
||||
var family: os.sa_family_t = os.AF_INET;
|
||||
var sl: os.socklen_t = @sizeOf(os.sockaddr.in);
|
||||
var family: os.sa_family_t = os.AF.INET;
|
||||
|
||||
var ns_list = std.ArrayList(Address).init(rc.ns.allocator);
|
||||
defer ns_list.deinit();
|
||||
@ -1398,9 +1398,9 @@ fn resMSendRc(
|
||||
for (rc.ns.items) |iplit, i| {
|
||||
ns[i] = iplit.addr;
|
||||
assert(ns[i].getPort() == 53);
|
||||
if (iplit.addr.any.family != os.AF_INET) {
|
||||
sl = @sizeOf(os.sockaddr_in6);
|
||||
family = os.AF_INET6;
|
||||
if (iplit.addr.any.family != os.AF.INET) {
|
||||
sl = @sizeOf(os.sockaddr.in6);
|
||||
family = os.AF.INET6;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1408,13 +1408,13 @@ fn resMSendRc(
|
||||
var sa: Address = undefined;
|
||||
@memset(@ptrCast([*]u8, &sa), 0, @sizeOf(Address));
|
||||
sa.any.family = family;
|
||||
const flags = os.SOCK_DGRAM | os.SOCK_CLOEXEC | os.SOCK_NONBLOCK;
|
||||
const flags = os.SOCK.DGRAM | os.SOCK.CLOEXEC | os.SOCK.NONBLOCK;
|
||||
const fd = os.socket(family, flags, 0) catch |err| switch (err) {
|
||||
error.AddressFamilyNotSupported => blk: {
|
||||
// Handle case where system lacks IPv6 support
|
||||
if (family == os.AF_INET6) {
|
||||
family = os.AF_INET;
|
||||
break :blk try os.socket(os.AF_INET, flags, 0);
|
||||
if (family == os.AF.INET6) {
|
||||
family = os.AF.INET;
|
||||
break :blk try os.socket(os.AF.INET, flags, 0);
|
||||
}
|
||||
return err;
|
||||
},
|
||||
@ -1429,15 +1429,15 @@ fn resMSendRc(
|
||||
|
||||
// Convert any IPv4 addresses in a mixed environment to v4-mapped
|
||||
// TODO
|
||||
//if (family == AF_INET6) {
|
||||
// setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, &(int){0}, sizeof 0);
|
||||
//if (family == AF.INET6) {
|
||||
// setsockopt(fd, IPPROTO.IPV6, IPV6_V6ONLY, &(int){0}, sizeof 0);
|
||||
// for (i=0; i<nns; i++) {
|
||||
// if (ns[i].sin.sin_family != AF_INET) continue;
|
||||
// if (ns[i].sin.sin_family != AF.INET) continue;
|
||||
// memcpy(ns[i].sin6.sin6_addr.s6_addr+12,
|
||||
// &ns[i].sin.sin_addr, 4);
|
||||
// memcpy(ns[i].sin6.sin6_addr.s6_addr,
|
||||
// "\0\0\0\0\0\0\0\0\0\0\xff\xff", 12);
|
||||
// ns[i].sin6.sin6_family = AF_INET6;
|
||||
// ns[i].sin6.sin6_family = AF.INET6;
|
||||
// ns[i].sin6.sin6_flowinfo = 0;
|
||||
// ns[i].sin6.sin6_scope_id = 0;
|
||||
// }
|
||||
@ -1445,7 +1445,7 @@ fn resMSendRc(
|
||||
|
||||
var pfd = [1]os.pollfd{os.pollfd{
|
||||
.fd = fd,
|
||||
.events = os.POLLIN,
|
||||
.events = os.POLL.IN,
|
||||
.revents = undefined,
|
||||
}};
|
||||
const retry_interval = timeout / attempts;
|
||||
@ -1465,9 +1465,9 @@ fn resMSendRc(
|
||||
var j: usize = 0;
|
||||
while (j < ns.len) : (j += 1) {
|
||||
if (std.io.is_async) {
|
||||
_ = std.event.Loop.instance.?.sendto(fd, queries[i], os.MSG_NOSIGNAL, &ns[j].any, sl) catch undefined;
|
||||
_ = std.event.Loop.instance.?.sendto(fd, queries[i], os.MSG.NOSIGNAL, &ns[j].any, sl) catch undefined;
|
||||
} else {
|
||||
_ = os.sendto(fd, queries[i], os.MSG_NOSIGNAL, &ns[j].any, sl) catch undefined;
|
||||
_ = os.sendto(fd, queries[i], os.MSG.NOSIGNAL, &ns[j].any, sl) catch undefined;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1513,9 +1513,9 @@ fn resMSendRc(
|
||||
2 => if (servfail_retry != 0) {
|
||||
servfail_retry -= 1;
|
||||
if (std.io.is_async) {
|
||||
_ = std.event.Loop.instance.?.sendto(fd, queries[i], os.MSG_NOSIGNAL, &ns[j].any, sl) catch undefined;
|
||||
_ = std.event.Loop.instance.?.sendto(fd, queries[i], os.MSG.NOSIGNAL, &ns[j].any, sl) catch undefined;
|
||||
} else {
|
||||
_ = os.sendto(fd, queries[i], os.MSG_NOSIGNAL, &ns[j].any, sl) catch undefined;
|
||||
_ = os.sendto(fd, queries[i], os.MSG.NOSIGNAL, &ns[j].any, sl) catch undefined;
|
||||
}
|
||||
},
|
||||
else => continue,
|
||||
@ -1570,21 +1570,21 @@ fn dnsParse(
|
||||
|
||||
fn dnsParseCallback(ctx: dpc_ctx, rr: u8, data: []const u8, packet: []const u8) !void {
|
||||
switch (rr) {
|
||||
os.RR_A => {
|
||||
os.RR.A => {
|
||||
if (data.len != 4) return error.InvalidDnsARecord;
|
||||
const new_addr = try ctx.addrs.addOne();
|
||||
new_addr.* = LookupAddr{
|
||||
.addr = Address.initIp4(data[0..4].*, ctx.port),
|
||||
};
|
||||
},
|
||||
os.RR_AAAA => {
|
||||
os.RR.AAAA => {
|
||||
if (data.len != 16) return error.InvalidDnsAAAARecord;
|
||||
const new_addr = try ctx.addrs.addOne();
|
||||
new_addr.* = LookupAddr{
|
||||
.addr = Address.initIp6(data[0..16].*, ctx.port, 0, 0),
|
||||
};
|
||||
},
|
||||
os.RR_CNAME => {
|
||||
os.RR.CNAME => {
|
||||
var tmp: [256]u8 = undefined;
|
||||
// Returns len of compressed name. strlen to get canon name.
|
||||
_ = try os.dn_expand(packet, data, &tmp);
|
||||
@ -1700,7 +1700,7 @@ pub const StreamServer = struct {
|
||||
/// seeing "Connection refused".
|
||||
kernel_backlog: u31 = 128,
|
||||
|
||||
/// Enable SO_REUSEADDR on the socket.
|
||||
/// Enable SO.REUSEADDR on the socket.
|
||||
reuse_address: bool = false,
|
||||
};
|
||||
|
||||
@ -1722,9 +1722,9 @@ pub const StreamServer = struct {
|
||||
}
|
||||
|
||||
pub fn listen(self: *StreamServer, address: Address) !void {
|
||||
const nonblock = if (std.io.is_async) os.SOCK_NONBLOCK else 0;
|
||||
const sock_flags = os.SOCK_STREAM | os.SOCK_CLOEXEC | nonblock;
|
||||
const proto = if (address.any.family == os.AF_UNIX) @as(u32, 0) else os.IPPROTO_TCP;
|
||||
const nonblock = if (std.io.is_async) os.SOCK.NONBLOCK else 0;
|
||||
const sock_flags = os.SOCK.STREAM | os.SOCK.CLOEXEC | nonblock;
|
||||
const proto = if (address.any.family == os.AF.UNIX) @as(u32, 0) else os.IPPROTO.TCP;
|
||||
|
||||
const sockfd = try os.socket(address.any.family, sock_flags, proto);
|
||||
self.sockfd = sockfd;
|
||||
@ -1736,8 +1736,8 @@ pub const StreamServer = struct {
|
||||
if (self.reuse_address) {
|
||||
try os.setsockopt(
|
||||
sockfd,
|
||||
os.SOL_SOCKET,
|
||||
os.SO_REUSEADDR,
|
||||
os.SOL.SOCKET,
|
||||
os.SO.REUSEADDR,
|
||||
&mem.toBytes(@as(c_int, 1)),
|
||||
);
|
||||
}
|
||||
@ -1801,9 +1801,9 @@ pub const StreamServer = struct {
|
||||
const accept_result = blk: {
|
||||
if (std.io.is_async) {
|
||||
const loop = std.event.Loop.instance orelse return error.UnexpectedError;
|
||||
break :blk loop.accept(self.sockfd.?, &accepted_addr.any, &adr_len, os.SOCK_CLOEXEC);
|
||||
break :blk loop.accept(self.sockfd.?, &accepted_addr.any, &adr_len, os.SOCK.CLOEXEC);
|
||||
} else {
|
||||
break :blk os.accept(self.sockfd.?, &accepted_addr.any, &adr_len, os.SOCK_CLOEXEC);
|
||||
break :blk os.accept(self.sockfd.?, &accepted_addr.any, &adr_len, os.SOCK.CLOEXEC);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
158
lib/std/os.zig
158
lib/std/os.zig
@ -62,27 +62,48 @@ else switch (builtin.os.tag) {
|
||||
.uefi => uefi,
|
||||
else => struct {},
|
||||
};
|
||||
|
||||
pub const AF = system.AF;
|
||||
pub const ARCH = system.ARCH;
|
||||
pub const AT = system.AT;
|
||||
pub const CLOCK = system.CLOCK;
|
||||
pub const CPU_COUNT = system.CPU_COUNT;
|
||||
pub const E = system.E;
|
||||
pub const Elf_Symndx = system.Elf_Symndx;
|
||||
pub const F = system.F;
|
||||
pub const FD_CLOEXEC = system.FD_CLOEXEC;
|
||||
pub const F_OK = system.F_OK;
|
||||
pub const Flock = system.Flock;
|
||||
pub const HOST_NAME_MAX = system.HOST_NAME_MAX;
|
||||
pub const IFNAMESIZE = system.IFNAMESIZE;
|
||||
pub const IOV_MAX = system.IOV_MAX;
|
||||
pub const IPPROTO = system.IPPROTO;
|
||||
pub const LOCK = system.LOCK;
|
||||
pub const MADV = system.MADV;
|
||||
pub const MAP = system.MAP;
|
||||
pub const MAX_ADDR_LEN = system.MAX_ADDR_LEN;
|
||||
pub const MMAP2_UNIT = system.MMAP2_UNIT;
|
||||
pub const MSG = system.MSG;
|
||||
pub const NAME_MAX = system.NAME_MAX;
|
||||
pub const O = system.O;
|
||||
pub const PATH_MAX = system.PATH_MAX;
|
||||
pub const POLL = system.POLL;
|
||||
pub const POSIX_FADV = system.POSIX_FADV;
|
||||
pub const PROT = system.PROT;
|
||||
pub const REG = system.REG;
|
||||
pub const RLIM = system.RLIM;
|
||||
pub const RR = system.RR;
|
||||
pub const R_OK = system.R_OK;
|
||||
pub const S = system.S;
|
||||
pub const SA = system.SA;
|
||||
pub const SC = system.SC;
|
||||
pub const SEEK = system.SEEK;
|
||||
pub const SHUT = system.SHUT;
|
||||
pub const SIG = system.SIG;
|
||||
pub const SIOCGIFINDEX = system.SIOCGIFINDEX;
|
||||
pub const SO = system.SO;
|
||||
pub const SOCK = system.SOCK;
|
||||
pub const SOL = system.SOL;
|
||||
pub const STDERR_FILENO = system.STDIN_FILENO;
|
||||
pub const STDIN_FILENO = system.STDIN_FILENO;
|
||||
pub const STDOUT_FILENO = system.STDIN_FILENO;
|
||||
@ -90,27 +111,39 @@ pub const SYS = system.SYS;
|
||||
pub const Sigaction = system.Sigaction;
|
||||
pub const Stat = system.Stat;
|
||||
pub const VDSO = system.VDSO;
|
||||
pub const W = system.W;
|
||||
pub const W_OK = system.W_OK;
|
||||
pub const X_OK = system.X_OK;
|
||||
pub const addrinfo = system.addrinfo;
|
||||
pub const blkcnt_t = system.blkcnt_t;
|
||||
pub const blksize_t = system.blksize_t;
|
||||
pub const clock_t = system.clock_t;
|
||||
pub const cpu_set_t = system.cpu_set_t;
|
||||
pub const dev_t = system.dev_t;
|
||||
pub const dl_phdr_info = system.dl_phdr_info;
|
||||
pub const empty_sigset = system.empty_sigset;
|
||||
pub const fd_t = system.fd_t;
|
||||
pub const gid_t = system.gid_t;
|
||||
pub const ifreq = system.ifreq;
|
||||
pub const ino_t = system.ino_t;
|
||||
pub const mcontext_t = system.mcontext_t;
|
||||
pub const mode_t = system.mode_t;
|
||||
pub const msghdr = system.msghdr;
|
||||
pub const msghdr_const = system.msghdr_const;
|
||||
pub const nfds_t = system.nfds_t;
|
||||
pub const nlink_t = system.nlink_t;
|
||||
pub const off_t = system.off_t;
|
||||
pub const pid_t = system.pid_t;
|
||||
pub const pollfd = system.pollfd;
|
||||
pub const rlim_t = system.rlim_t;
|
||||
pub const rlimit = system.rlimit;
|
||||
pub const rlimit_resource = system.rlimit_resource;
|
||||
pub const sa_family_t = system.sa_family_t;
|
||||
pub const siginfo_t = system.siginfo_t;
|
||||
pub const sigset_t = system.sigset_t;
|
||||
pub const sockaddr = system.sockaddr;
|
||||
pub const socklen_t = system.socklen_t;
|
||||
pub const stack_t = system.stack_t;
|
||||
pub const time_t = system.time_t;
|
||||
pub const timespec = system.timespec;
|
||||
pub const timeval = system.timeval;
|
||||
@ -118,6 +151,7 @@ pub const timezone = system.timezone;
|
||||
pub const ucontext_t = system.ucontext_t;
|
||||
pub const uid_t = system.uid_t;
|
||||
pub const user_desc = system.user_desc;
|
||||
pub const utsname = system.utsname;
|
||||
|
||||
pub const iovec = extern struct {
|
||||
iov_base: [*]u8,
|
||||
@ -251,11 +285,11 @@ pub fn getrandom(buffer: []u8) GetRandomError!void {
|
||||
}
|
||||
|
||||
fn getRandomBytesDevURandom(buf: []u8) !void {
|
||||
const fd = try openZ("/dev/urandom", O_RDONLY | O_CLOEXEC, 0);
|
||||
const fd = try openZ("/dev/urandom", O.RDONLY | O.CLOEXEC, 0);
|
||||
defer close(fd);
|
||||
|
||||
const st = try fstat(fd);
|
||||
if (!S_ISCHR(st.mode)) {
|
||||
if (!S.ISCHR(st.mode)) {
|
||||
return error.NoDevice;
|
||||
}
|
||||
|
||||
@ -1113,18 +1147,18 @@ pub const OpenError = error{
|
||||
/// for 64-bit targets, as well as when opening directories.
|
||||
FileTooBig,
|
||||
|
||||
/// The path refers to directory but the `O_DIRECTORY` flag was not provided.
|
||||
/// The path refers to directory but the `O.DIRECTORY` flag was not provided.
|
||||
IsDir,
|
||||
|
||||
/// A new path cannot be created because the device has no room for the new file.
|
||||
/// This error is only reachable when the `O_CREAT` flag is provided.
|
||||
/// This error is only reachable when the `O.CREAT` flag is provided.
|
||||
NoSpaceLeft,
|
||||
|
||||
/// A component used as a directory in the path was not, in fact, a directory, or
|
||||
/// `O_DIRECTORY` was specified and the path was not a directory.
|
||||
/// `O.DIRECTORY` was specified and the path was not a directory.
|
||||
NotDir,
|
||||
|
||||
/// The path already exists and the `O_CREAT` and `O_EXCL` flags were provided.
|
||||
/// The path already exists and the `O.CREAT` and `O.EXCL` flags were provided.
|
||||
PathAlreadyExists,
|
||||
DeviceBusy,
|
||||
|
||||
@ -1196,20 +1230,20 @@ fn openOptionsFromFlags(flags: u32) windows.OpenFileOptions {
|
||||
const w = windows;
|
||||
|
||||
var access_mask: w.ULONG = w.READ_CONTROL | w.FILE_WRITE_ATTRIBUTES | w.SYNCHRONIZE;
|
||||
if (flags & O_RDWR != 0) {
|
||||
if (flags & O.RDWR != 0) {
|
||||
access_mask |= w.GENERIC_READ | w.GENERIC_WRITE;
|
||||
} else if (flags & O_WRONLY != 0) {
|
||||
} else if (flags & O.WRONLY != 0) {
|
||||
access_mask |= w.GENERIC_WRITE;
|
||||
} else {
|
||||
access_mask |= w.GENERIC_READ | w.GENERIC_WRITE;
|
||||
}
|
||||
|
||||
const open_dir: bool = flags & O_DIRECTORY != 0;
|
||||
const follow_symlinks: bool = flags & O_NOFOLLOW == 0;
|
||||
const open_dir: bool = flags & O.DIRECTORY != 0;
|
||||
const follow_symlinks: bool = flags & O.NOFOLLOW == 0;
|
||||
|
||||
const creation: w.ULONG = blk: {
|
||||
if (flags & O_CREAT != 0) {
|
||||
if (flags & O_EXCL != 0) {
|
||||
if (flags & O.CREAT != 0) {
|
||||
if (flags & O.EXCL != 0) {
|
||||
break :blk w.FILE_CREATE;
|
||||
}
|
||||
}
|
||||
@ -2812,10 +2846,10 @@ pub const SocketError = error{
|
||||
|
||||
pub fn socket(domain: u32, socket_type: u32, protocol: u32) SocketError!socket_t {
|
||||
if (builtin.os.tag == .windows) {
|
||||
// NOTE: windows translates the SOCK_NONBLOCK/SOCK_CLOEXEC flags into
|
||||
// NOTE: windows translates the SOCK.NONBLOCK/SOCK.CLOEXEC flags into
|
||||
// windows-analagous operations
|
||||
const filtered_sock_type = socket_type & ~@as(u32, SOCK_NONBLOCK | SOCK_CLOEXEC);
|
||||
const flags: u32 = if ((socket_type & SOCK_CLOEXEC) != 0)
|
||||
const filtered_sock_type = socket_type & ~@as(u32, SOCK.NONBLOCK | SOCK.CLOEXEC);
|
||||
const flags: u32 = if ((socket_type & SOCK.CLOEXEC) != 0)
|
||||
windows.ws2_32.WSA_FLAG_NO_HANDLE_INHERIT
|
||||
else
|
||||
0;
|
||||
@ -2828,7 +2862,7 @@ pub fn socket(domain: u32, socket_type: u32, protocol: u32) SocketError!socket_t
|
||||
flags,
|
||||
);
|
||||
errdefer windows.closesocket(rc) catch unreachable;
|
||||
if ((socket_type & SOCK_NONBLOCK) != 0) {
|
||||
if ((socket_type & SOCK.NONBLOCK) != 0) {
|
||||
var mode: c_ulong = 1; // nonblocking
|
||||
if (windows.ws2_32.SOCKET_ERROR == windows.ws2_32.ioctlsocket(rc, windows.ws2_32.FIONBIO, &mode)) {
|
||||
switch (windows.ws2_32.WSAGetLastError()) {
|
||||
@ -2842,7 +2876,7 @@ pub fn socket(domain: u32, socket_type: u32, protocol: u32) SocketError!socket_t
|
||||
|
||||
const have_sock_flags = comptime !std.Target.current.isDarwin();
|
||||
const filtered_sock_type = if (!have_sock_flags)
|
||||
socket_type & ~@as(u32, SOCK_NONBLOCK | SOCK_CLOEXEC)
|
||||
socket_type & ~@as(u32, SOCK.NONBLOCK | SOCK.CLOEXEC)
|
||||
else
|
||||
socket_type;
|
||||
const rc = system.socket(domain, filtered_sock_type, protocol);
|
||||
@ -2905,9 +2939,9 @@ pub fn shutdown(sock: socket_t, how: ShutdownHow) ShutdownError!void {
|
||||
};
|
||||
} else {
|
||||
const rc = system.shutdown(sock, switch (how) {
|
||||
.recv => SHUT_RD,
|
||||
.send => SHUT_WR,
|
||||
.both => SHUT_RDWR,
|
||||
.recv => SHUT.RD,
|
||||
.send => SHUT.WR,
|
||||
.both => SHUT.RDWR,
|
||||
});
|
||||
switch (errno(rc)) {
|
||||
.SUCCESS => return,
|
||||
@ -3132,15 +3166,15 @@ pub fn accept(
|
||||
/// will return a value greater than was supplied to the call.
|
||||
addr_size: ?*socklen_t,
|
||||
/// The following values can be bitwise ORed in flags to obtain different behavior:
|
||||
/// * `SOCK_NONBLOCK` - Set the `O_NONBLOCK` file status flag on the open file description (see `open`)
|
||||
/// * `SOCK.NONBLOCK` - Set the `O.NONBLOCK` file status flag on the open file description (see `open`)
|
||||
/// referred to by the new file descriptor. Using this flag saves extra calls to `fcntl` to achieve
|
||||
/// the same result.
|
||||
/// * `SOCK_CLOEXEC` - Set the close-on-exec (`FD_CLOEXEC`) flag on the new file descriptor. See the
|
||||
/// description of the `O_CLOEXEC` flag in `open` for reasons why this may be useful.
|
||||
/// * `SOCK.CLOEXEC` - Set the close-on-exec (`FD_CLOEXEC`) flag on the new file descriptor. See the
|
||||
/// description of the `O.CLOEXEC` flag in `open` for reasons why this may be useful.
|
||||
flags: u32,
|
||||
) AcceptError!socket_t {
|
||||
const have_accept4 = comptime !(std.Target.current.isDarwin() or builtin.os.tag == .windows);
|
||||
assert(0 == (flags & ~@as(u32, SOCK_NONBLOCK | SOCK_CLOEXEC))); // Unsupported flag(s)
|
||||
assert(0 == (flags & ~@as(u32, SOCK.NONBLOCK | SOCK.CLOEXEC))); // Unsupported flag(s)
|
||||
|
||||
const accepted_sock = while (true) {
|
||||
const rc = if (have_accept4)
|
||||
@ -3250,7 +3284,7 @@ pub const EpollCtlError = error{
|
||||
FileDescriptorIncompatibleWithEpoll,
|
||||
} || UnexpectedError;
|
||||
|
||||
pub fn epoll_ctl(epfd: i32, op: u32, fd: i32, event: ?*epoll_event) EpollCtlError!void {
|
||||
pub fn epoll_ctl(epfd: i32, op: u32, fd: i32, event: ?*linux.epoll_event) EpollCtlError!void {
|
||||
const rc = system.epoll_ctl(epfd, op, fd, event);
|
||||
switch (errno(rc)) {
|
||||
.SUCCESS => return,
|
||||
@ -3270,7 +3304,7 @@ pub fn epoll_ctl(epfd: i32, op: u32, fd: i32, event: ?*epoll_event) EpollCtlErro
|
||||
/// Waits for an I/O event on an epoll file descriptor.
|
||||
/// Returns the number of file descriptors ready for the requested I/O,
|
||||
/// or zero if no file descriptor became ready during the requested timeout milliseconds.
|
||||
pub fn epoll_wait(epfd: i32, events: []epoll_event, timeout: i32) usize {
|
||||
pub fn epoll_wait(epfd: i32, events: []linux.epoll_event, timeout: i32) usize {
|
||||
while (true) {
|
||||
// TODO get rid of the @intCast
|
||||
const rc = system.epoll_wait(epfd, events.ptr, @intCast(u32, events.len), timeout);
|
||||
@ -3472,7 +3506,7 @@ pub fn connect(sock: socket_t, sock_addr: *const sockaddr, len: socklen_t) Conne
|
||||
.NOTSOCK => unreachable, // The file descriptor sockfd does not refer to a socket.
|
||||
.PROTOTYPE => unreachable, // The socket type does not support the requested communications protocol.
|
||||
.TIMEDOUT => return error.ConnectionTimedOut,
|
||||
.NOENT => return error.FileNotFound, // Returned when socket is AF_UNIX and the given path does not exist.
|
||||
.NOENT => return error.FileNotFound, // Returned when socket is AF.UNIX and the given path does not exist.
|
||||
else => |err| return unexpectedErrno(err),
|
||||
}
|
||||
}
|
||||
@ -3481,7 +3515,7 @@ pub fn connect(sock: socket_t, sock_addr: *const sockaddr, len: socklen_t) Conne
|
||||
pub fn getsockoptError(sockfd: fd_t) ConnectError!void {
|
||||
var err_code: i32 = undefined;
|
||||
var size: u32 = @sizeOf(u32);
|
||||
const rc = system.getsockopt(sockfd, SOL_SOCKET, SO_ERROR, @ptrCast([*]u8, &err_code), &size);
|
||||
const rc = system.getsockopt(sockfd, SOL.SOCKET, SO.ERROR, @ptrCast([*]u8, &err_code), &size);
|
||||
assert(size == 4);
|
||||
switch (errno(rc)) {
|
||||
.SUCCESS => switch (@intToEnum(E, err_code)) {
|
||||
@ -3813,8 +3847,8 @@ pub const MMapError = error{
|
||||
MemoryMappingNotSupported,
|
||||
|
||||
/// A file descriptor refers to a non-regular file. Or a file mapping was requested,
|
||||
/// but the file descriptor is not open for reading. Or `MAP_SHARED` was requested
|
||||
/// and `PROT_WRITE` is set, but the file descriptor is not open in `O_RDWR` mode.
|
||||
/// but the file descriptor is not open for reading. Or `MAP.SHARED` was requested
|
||||
/// and `PROT_WRITE` is set, but the file descriptor is not open in `O.RDWR` mode.
|
||||
/// Or `PROT_WRITE` is set, but the file is append-only.
|
||||
AccessDenied,
|
||||
|
||||
@ -3846,7 +3880,7 @@ pub fn mmap(
|
||||
const ioffset = @bitCast(i64, offset); // the OS treats this as unsigned
|
||||
const rc = mmap_sym(ptr, length, prot, flags, fd, ioffset);
|
||||
const err = if (builtin.link_libc) blk: {
|
||||
if (rc != std.c.MAP_FAILED) return @ptrCast([*]align(mem.page_size) u8, @alignCast(mem.page_size, rc))[0..length];
|
||||
if (rc != std.c.MAP.FAILED) return @ptrCast([*]align(mem.page_size) u8, @alignCast(mem.page_size, rc))[0..length];
|
||||
break :blk @intToEnum(E, system._errno().*);
|
||||
} else blk: {
|
||||
const err = errno(rc);
|
||||
@ -4069,9 +4103,9 @@ pub fn pipe2(flags: u32) PipeError![2]fd_t {
|
||||
if (flags == 0)
|
||||
return fds;
|
||||
|
||||
// O_CLOEXEC is special, it's a file descriptor flag and must be set using
|
||||
// O.CLOEXEC is special, it's a file descriptor flag and must be set using
|
||||
// F_SETFD.
|
||||
if (flags & O_CLOEXEC != 0) {
|
||||
if (flags & O.CLOEXEC != 0) {
|
||||
for (fds) |fd| {
|
||||
switch (errno(system.fcntl(fd, F_SETFD, @as(u32, FD_CLOEXEC)))) {
|
||||
.SUCCESS => {},
|
||||
@ -4082,7 +4116,7 @@ pub fn pipe2(flags: u32) PipeError![2]fd_t {
|
||||
}
|
||||
}
|
||||
|
||||
const new_flags = flags & ~@as(u32, O_CLOEXEC);
|
||||
const new_flags = flags & ~@as(u32, O.CLOEXEC);
|
||||
// Set every other flag affecting the file status using F_SETFL.
|
||||
if (new_flags != 0) {
|
||||
for (fds) |fd| {
|
||||
@ -4176,7 +4210,7 @@ pub const SeekError = error{
|
||||
pub fn lseek_SET(fd: fd_t, offset: u64) SeekError!void {
|
||||
if (builtin.os.tag == .linux and !builtin.link_libc and @sizeOf(usize) == 4) {
|
||||
var result: u64 = undefined;
|
||||
switch (errno(system.llseek(fd, offset, &result, SEEK_SET))) {
|
||||
switch (errno(system.llseek(fd, offset, &result, SEEK.SET))) {
|
||||
.SUCCESS => return,
|
||||
.BADF => unreachable, // always a race condition
|
||||
.INVAL => return error.Unseekable,
|
||||
@ -4209,7 +4243,7 @@ pub fn lseek_SET(fd: fd_t, offset: u64) SeekError!void {
|
||||
system.lseek;
|
||||
|
||||
const ioffset = @bitCast(i64, offset); // the OS treats this as unsigned
|
||||
switch (errno(lseek_sym(fd, ioffset, SEEK_SET))) {
|
||||
switch (errno(lseek_sym(fd, ioffset, SEEK.SET))) {
|
||||
.SUCCESS => return,
|
||||
.BADF => unreachable, // always a race condition
|
||||
.INVAL => return error.Unseekable,
|
||||
@ -4224,7 +4258,7 @@ pub fn lseek_SET(fd: fd_t, offset: u64) SeekError!void {
|
||||
pub fn lseek_CUR(fd: fd_t, offset: i64) SeekError!void {
|
||||
if (builtin.os.tag == .linux and !builtin.link_libc and @sizeOf(usize) == 4) {
|
||||
var result: u64 = undefined;
|
||||
switch (errno(system.llseek(fd, @bitCast(u64, offset), &result, SEEK_CUR))) {
|
||||
switch (errno(system.llseek(fd, @bitCast(u64, offset), &result, SEEK.CUR))) {
|
||||
.SUCCESS => return,
|
||||
.BADF => unreachable, // always a race condition
|
||||
.INVAL => return error.Unseekable,
|
||||
@ -4256,7 +4290,7 @@ pub fn lseek_CUR(fd: fd_t, offset: i64) SeekError!void {
|
||||
system.lseek;
|
||||
|
||||
const ioffset = @bitCast(i64, offset); // the OS treats this as unsigned
|
||||
switch (errno(lseek_sym(fd, ioffset, SEEK_CUR))) {
|
||||
switch (errno(lseek_sym(fd, ioffset, SEEK.CUR))) {
|
||||
.SUCCESS => return,
|
||||
.BADF => unreachable, // always a race condition
|
||||
.INVAL => return error.Unseekable,
|
||||
@ -4271,7 +4305,7 @@ pub fn lseek_CUR(fd: fd_t, offset: i64) SeekError!void {
|
||||
pub fn lseek_END(fd: fd_t, offset: i64) SeekError!void {
|
||||
if (builtin.os.tag == .linux and !builtin.link_libc and @sizeOf(usize) == 4) {
|
||||
var result: u64 = undefined;
|
||||
switch (errno(system.llseek(fd, @bitCast(u64, offset), &result, SEEK_END))) {
|
||||
switch (errno(system.llseek(fd, @bitCast(u64, offset), &result, SEEK.END))) {
|
||||
.SUCCESS => return,
|
||||
.BADF => unreachable, // always a race condition
|
||||
.INVAL => return error.Unseekable,
|
||||
@ -4303,7 +4337,7 @@ pub fn lseek_END(fd: fd_t, offset: i64) SeekError!void {
|
||||
system.lseek;
|
||||
|
||||
const ioffset = @bitCast(i64, offset); // the OS treats this as unsigned
|
||||
switch (errno(lseek_sym(fd, ioffset, SEEK_END))) {
|
||||
switch (errno(lseek_sym(fd, ioffset, SEEK.END))) {
|
||||
.SUCCESS => return,
|
||||
.BADF => unreachable, // always a race condition
|
||||
.INVAL => return error.Unseekable,
|
||||
@ -4318,7 +4352,7 @@ pub fn lseek_END(fd: fd_t, offset: i64) SeekError!void {
|
||||
pub fn lseek_CUR_get(fd: fd_t) SeekError!u64 {
|
||||
if (builtin.os.tag == .linux and !builtin.link_libc and @sizeOf(usize) == 4) {
|
||||
var result: u64 = undefined;
|
||||
switch (errno(system.llseek(fd, 0, &result, SEEK_CUR))) {
|
||||
switch (errno(system.llseek(fd, 0, &result, SEEK.CUR))) {
|
||||
.SUCCESS => return result,
|
||||
.BADF => unreachable, // always a race condition
|
||||
.INVAL => return error.Unseekable,
|
||||
@ -4349,7 +4383,7 @@ pub fn lseek_CUR_get(fd: fd_t) SeekError!u64 {
|
||||
else
|
||||
system.lseek;
|
||||
|
||||
const rc = lseek_sym(fd, 0, SEEK_CUR);
|
||||
const rc = lseek_sym(fd, 0, SEEK.CUR);
|
||||
switch (errno(rc)) {
|
||||
.SUCCESS => return @bitCast(u64, rc),
|
||||
.BADF => unreachable, // always a race condition
|
||||
@ -4387,7 +4421,7 @@ pub fn fcntl(fd: fd_t, cmd: i32, arg: usize) FcntlError!usize {
|
||||
}
|
||||
|
||||
fn setSockFlags(sock: socket_t, flags: u32) !void {
|
||||
if ((flags & SOCK_CLOEXEC) != 0) {
|
||||
if ((flags & SOCK.CLOEXEC) != 0) {
|
||||
if (builtin.os.tag == .windows) {
|
||||
// TODO: Find out if this is supported for sockets
|
||||
} else {
|
||||
@ -4406,7 +4440,7 @@ fn setSockFlags(sock: socket_t, flags: u32) !void {
|
||||
};
|
||||
}
|
||||
}
|
||||
if ((flags & SOCK_NONBLOCK) != 0) {
|
||||
if ((flags & SOCK.NONBLOCK) != 0) {
|
||||
if (builtin.os.tag == .windows) {
|
||||
var mode: c_ulong = 1;
|
||||
if (windows.ws2_32.ioctlsocket(sock, windows.ws2_32.FIONBIO, &mode) == windows.ws2_32.SOCKET_ERROR) {
|
||||
@ -4425,7 +4459,7 @@ fn setSockFlags(sock: socket_t, flags: u32) !void {
|
||||
error.PermissionDenied => unreachable,
|
||||
else => |e| return e,
|
||||
};
|
||||
fl_flags |= O_NONBLOCK;
|
||||
fl_flags |= O.NONBLOCK;
|
||||
_ = fcntl(sock, F_SETFL, fl_flags) catch |err| switch (err) {
|
||||
error.FileBusy => unreachable,
|
||||
error.Locked => unreachable,
|
||||
@ -4512,7 +4546,7 @@ pub fn realpathZ(pathname: [*:0]const u8, out_buffer: *[MAX_PATH_BYTES]u8) RealP
|
||||
return realpathW(pathname_w.span(), out_buffer);
|
||||
}
|
||||
if (!builtin.link_libc) {
|
||||
const flags = if (builtin.os.tag == .linux) O_PATH | O_NONBLOCK | O_CLOEXEC else O_NONBLOCK | O_CLOEXEC;
|
||||
const flags = if (builtin.os.tag == .linux) O.PATH | O.NONBLOCK | O.CLOEXEC else O.NONBLOCK | O.CLOEXEC;
|
||||
const fd = openZ(pathname, flags, 0) catch |err| switch (err) {
|
||||
error.FileLocksNotSupported => unreachable,
|
||||
error.WouldBlock => unreachable,
|
||||
@ -5043,7 +5077,7 @@ pub const SendError = error{
|
||||
SystemResources,
|
||||
|
||||
/// The local end has been shut down on a connection oriented socket. In this case, the
|
||||
/// process will also receive a SIGPIPE unless MSG_NOSIGNAL is set.
|
||||
/// process will also receive a SIGPIPE unless MSG.NOSIGNAL is set.
|
||||
BrokenPipe,
|
||||
|
||||
FileDescriptorNotASocket,
|
||||
@ -5059,13 +5093,13 @@ pub const SendMsgError = SendError || error{
|
||||
/// The passed address didn't have the correct address family in its sa_family field.
|
||||
AddressFamilyNotSupported,
|
||||
|
||||
/// Returned when socket is AF_UNIX and the given path has a symlink loop.
|
||||
/// Returned when socket is AF.UNIX and the given path has a symlink loop.
|
||||
SymLinkLoop,
|
||||
|
||||
/// Returned when socket is AF_UNIX and the given path length exceeds `MAX_PATH_BYTES` bytes.
|
||||
/// Returned when socket is AF.UNIX and the given path length exceeds `MAX_PATH_BYTES` bytes.
|
||||
NameTooLong,
|
||||
|
||||
/// Returned when socket is AF_UNIX and the given path does not point to an existing file.
|
||||
/// Returned when socket is AF.UNIX and the given path does not point to an existing file.
|
||||
FileNotFound,
|
||||
NotDir,
|
||||
|
||||
@ -5158,7 +5192,7 @@ pub const SendToError = SendMsgError;
|
||||
///
|
||||
/// sendto(sockfd, buf, len, flags, NULL, 0);
|
||||
///
|
||||
/// If sendto() is used on a connection-mode (`SOCK_STREAM`, `SOCK_SEQPACKET`) socket, the arguments
|
||||
/// If sendto() is used on a connection-mode (`SOCK.STREAM`, `SOCK.SEQPACKET`) socket, the arguments
|
||||
/// `dest_addr` and `addrlen` are asserted to be `null` and `0` respectively, and asserted
|
||||
/// that the socket was actually connected.
|
||||
/// Otherwise, the address of the target is given by `dest_addr` with `addrlen` specifying its size.
|
||||
@ -5398,7 +5432,7 @@ pub fn sendfile(
|
||||
// * Descriptor is not valid or locked
|
||||
// * an mmap(2)-like operation is not available for in_fd
|
||||
// * count is negative
|
||||
// * out_fd has the O_APPEND flag set
|
||||
// * out_fd has the O.APPEND flag set
|
||||
// Because of the "mmap(2)-like operation" possibility, we fall back to doing read/write
|
||||
// manually, the same as ENOSYS.
|
||||
break :sf;
|
||||
@ -5464,7 +5498,7 @@ pub fn sendfile(
|
||||
.INVAL, .OPNOTSUPP, .NOTSOCK, .NOSYS => {
|
||||
// EINVAL could be any of the following situations:
|
||||
// * The fd argument is not a regular file.
|
||||
// * The s argument is not a SOCK_STREAM type socket.
|
||||
// * The s argument is not a SOCK.STREAM type socket.
|
||||
// * The offset argument is negative.
|
||||
// Because of some of these possibilities, we fall back to doing read/write
|
||||
// manually, the same as ENOSYS.
|
||||
@ -5606,7 +5640,7 @@ pub const CopyFileRangeError = error{
|
||||
FileTooBig,
|
||||
InputOutput,
|
||||
/// `fd_in` is not open for reading; or `fd_out` is not open for writing;
|
||||
/// or the `O_APPEND` flag is set for `fd_out`.
|
||||
/// or the `O.APPEND` flag is set for `fd_out`.
|
||||
FilesOpenedWithWrongFlags,
|
||||
IsDir,
|
||||
OutOfMemory,
|
||||
@ -6222,27 +6256,27 @@ pub fn setrlimit(resource: rlimit_resource, limits: rlimit) SetrlimitError!void
|
||||
}
|
||||
|
||||
pub const MadviseError = error{
|
||||
/// advice is MADV_REMOVE, but the specified address range is not a shared writable mapping.
|
||||
/// advice is MADV.REMOVE, but the specified address range is not a shared writable mapping.
|
||||
AccessDenied,
|
||||
/// advice is MADV_HWPOISON, but the caller does not have the CAP_SYS_ADMIN capability.
|
||||
/// advice is MADV.HWPOISON, but the caller does not have the CAP_SYS_ADMIN capability.
|
||||
PermissionDenied,
|
||||
/// A kernel resource was temporarily unavailable.
|
||||
SystemResources,
|
||||
/// One of the following:
|
||||
/// * addr is not page-aligned or length is negative
|
||||
/// * advice is not valid
|
||||
/// * advice is MADV_DONTNEED or MADV_REMOVE and the specified address range
|
||||
/// * advice is MADV.DONTNEED or MADV.REMOVE and the specified address range
|
||||
/// includes locked, Huge TLB pages, or VM_PFNMAP pages.
|
||||
/// * advice is MADV_MERGEABLE or MADV_UNMERGEABLE, but the kernel was not
|
||||
/// * advice is MADV.MERGEABLE or MADV.UNMERGEABLE, but the kernel was not
|
||||
/// configured with CONFIG_KSM.
|
||||
/// * advice is MADV_FREE or MADV_WIPEONFORK but the specified address range
|
||||
/// includes file, Huge TLB, MAP_SHARED, or VM_PFNMAP ranges.
|
||||
/// * advice is MADV.FREE or MADV.WIPEONFORK but the specified address range
|
||||
/// includes file, Huge TLB, MAP.SHARED, or VM_PFNMAP ranges.
|
||||
InvalidSyscall,
|
||||
/// (for MADV_WILLNEED) Paging in this area would exceed the process's
|
||||
/// (for MADV.WILLNEED) Paging in this area would exceed the process's
|
||||
/// maximum resident set size.
|
||||
WouldExceedMaximumResidentSetSize,
|
||||
/// One of the following:
|
||||
/// * (for MADV_WILLNEED) Not enough memory: paging in failed.
|
||||
/// * (for MADV.WILLNEED) Not enough memory: paging in failed.
|
||||
/// * Addresses in the specified range are not currently mapped, or
|
||||
/// are outside the address space of the process.
|
||||
OutOfMemory,
|
||||
|
||||
@ -17,6 +17,8 @@ const is_mips = native_arch.isMIPS();
|
||||
const is_ppc = native_arch.isPPC();
|
||||
const is_ppc64 = native_arch.isPPC64();
|
||||
const is_sparc = native_arch.isSPARC();
|
||||
const iovec = std.os.iovec;
|
||||
const iovec_const = std.os.iovec_const;
|
||||
|
||||
test {
|
||||
if (std.Target.current.os.tag == .linux) {
|
||||
@ -306,7 +308,7 @@ pub fn readlink(noalias path: [*:0]const u8, noalias buf_ptr: [*]u8, buf_len: us
|
||||
if (@hasField(SYS, "readlink")) {
|
||||
return syscall3(.readlink, @ptrToInt(path), @ptrToInt(buf_ptr), buf_len);
|
||||
} else {
|
||||
return syscall4(.readlinkat, @bitCast(usize, @as(isize, AT_FDCWD)), @ptrToInt(path), @ptrToInt(buf_ptr), buf_len);
|
||||
return syscall4(.readlinkat, @bitCast(usize, @as(isize, AT.FDCWD)), @ptrToInt(path), @ptrToInt(buf_ptr), buf_len);
|
||||
}
|
||||
}
|
||||
|
||||
@ -318,7 +320,7 @@ pub fn mkdir(path: [*:0]const u8, mode: u32) usize {
|
||||
if (@hasField(SYS, "mkdir")) {
|
||||
return syscall2(.mkdir, @ptrToInt(path), mode);
|
||||
} else {
|
||||
return syscall3(.mkdirat, @bitCast(usize, @as(isize, AT_FDCWD)), @ptrToInt(path), mode);
|
||||
return syscall3(.mkdirat, @bitCast(usize, @as(isize, AT.FDCWD)), @ptrToInt(path), mode);
|
||||
}
|
||||
}
|
||||
|
||||
@ -330,7 +332,7 @@ pub fn mknod(path: [*:0]const u8, mode: u32, dev: u32) usize {
|
||||
if (@hasField(SYS, "mknod")) {
|
||||
return syscall3(.mknod, @ptrToInt(path), mode, dev);
|
||||
} else {
|
||||
return mknodat(AT_FDCWD, path, mode, dev);
|
||||
return mknodat(AT.FDCWD, path, mode, dev);
|
||||
}
|
||||
}
|
||||
|
||||
@ -477,7 +479,7 @@ pub fn rmdir(path: [*:0]const u8) usize {
|
||||
if (@hasField(SYS, "rmdir")) {
|
||||
return syscall1(.rmdir, @ptrToInt(path));
|
||||
} else {
|
||||
return syscall3(.unlinkat, @bitCast(usize, @as(isize, AT_FDCWD)), @ptrToInt(path), AT_REMOVEDIR);
|
||||
return syscall3(.unlinkat, @bitCast(usize, @as(isize, AT.FDCWD)), @ptrToInt(path), AT.REMOVEDIR);
|
||||
}
|
||||
}
|
||||
|
||||
@ -485,7 +487,7 @@ pub fn symlink(existing: [*:0]const u8, new: [*:0]const u8) usize {
|
||||
if (@hasField(SYS, "symlink")) {
|
||||
return syscall2(.symlink, @ptrToInt(existing), @ptrToInt(new));
|
||||
} else {
|
||||
return syscall3(.symlinkat, @ptrToInt(existing), @bitCast(usize, @as(isize, AT_FDCWD)), @ptrToInt(new));
|
||||
return syscall3(.symlinkat, @ptrToInt(existing), @bitCast(usize, @as(isize, AT.FDCWD)), @ptrToInt(new));
|
||||
}
|
||||
}
|
||||
|
||||
@ -518,9 +520,12 @@ pub fn pread(fd: i32, buf: [*]u8, count: usize, offset: i64) usize {
|
||||
}
|
||||
} else {
|
||||
// Some architectures (eg. 64bit SPARC) pread is called pread64.
|
||||
const S = if (!@hasField(SYS, "pread") and @hasField(SYS, "pread64")) .pread64 else .pread;
|
||||
const syscall_number = if (!@hasField(SYS, "pread") and @hasField(SYS, "pread64"))
|
||||
.pread64
|
||||
else
|
||||
.pread;
|
||||
return syscall4(
|
||||
S,
|
||||
syscall_number,
|
||||
@bitCast(usize, @as(isize, fd)),
|
||||
@ptrToInt(buf),
|
||||
count,
|
||||
@ -533,7 +538,7 @@ pub fn access(path: [*:0]const u8, mode: u32) usize {
|
||||
if (@hasField(SYS, "access")) {
|
||||
return syscall2(.access, @ptrToInt(path), mode);
|
||||
} else {
|
||||
return syscall4(.faccessat, @bitCast(usize, @as(isize, AT_FDCWD)), @ptrToInt(path), mode, 0);
|
||||
return syscall4(.faccessat, @bitCast(usize, @as(isize, AT.FDCWD)), @ptrToInt(path), mode, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@ -613,9 +618,12 @@ pub fn pwrite(fd: i32, buf: [*]const u8, count: usize, offset: i64) usize {
|
||||
}
|
||||
} else {
|
||||
// Some architectures (eg. 64bit SPARC) pwrite is called pwrite64.
|
||||
const S = if (!@hasField(SYS, "pwrite") and @hasField(SYS, "pwrite64")) .pwrite64 else .pwrite;
|
||||
const syscall_number = if (!@hasField(SYS, "pwrite") and @hasField(SYS, "pwrite64"))
|
||||
.pwrite64
|
||||
else
|
||||
.pwrite;
|
||||
return syscall4(
|
||||
S,
|
||||
syscall_number,
|
||||
@bitCast(usize, @as(isize, fd)),
|
||||
@ptrToInt(buf),
|
||||
count,
|
||||
@ -628,9 +636,9 @@ pub fn rename(old: [*:0]const u8, new: [*:0]const u8) usize {
|
||||
if (@hasField(SYS, "rename")) {
|
||||
return syscall2(.rename, @ptrToInt(old), @ptrToInt(new));
|
||||
} else if (@hasField(SYS, "renameat")) {
|
||||
return syscall4(.renameat, @bitCast(usize, @as(isize, AT_FDCWD)), @ptrToInt(old), @bitCast(usize, @as(isize, AT_FDCWD)), @ptrToInt(new));
|
||||
return syscall4(.renameat, @bitCast(usize, @as(isize, AT.FDCWD)), @ptrToInt(old), @bitCast(usize, @as(isize, AT.FDCWD)), @ptrToInt(new));
|
||||
} else {
|
||||
return syscall5(.renameat2, @bitCast(usize, @as(isize, AT_FDCWD)), @ptrToInt(old), @bitCast(usize, @as(isize, AT_FDCWD)), @ptrToInt(new), 0);
|
||||
return syscall5(.renameat2, @bitCast(usize, @as(isize, AT.FDCWD)), @ptrToInt(old), @bitCast(usize, @as(isize, AT.FDCWD)), @ptrToInt(new), 0);
|
||||
}
|
||||
}
|
||||
|
||||
@ -672,7 +680,7 @@ pub fn open(path: [*:0]const u8, flags: u32, perm: mode_t) usize {
|
||||
} else {
|
||||
return syscall4(
|
||||
.openat,
|
||||
@bitCast(usize, @as(isize, AT_FDCWD)),
|
||||
@bitCast(usize, @as(isize, AT.FDCWD)),
|
||||
@ptrToInt(path),
|
||||
flags,
|
||||
perm,
|
||||
@ -685,7 +693,7 @@ pub fn create(path: [*:0]const u8, perm: mode_t) usize {
|
||||
}
|
||||
|
||||
pub fn openat(dirfd: i32, path: [*:0]const u8, flags: u32, mode: mode_t) usize {
|
||||
// dirfd could be negative, for example AT_FDCWD is -100
|
||||
// dirfd could be negative, for example AT.FDCWD is -100
|
||||
return syscall4(.openat, @bitCast(usize, @as(isize, dirfd)), @ptrToInt(path), flags, mode);
|
||||
}
|
||||
|
||||
@ -759,9 +767,9 @@ pub fn link(oldpath: [*:0]const u8, newpath: [*:0]const u8, flags: i32) usize {
|
||||
} else {
|
||||
return syscall5(
|
||||
.linkat,
|
||||
@bitCast(usize, @as(isize, AT_FDCWD)),
|
||||
@bitCast(usize, @as(isize, AT.FDCWD)),
|
||||
@ptrToInt(oldpath),
|
||||
@bitCast(usize, @as(isize, AT_FDCWD)),
|
||||
@bitCast(usize, @as(isize, AT.FDCWD)),
|
||||
@ptrToInt(newpath),
|
||||
@bitCast(usize, @as(isize, flags)),
|
||||
);
|
||||
@ -783,7 +791,7 @@ pub fn unlink(path: [*:0]const u8) usize {
|
||||
if (@hasField(SYS, "unlink")) {
|
||||
return syscall1(.unlink, @ptrToInt(path));
|
||||
} else {
|
||||
return syscall3(.unlinkat, @bitCast(usize, @as(isize, AT_FDCWD)), @ptrToInt(path), 0);
|
||||
return syscall3(.unlinkat, @bitCast(usize, @as(isize, AT.FDCWD)), @ptrToInt(path), 0);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1131,7 +1139,7 @@ pub fn sendmmsg(fd: i32, msgvec: [*]mmsghdr_const, vlen: u32, flags: u32) usize
|
||||
}
|
||||
}
|
||||
}
|
||||
if (next_unsent < kvlen or next_unsent == 0) { // want to make sure at least one syscall occurs (e.g. to trigger MSG_EOR)
|
||||
if (next_unsent < kvlen or next_unsent == 0) { // want to make sure at least one syscall occurs (e.g. to trigger MSG.EOR)
|
||||
const batch_size = kvlen - next_unsent;
|
||||
const r = syscall4(.sendmmsg, @bitCast(usize, @as(isize, fd)), @ptrToInt(&msgvec[next_unsent]), batch_size, flags);
|
||||
if (getErrno(r) != 0) return r;
|
||||
@ -1759,10 +1767,10 @@ pub const W = struct {
|
||||
return s & 0x7f;
|
||||
}
|
||||
pub fn STOPSIG(s: u32) u32 {
|
||||
return WEXITSTATUS(s);
|
||||
return EXITSTATUS(s);
|
||||
}
|
||||
pub fn IFEXITED(s: u32) bool {
|
||||
return WTERMSIG(s) == 0;
|
||||
return TERMSIG(s) == 0;
|
||||
}
|
||||
pub fn IFSTOPPED(s: u32) bool {
|
||||
return @intCast(u16, ((s & 0xffff) *% 0x10001) >> 8) > 0x7f00;
|
||||
@ -2886,31 +2894,51 @@ pub const socklen_t = u32;
|
||||
pub const sockaddr = extern struct {
|
||||
family: sa_family_t,
|
||||
data: [14]u8,
|
||||
};
|
||||
|
||||
pub const sockaddr_storage = std.x.os.Socket.Address.Native.Storage;
|
||||
pub const storage = std.x.os.Socket.Address.Native.Storage;
|
||||
|
||||
/// IPv4 socket address
|
||||
pub const sockaddr_in = extern struct {
|
||||
family: sa_family_t = AF_INET,
|
||||
port: in_port_t,
|
||||
addr: u32,
|
||||
zero: [8]u8 = [8]u8{ 0, 0, 0, 0, 0, 0, 0, 0 },
|
||||
};
|
||||
/// IPv4 socket address
|
||||
pub const in = extern struct {
|
||||
family: sa_family_t = AF.INET,
|
||||
port: in_port_t,
|
||||
addr: u32,
|
||||
zero: [8]u8 = [8]u8{ 0, 0, 0, 0, 0, 0, 0, 0 },
|
||||
};
|
||||
|
||||
/// IPv6 socket address
|
||||
pub const sockaddr_in6 = extern struct {
|
||||
family: sa_family_t = AF_INET6,
|
||||
port: in_port_t,
|
||||
flowinfo: u32,
|
||||
addr: [16]u8,
|
||||
scope_id: u32,
|
||||
};
|
||||
/// IPv6 socket address
|
||||
pub const in6 = extern struct {
|
||||
family: sa_family_t = AF.INET6,
|
||||
port: in_port_t,
|
||||
flowinfo: u32,
|
||||
addr: [16]u8,
|
||||
scope_id: u32,
|
||||
};
|
||||
|
||||
/// UNIX domain socket address
|
||||
pub const sockaddr_un = extern struct {
|
||||
family: sa_family_t = AF_UNIX,
|
||||
path: [108]u8,
|
||||
/// UNIX domain socket address
|
||||
pub const un = extern struct {
|
||||
family: sa_family_t = AF.UNIX,
|
||||
path: [108]u8,
|
||||
};
|
||||
|
||||
/// Netlink socket address
|
||||
pub const nl = extern struct {
|
||||
family: sa_family_t = AF.NETLINK,
|
||||
__pad1: c_ushort = 0,
|
||||
|
||||
/// port ID
|
||||
pid: u32,
|
||||
|
||||
/// multicast groups mask
|
||||
groups: u32,
|
||||
};
|
||||
|
||||
pub const xdp = extern struct {
|
||||
family: u16 = AF.XDP,
|
||||
flags: u16,
|
||||
ifindex: u32,
|
||||
queue_id: u32,
|
||||
shared_umem_fd: u32,
|
||||
};
|
||||
};
|
||||
|
||||
pub const mmsghdr = extern struct {
|
||||
@ -3584,43 +3612,47 @@ pub const addrinfo = extern struct {
|
||||
|
||||
pub const IPPORT_RESERVED = 1024;
|
||||
|
||||
pub const IPPROTO_IP = 0;
|
||||
pub const IPPROTO_HOPOPTS = 0;
|
||||
pub const IPPROTO_ICMP = 1;
|
||||
pub const IPPROTO_IGMP = 2;
|
||||
pub const IPPROTO_IPIP = 4;
|
||||
pub const IPPROTO_TCP = 6;
|
||||
pub const IPPROTO_EGP = 8;
|
||||
pub const IPPROTO_PUP = 12;
|
||||
pub const IPPROTO_UDP = 17;
|
||||
pub const IPPROTO_IDP = 22;
|
||||
pub const IPPROTO_TP = 29;
|
||||
pub const IPPROTO_DCCP = 33;
|
||||
pub const IPPROTO_IPV6 = 41;
|
||||
pub const IPPROTO_ROUTING = 43;
|
||||
pub const IPPROTO_FRAGMENT = 44;
|
||||
pub const IPPROTO_RSVP = 46;
|
||||
pub const IPPROTO_GRE = 47;
|
||||
pub const IPPROTO_ESP = 50;
|
||||
pub const IPPROTO_AH = 51;
|
||||
pub const IPPROTO_ICMPV6 = 58;
|
||||
pub const IPPROTO_NONE = 59;
|
||||
pub const IPPROTO_DSTOPTS = 60;
|
||||
pub const IPPROTO_MTP = 92;
|
||||
pub const IPPROTO_BEETPH = 94;
|
||||
pub const IPPROTO_ENCAP = 98;
|
||||
pub const IPPROTO_PIM = 103;
|
||||
pub const IPPROTO_COMP = 108;
|
||||
pub const IPPROTO_SCTP = 132;
|
||||
pub const IPPROTO_MH = 135;
|
||||
pub const IPPROTO_UDPLITE = 136;
|
||||
pub const IPPROTO_MPLS = 137;
|
||||
pub const IPPROTO_RAW = 255;
|
||||
pub const IPPROTO_MAX = 256;
|
||||
pub const IPPROTO = struct {
|
||||
pub const IP = 0;
|
||||
pub const HOPOPTS = 0;
|
||||
pub const ICMP = 1;
|
||||
pub const IGMP = 2;
|
||||
pub const IPIP = 4;
|
||||
pub const TCP = 6;
|
||||
pub const EGP = 8;
|
||||
pub const PUP = 12;
|
||||
pub const UDP = 17;
|
||||
pub const IDP = 22;
|
||||
pub const TP = 29;
|
||||
pub const DCCP = 33;
|
||||
pub const IPV6 = 41;
|
||||
pub const ROUTING = 43;
|
||||
pub const FRAGMENT = 44;
|
||||
pub const RSVP = 46;
|
||||
pub const GRE = 47;
|
||||
pub const ESP = 50;
|
||||
pub const AH = 51;
|
||||
pub const ICMPV6 = 58;
|
||||
pub const NONE = 59;
|
||||
pub const DSTOPTS = 60;
|
||||
pub const MTP = 92;
|
||||
pub const BEETPH = 94;
|
||||
pub const ENCAP = 98;
|
||||
pub const PIM = 103;
|
||||
pub const COMP = 108;
|
||||
pub const SCTP = 132;
|
||||
pub const MH = 135;
|
||||
pub const UDPLITE = 136;
|
||||
pub const MPLS = 137;
|
||||
pub const RAW = 255;
|
||||
pub const MAX = 256;
|
||||
};
|
||||
|
||||
pub const RR_A = 1;
|
||||
pub const RR_CNAME = 5;
|
||||
pub const RR_AAAA = 28;
|
||||
pub const RR = struct {
|
||||
pub const A = 1;
|
||||
pub const CNAME = 5;
|
||||
pub const AAAA = 28;
|
||||
};
|
||||
|
||||
/// Turn off Nagle's algorithm
|
||||
pub const TCP_NODELAY = 1;
|
||||
@ -3746,14 +3778,16 @@ pub const pollfd = extern struct {
|
||||
revents: i16,
|
||||
};
|
||||
|
||||
pub const POLLIN = 0x001;
|
||||
pub const POLLPRI = 0x002;
|
||||
pub const POLLOUT = 0x004;
|
||||
pub const POLLERR = 0x008;
|
||||
pub const POLLHUP = 0x010;
|
||||
pub const POLLNVAL = 0x020;
|
||||
pub const POLLRDNORM = 0x040;
|
||||
pub const POLLRDBAND = 0x080;
|
||||
pub const POLL = struct {
|
||||
pub const IN = 0x001;
|
||||
pub const PRI = 0x002;
|
||||
pub const OUT = 0x004;
|
||||
pub const ERR = 0x008;
|
||||
pub const HUP = 0x010;
|
||||
pub const NVAL = 0x020;
|
||||
pub const RDNORM = 0x040;
|
||||
pub const RDBAND = 0x080;
|
||||
};
|
||||
|
||||
pub const MFD_CLOEXEC = 0x0001;
|
||||
pub const MFD_ALLOW_SEALING = 0x0002;
|
||||
@ -4097,11 +4131,13 @@ pub const rlimit_resource = enum(c_int) {
|
||||
|
||||
pub const rlim_t = u64;
|
||||
|
||||
/// No limit
|
||||
pub const RLIM_INFINITY = ~@as(rlim_t, 0);
|
||||
pub const RLIM = struct {
|
||||
/// No limit
|
||||
pub const INFINITY = ~@as(rlim_t, 0);
|
||||
|
||||
pub const RLIM_SAVED_MAX = RLIM_INFINITY;
|
||||
pub const RLIM_SAVED_CUR = RLIM_INFINITY;
|
||||
pub const SAVED_MAX = INFINITY;
|
||||
pub const SAVED_CUR = INFINITY;
|
||||
};
|
||||
|
||||
pub const rlimit = extern struct {
|
||||
/// Soft limit
|
||||
@ -4189,14 +4225,6 @@ pub const XDP = struct {
|
||||
pub const UMEM_PGOFF_COMPLETION_RING = 0x180000000;
|
||||
};
|
||||
|
||||
pub const sockaddr_xdp = extern struct {
|
||||
family: u16 = AF_XDP,
|
||||
flags: u16,
|
||||
ifindex: u32,
|
||||
queue_id: u32,
|
||||
shared_umem_fd: u32,
|
||||
};
|
||||
|
||||
pub const xdp_ring_offset = extern struct {
|
||||
producer: u64,
|
||||
consumer: u64,
|
||||
@ -4673,18 +4701,6 @@ pub const NetlinkMessageType = enum(u16) {
|
||||
_,
|
||||
};
|
||||
|
||||
/// Netlink socket address
|
||||
pub const sockaddr_nl = extern struct {
|
||||
family: sa_family_t = AF_NETLINK,
|
||||
__pad1: c_ushort = 0,
|
||||
|
||||
/// port ID
|
||||
pid: u32,
|
||||
|
||||
/// multicast groups mask
|
||||
groups: u32,
|
||||
};
|
||||
|
||||
/// Netlink message header
|
||||
/// Specified in RFC 3549 Section 2.3.2
|
||||
pub const nlmsghdr = extern struct {
|
||||
|
||||
@ -575,26 +575,27 @@ pub const F_GETOWN_EX = 16;
|
||||
|
||||
pub const F_GETOWNER_UIDS = 17;
|
||||
|
||||
pub const LOCK_SH = 1;
|
||||
pub const LOCK_EX = 2;
|
||||
pub const LOCK_UN = 8;
|
||||
pub const LOCK_NB = 4;
|
||||
|
||||
/// stack-like segment
|
||||
pub const MAP_GROWSDOWN = 0x0100;
|
||||
|
||||
/// ETXTBSY
|
||||
pub const MAP_DENYWRITE = 0x0800;
|
||||
|
||||
/// mark it as an executable
|
||||
pub const MAP_EXECUTABLE = 0x1000;
|
||||
|
||||
/// pages are locked
|
||||
pub const MAP_LOCKED = 0x2000;
|
||||
|
||||
/// don't check for reservations
|
||||
pub const MAP_NORESERVE = 0x4000;
|
||||
pub const LOCK = struct {
|
||||
pub const SH = 1;
|
||||
pub const EX = 2;
|
||||
pub const UN = 8;
|
||||
pub const NB = 4;
|
||||
};
|
||||
|
||||
pub const MAP = struct {
|
||||
/// stack-like segment
|
||||
pub const GROWSDOWN = 0x0100;
|
||||
/// ETXTBSY
|
||||
pub const DENYWRITE = 0x0800;
|
||||
/// mark it as an executable
|
||||
pub const EXECUTABLE = 0x1000;
|
||||
/// pages are locked
|
||||
pub const LOCKED = 0x2000;
|
||||
/// don't check for reservations
|
||||
pub const NORESERVE = 0x4000;
|
||||
/// Only used by libc to communicate failure.
|
||||
pub const FAILED = @intToPtr(*c_void, maxInt(usize));
|
||||
};
|
||||
pub const VDSO_CGT_SYM = "__vdso_clock_gettime";
|
||||
pub const VDSO_CGT_VER = "LINUX_2.6";
|
||||
|
||||
|
||||
@ -449,31 +449,32 @@ pub const F_RDLCK = 0;
|
||||
pub const F_WRLCK = 1;
|
||||
pub const F_UNLCK = 2;
|
||||
|
||||
pub const LOCK_SH = 1;
|
||||
pub const LOCK_EX = 2;
|
||||
pub const LOCK_UN = 8;
|
||||
pub const LOCK_NB = 4;
|
||||
pub const LOCK = struct {
|
||||
pub const SH = 1;
|
||||
pub const EX = 2;
|
||||
pub const UN = 8;
|
||||
pub const NB = 4;
|
||||
};
|
||||
|
||||
pub const F_SETOWN_EX = 15;
|
||||
pub const F_GETOWN_EX = 16;
|
||||
|
||||
pub const F_GETOWNER_UIDS = 17;
|
||||
|
||||
/// stack-like segment
|
||||
pub const MAP_GROWSDOWN = 0x0100;
|
||||
|
||||
/// ETXTBSY
|
||||
pub const MAP_DENYWRITE = 0x0800;
|
||||
|
||||
/// mark it as an executable
|
||||
pub const MAP_EXECUTABLE = 0x1000;
|
||||
|
||||
/// pages are locked
|
||||
pub const MAP_LOCKED = 0x2000;
|
||||
|
||||
/// don't check for reservations
|
||||
pub const MAP_NORESERVE = 0x4000;
|
||||
|
||||
pub const MAP = struct {
|
||||
/// stack-like segment
|
||||
pub const GROWSDOWN = 0x0100;
|
||||
/// ETXTBSY
|
||||
pub const DENYWRITE = 0x0800;
|
||||
/// mark it as an executable
|
||||
pub const EXECUTABLE = 0x1000;
|
||||
/// pages are locked
|
||||
pub const LOCKED = 0x2000;
|
||||
/// don't check for reservations
|
||||
pub const NORESERVE = 0x4000;
|
||||
/// Only used by libc to communicate failure.
|
||||
pub const FAILED = @intToPtr(*c_void, maxInt(usize));
|
||||
};
|
||||
pub const VDSO_CGT_SYM = "__kernel_clock_gettime";
|
||||
pub const VDSO_CGT_VER = "LINUX_2.6.39";
|
||||
|
||||
|
||||
@ -671,6 +671,9 @@ pub const MAP = struct {
|
||||
pub const EXECUTABLE = 0x1000;
|
||||
pub const LOCKED = 0x2000;
|
||||
pub const @"32BIT" = 0x40;
|
||||
|
||||
/// Only used by libc to communicate failure.
|
||||
pub const FAILED = @intToPtr(*c_void, maxInt(usize));
|
||||
};
|
||||
|
||||
pub const MMAP2_UNIT = 4096;
|
||||
|
||||
@ -535,7 +535,7 @@ pub const IO_Uring = struct {
|
||||
/// `0` if the timeout completed after the specified number of events, or `-ECANCELED` if the
|
||||
/// timeout was removed before it expired.
|
||||
///
|
||||
/// io_uring timeouts use the `CLOCK_MONOTONIC` clock source.
|
||||
/// io_uring timeouts use the `CLOCK.MONOTONIC` clock source.
|
||||
pub fn timeout(
|
||||
self: *IO_Uring,
|
||||
user_data: u64,
|
||||
@ -736,8 +736,8 @@ pub const SubmissionQueue = struct {
|
||||
const mmap = try os.mmap(
|
||||
null,
|
||||
size,
|
||||
os.PROT_READ | os.PROT_WRITE,
|
||||
os.MAP_SHARED | os.MAP_POPULATE,
|
||||
os.PROT.READ | os.PROT.WRITE,
|
||||
os.MAP.SHARED | os.MAP.POPULATE,
|
||||
fd,
|
||||
linux.IORING_OFF_SQ_RING,
|
||||
);
|
||||
@ -750,8 +750,8 @@ pub const SubmissionQueue = struct {
|
||||
const mmap_sqes = try os.mmap(
|
||||
null,
|
||||
size_sqes,
|
||||
os.PROT_READ | os.PROT_WRITE,
|
||||
os.MAP_SHARED | os.MAP_POPULATE,
|
||||
os.PROT.READ | os.PROT.WRITE,
|
||||
os.MAP.SHARED | os.MAP.POPULATE,
|
||||
fd,
|
||||
linux.IORING_OFF_SQES,
|
||||
);
|
||||
@ -1372,9 +1372,9 @@ test "accept/connect/send/recv" {
|
||||
|
||||
const address = try net.Address.parseIp4("127.0.0.1", 3131);
|
||||
const kernel_backlog = 1;
|
||||
const server = try os.socket(address.any.family, os.SOCK_STREAM | os.SOCK_CLOEXEC, 0);
|
||||
const server = try os.socket(address.any.family, os.SOCK.STREAM | os.SOCK.CLOEXEC, 0);
|
||||
defer os.close(server);
|
||||
try os.setsockopt(server, os.SOL_SOCKET, os.SO_REUSEADDR, &mem.toBytes(@as(c_int, 1)));
|
||||
try os.setsockopt(server, os.SOL.SOCKET, os.SO.REUSEADDR, &mem.toBytes(@as(c_int, 1)));
|
||||
try os.bind(server, &address.any, address.getOsSockLen());
|
||||
try os.listen(server, kernel_backlog);
|
||||
|
||||
@ -1386,7 +1386,7 @@ test "accept/connect/send/recv" {
|
||||
_ = try ring.accept(0xaaaaaaaa, server, &accept_addr, &accept_addr_len, 0);
|
||||
try testing.expectEqual(@as(u32, 1), try ring.submit());
|
||||
|
||||
const client = try os.socket(address.any.family, os.SOCK_STREAM | os.SOCK_CLOEXEC, 0);
|
||||
const client = try os.socket(address.any.family, os.SOCK.STREAM | os.SOCK.CLOEXEC, 0);
|
||||
defer os.close(client);
|
||||
_ = try ring.connect(0xcccccccc, client, &address.any, address.getOsSockLen());
|
||||
try testing.expectEqual(@as(u32, 1), try ring.submit());
|
||||
|
||||
@ -668,10 +668,12 @@ pub const F_RDLCK = 0;
|
||||
pub const F_WRLCK = 1;
|
||||
pub const F_UNLCK = 2;
|
||||
|
||||
pub const LOCK_SH = 1;
|
||||
pub const LOCK_EX = 2;
|
||||
pub const LOCK_UN = 8;
|
||||
pub const LOCK_NB = 4;
|
||||
pub const LOCK = struct {
|
||||
pub const SH = 1;
|
||||
pub const EX = 2;
|
||||
pub const UN = 8;
|
||||
pub const NB = 4;
|
||||
};
|
||||
|
||||
pub const F_SETOWN_EX = 15;
|
||||
pub const F_GETOWN_EX = 16;
|
||||
@ -680,40 +682,46 @@ pub const F_GETOWNER_UIDS = 17;
|
||||
|
||||
pub const MMAP2_UNIT = 4096;
|
||||
|
||||
pub const MAP_NORESERVE = 0x0400;
|
||||
pub const MAP_GROWSDOWN = 0x1000;
|
||||
pub const MAP_DENYWRITE = 0x2000;
|
||||
pub const MAP_EXECUTABLE = 0x4000;
|
||||
pub const MAP_LOCKED = 0x8000;
|
||||
pub const MAP_32BIT = 0x40;
|
||||
pub const MAP = struct {
|
||||
pub const NORESERVE = 0x0400;
|
||||
pub const GROWSDOWN = 0x1000;
|
||||
pub const DENYWRITE = 0x2000;
|
||||
pub const EXECUTABLE = 0x4000;
|
||||
pub const LOCKED = 0x8000;
|
||||
pub const @"32BIT" = 0x40;
|
||||
/// Only used by libc to communicate failure.
|
||||
pub const FAILED = @intToPtr(*c_void, maxInt(usize));
|
||||
};
|
||||
|
||||
pub const SO_DEBUG = 1;
|
||||
pub const SO_REUSEADDR = 0x0004;
|
||||
pub const SO_KEEPALIVE = 0x0008;
|
||||
pub const SO_DONTROUTE = 0x0010;
|
||||
pub const SO_BROADCAST = 0x0020;
|
||||
pub const SO_LINGER = 0x0080;
|
||||
pub const SO_OOBINLINE = 0x0100;
|
||||
pub const SO_REUSEPORT = 0x0200;
|
||||
pub const SO_SNDBUF = 0x1001;
|
||||
pub const SO_RCVBUF = 0x1002;
|
||||
pub const SO_SNDLOWAT = 0x1003;
|
||||
pub const SO_RCVLOWAT = 0x1004;
|
||||
pub const SO_RCVTIMEO = 0x1006;
|
||||
pub const SO_SNDTIMEO = 0x1005;
|
||||
pub const SO_ERROR = 0x1007;
|
||||
pub const SO_TYPE = 0x1008;
|
||||
pub const SO_ACCEPTCONN = 0x1009;
|
||||
pub const SO_PROTOCOL = 0x1028;
|
||||
pub const SO_DOMAIN = 0x1029;
|
||||
pub const SO_NO_CHECK = 11;
|
||||
pub const SO_PRIORITY = 12;
|
||||
pub const SO_BSDCOMPAT = 14;
|
||||
pub const SO_PASSCRED = 17;
|
||||
pub const SO_PEERCRED = 18;
|
||||
pub const SO_PEERSEC = 30;
|
||||
pub const SO_SNDBUFFORCE = 31;
|
||||
pub const SO_RCVBUFFORCE = 33;
|
||||
pub const SO = struct {
|
||||
pub const DEBUG = 1;
|
||||
pub const REUSEADDR = 0x0004;
|
||||
pub const KEEPALIVE = 0x0008;
|
||||
pub const DONTROUTE = 0x0010;
|
||||
pub const BROADCAST = 0x0020;
|
||||
pub const LINGER = 0x0080;
|
||||
pub const OOBINLINE = 0x0100;
|
||||
pub const REUSEPORT = 0x0200;
|
||||
pub const SNDBUF = 0x1001;
|
||||
pub const RCVBUF = 0x1002;
|
||||
pub const SNDLOWAT = 0x1003;
|
||||
pub const RCVLOWAT = 0x1004;
|
||||
pub const RCVTIMEO = 0x1006;
|
||||
pub const SNDTIMEO = 0x1005;
|
||||
pub const ERROR = 0x1007;
|
||||
pub const TYPE = 0x1008;
|
||||
pub const ACCEPTCONN = 0x1009;
|
||||
pub const PROTOCOL = 0x1028;
|
||||
pub const DOMAIN = 0x1029;
|
||||
pub const NO_CHECK = 11;
|
||||
pub const PRIORITY = 12;
|
||||
pub const BSDCOMPAT = 14;
|
||||
pub const PASSCRED = 17;
|
||||
pub const PEERCRED = 18;
|
||||
pub const PEERSEC = 30;
|
||||
pub const SNDBUFFORCE = 31;
|
||||
pub const RCVBUFFORCE = 33;
|
||||
};
|
||||
|
||||
pub const VDSO_CGT_SYM = "__kernel_clock_gettime";
|
||||
pub const VDSO_CGT_VER = "LINUX_2.6.39";
|
||||
|
||||
@ -605,26 +605,27 @@ pub const F_RDLCK = 0;
|
||||
pub const F_WRLCK = 1;
|
||||
pub const F_UNLCK = 2;
|
||||
|
||||
pub const LOCK_SH = 1;
|
||||
pub const LOCK_EX = 2;
|
||||
pub const LOCK_UN = 8;
|
||||
pub const LOCK_NB = 4;
|
||||
|
||||
/// stack-like segment
|
||||
pub const MAP_GROWSDOWN = 0x0100;
|
||||
|
||||
/// ETXTBSY
|
||||
pub const MAP_DENYWRITE = 0x0800;
|
||||
|
||||
/// mark it as an executable
|
||||
pub const MAP_EXECUTABLE = 0x1000;
|
||||
|
||||
/// pages are locked
|
||||
pub const MAP_LOCKED = 0x0080;
|
||||
|
||||
/// don't check for reservations
|
||||
pub const MAP_NORESERVE = 0x0040;
|
||||
pub const LOCK = struct {
|
||||
pub const SH = 1;
|
||||
pub const EX = 2;
|
||||
pub const UN = 8;
|
||||
pub const NB = 4;
|
||||
};
|
||||
|
||||
pub const MAP = struct {
|
||||
/// stack-like segment
|
||||
pub const GROWSDOWN = 0x0100;
|
||||
/// ETXTBSY
|
||||
pub const DENYWRITE = 0x0800;
|
||||
/// mark it as an executable
|
||||
pub const EXECUTABLE = 0x1000;
|
||||
/// pages are locked
|
||||
pub const LOCKED = 0x0080;
|
||||
/// don't check for reservations
|
||||
pub const NORESERVE = 0x0040;
|
||||
/// Only used by libc to communicate failure.
|
||||
pub const FAILED = @intToPtr(*c_void, maxInt(usize));
|
||||
};
|
||||
pub const VDSO_CGT_SYM = "__kernel_clock_gettime";
|
||||
pub const VDSO_CGT_VER = "LINUX_2.6.15";
|
||||
|
||||
|
||||
@ -575,30 +575,32 @@ pub const F_RDLCK = 0;
|
||||
pub const F_WRLCK = 1;
|
||||
pub const F_UNLCK = 2;
|
||||
|
||||
pub const LOCK_SH = 1;
|
||||
pub const LOCK_EX = 2;
|
||||
pub const LOCK_UN = 8;
|
||||
pub const LOCK_NB = 4;
|
||||
pub const LOCK = struct {
|
||||
pub const SH = 1;
|
||||
pub const EX = 2;
|
||||
pub const UN = 8;
|
||||
pub const NB = 4;
|
||||
};
|
||||
|
||||
pub const F_SETOWN_EX = 15;
|
||||
pub const F_GETOWN_EX = 16;
|
||||
|
||||
pub const F_GETOWNER_UIDS = 17;
|
||||
|
||||
/// stack-like segment
|
||||
pub const MAP_GROWSDOWN = 0x0100;
|
||||
|
||||
/// ETXTBSY
|
||||
pub const MAP_DENYWRITE = 0x0800;
|
||||
|
||||
/// mark it as an executable
|
||||
pub const MAP_EXECUTABLE = 0x1000;
|
||||
|
||||
/// pages are locked
|
||||
pub const MAP_LOCKED = 0x0080;
|
||||
|
||||
/// don't check for reservations
|
||||
pub const MAP_NORESERVE = 0x0040;
|
||||
pub const MAP = struct {
|
||||
/// stack-like segment
|
||||
pub const GROWSDOWN = 0x0100;
|
||||
/// ETXTBSY
|
||||
pub const DENYWRITE = 0x0800;
|
||||
/// mark it as an executable
|
||||
pub const EXECUTABLE = 0x1000;
|
||||
/// pages are locked
|
||||
pub const LOCKED = 0x0080;
|
||||
/// don't check for reservations
|
||||
pub const NORESERVE = 0x0040;
|
||||
/// Only used by libc to communicate failure.
|
||||
pub const FAILED = @intToPtr(*c_void, maxInt(usize));
|
||||
};
|
||||
|
||||
pub const VDSO_CGT_SYM = "__kernel_clock_gettime";
|
||||
pub const VDSO_CGT_VER = "LINUX_2.6.15";
|
||||
|
||||
@ -444,10 +444,12 @@ pub const F_RDLCK = 0;
|
||||
pub const F_WRLCK = 1;
|
||||
pub const F_UNLCK = 2;
|
||||
|
||||
pub const LOCK_SH = 1;
|
||||
pub const LOCK_EX = 2;
|
||||
pub const LOCK_UN = 8;
|
||||
pub const LOCK_NB = 4;
|
||||
pub const LOCK = struct {
|
||||
pub const SH = 1;
|
||||
pub const EX = 2;
|
||||
pub const UN = 8;
|
||||
pub const NB = 4;
|
||||
};
|
||||
|
||||
pub const F_SETOWN_EX = 15;
|
||||
pub const F_GETOWN_EX = 16;
|
||||
|
||||
@ -612,26 +612,27 @@ pub const F_GETOWN_EX = 16;
|
||||
|
||||
pub const F_GETOWNER_UIDS = 17;
|
||||
|
||||
pub const LOCK_SH = 1;
|
||||
pub const LOCK_EX = 2;
|
||||
pub const LOCK_NB = 4;
|
||||
pub const LOCK_UN = 8;
|
||||
|
||||
/// stack-like segment
|
||||
pub const MAP_GROWSDOWN = 0x0200;
|
||||
|
||||
/// ETXTBSY
|
||||
pub const MAP_DENYWRITE = 0x0800;
|
||||
|
||||
/// mark it as an executable
|
||||
pub const MAP_EXECUTABLE = 0x1000;
|
||||
|
||||
/// pages are locked
|
||||
pub const MAP_LOCKED = 0x0100;
|
||||
|
||||
/// don't check for reservations
|
||||
pub const MAP_NORESERVE = 0x0040;
|
||||
pub const LOCK = struct {
|
||||
pub const SH = 1;
|
||||
pub const EX = 2;
|
||||
pub const NB = 4;
|
||||
pub const UN = 8;
|
||||
};
|
||||
|
||||
pub const MAP = struct {
|
||||
/// stack-like segment
|
||||
pub const GROWSDOWN = 0x0200;
|
||||
/// ETXTBSY
|
||||
pub const DENYWRITE = 0x0800;
|
||||
/// mark it as an executable
|
||||
pub const EXECUTABLE = 0x1000;
|
||||
/// pages are locked
|
||||
pub const LOCKED = 0x0100;
|
||||
/// don't check for reservations
|
||||
pub const NORESERVE = 0x0040;
|
||||
/// Only used by libc to communicate failure.
|
||||
pub const FAILED = @intToPtr(*c_void, maxInt(usize));
|
||||
};
|
||||
pub const VDSO_CGT_SYM = "__vdso_clock_gettime";
|
||||
pub const VDSO_CGT_VER = "LINUX_2.6";
|
||||
|
||||
|
||||
@ -35,7 +35,7 @@ test "timer" {
|
||||
var err: linux.E = linux.getErrno(epoll_fd);
|
||||
try expect(err == .SUCCESS);
|
||||
|
||||
const timer_fd = linux.timerfd_create(linux.CLOCK_MONOTONIC, 0);
|
||||
const timer_fd = linux.timerfd_create(linux.CLOCK.MONOTONIC, 0);
|
||||
try expect(linux.getErrno(timer_fd) == .SUCCESS);
|
||||
|
||||
const time_interval = linux.timespec{
|
||||
@ -52,11 +52,11 @@ test "timer" {
|
||||
try expect(err == .SUCCESS);
|
||||
|
||||
var event = linux.epoll_event{
|
||||
.events = linux.EPOLLIN | linux.EPOLLOUT | linux.EPOLLET,
|
||||
.events = linux.EPOLL.IN | linux.EPOLL.OUT | linux.EPOLL.ET,
|
||||
.data = linux.epoll_data{ .ptr = 0 },
|
||||
};
|
||||
|
||||
err = linux.getErrno(linux.epoll_ctl(@intCast(i32, epoll_fd), linux.EPOLL_CTL_ADD, @intCast(i32, timer_fd), &event));
|
||||
err = linux.getErrno(linux.epoll_ctl(@intCast(i32, epoll_fd), linux.EPOLL.CTL_ADD, @intCast(i32, timer_fd), &event));
|
||||
try expect(err == .SUCCESS);
|
||||
|
||||
const events_one: linux.epoll_event = undefined;
|
||||
@ -75,7 +75,7 @@ test "statx" {
|
||||
}
|
||||
|
||||
var statx_buf: linux.Statx = undefined;
|
||||
switch (linux.getErrno(linux.statx(file.handle, "", linux.AT_EMPTY_PATH, linux.STATX_BASIC_STATS, &statx_buf))) {
|
||||
switch (linux.getErrno(linux.statx(file.handle, "", linux.AT.EMPTY_PATH, linux.STATX_BASIC_STATS, &statx_buf))) {
|
||||
.SUCCESS => {},
|
||||
// The statx syscall was only introduced in linux 4.11
|
||||
.NOSYS => return error.SkipZigTest,
|
||||
@ -83,7 +83,7 @@ test "statx" {
|
||||
}
|
||||
|
||||
var stat_buf: linux.Stat = undefined;
|
||||
switch (linux.getErrno(linux.fstatat(file.handle, "", &stat_buf, linux.AT_EMPTY_PATH))) {
|
||||
switch (linux.getErrno(linux.fstatat(file.handle, "", &stat_buf, linux.AT.EMPTY_PATH))) {
|
||||
.SUCCESS => {},
|
||||
else => unreachable,
|
||||
}
|
||||
@ -119,7 +119,7 @@ test "fadvise" {
|
||||
file.handle,
|
||||
0,
|
||||
0,
|
||||
linux.POSIX_FADV_SEQUENTIAL,
|
||||
linux.POSIX_FADV.SEQUENTIAL,
|
||||
);
|
||||
try expectEqual(@as(usize, 0), ret);
|
||||
}
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
const std = @import("../../std.zig");
|
||||
const maxInt = std.math.maxInt;
|
||||
const linux = std.os.linux;
|
||||
const iovec = std.os.iovec;
|
||||
const iovec_const = std.os.iovec_const;
|
||||
@ -527,59 +528,44 @@ pub const F = struct {
|
||||
pub const MAP = struct {
|
||||
/// Share changes
|
||||
pub const SHARED = 0x01;
|
||||
|
||||
/// Changes are private
|
||||
pub const PRIVATE = 0x02;
|
||||
|
||||
/// share + validate extension flags
|
||||
pub const SHARED_VALIDATE = 0x03;
|
||||
|
||||
/// Mask for type of mapping
|
||||
pub const TYPE = 0x0f;
|
||||
|
||||
/// Interpret addr exactly
|
||||
pub const FIXED = 0x10;
|
||||
|
||||
/// don't use a file
|
||||
pub const ANONYMOUS = 0x20;
|
||||
|
||||
/// populate (prefault) pagetables
|
||||
pub const POPULATE = 0x8000;
|
||||
|
||||
/// do not block on IO
|
||||
pub const NONBLOCK = 0x10000;
|
||||
|
||||
/// give out an address that is best suited for process/thread stacks
|
||||
pub const STACK = 0x20000;
|
||||
|
||||
/// create a huge page mapping
|
||||
pub const HUGETLB = 0x40000;
|
||||
|
||||
/// perform synchronous page faults for the mapping
|
||||
pub const SYNC = 0x80000;
|
||||
|
||||
/// FIXED which doesn't unmap underlying mapping
|
||||
pub const FIXED_NOREPLACE = 0x100000;
|
||||
|
||||
/// For anonymous mmap, memory could be uninitialized
|
||||
pub const UNINITIALIZED = 0x4000000;
|
||||
/// only give out 32bit addresses
|
||||
pub const @"32BIT" = 0x40;
|
||||
|
||||
/// stack-like segment
|
||||
pub const GROWSDOWN = 0x0100;
|
||||
|
||||
/// ETXTBSY
|
||||
pub const DENYWRITE = 0x0800;
|
||||
|
||||
/// mark it as an executable
|
||||
pub const EXECUTABLE = 0x1000;
|
||||
|
||||
/// pages are locked
|
||||
pub const LOCKED = 0x2000;
|
||||
|
||||
/// don't check for reservations
|
||||
pub const NORESERVE = 0x4000;
|
||||
/// Only used by libc to communicate failure.
|
||||
pub const FAILED = @intToPtr(*c_void, maxInt(usize));
|
||||
};
|
||||
|
||||
pub const VDSO = struct {
|
||||
|
||||
@ -70,21 +70,21 @@ test "open smoke test" {
|
||||
|
||||
// Create some file using `open`.
|
||||
file_path = try fs.path.join(&arena.allocator, &[_][]const u8{ base_path, "some_file" });
|
||||
fd = try os.open(file_path, os.O_RDWR | os.O_CREAT | os.O_EXCL, mode);
|
||||
fd = try os.open(file_path, os.O.RDWR | os.O.CREAT | os.O.EXCL, mode);
|
||||
os.close(fd);
|
||||
|
||||
// Try this again with the same flags. This op should fail with error.PathAlreadyExists.
|
||||
file_path = try fs.path.join(&arena.allocator, &[_][]const u8{ base_path, "some_file" });
|
||||
try expectError(error.PathAlreadyExists, os.open(file_path, os.O_RDWR | os.O_CREAT | os.O_EXCL, mode));
|
||||
try expectError(error.PathAlreadyExists, os.open(file_path, os.O.RDWR | os.O.CREAT | os.O.EXCL, mode));
|
||||
|
||||
// Try opening without `O_EXCL` flag.
|
||||
// Try opening without `O.EXCL` flag.
|
||||
file_path = try fs.path.join(&arena.allocator, &[_][]const u8{ base_path, "some_file" });
|
||||
fd = try os.open(file_path, os.O_RDWR | os.O_CREAT, mode);
|
||||
fd = try os.open(file_path, os.O.RDWR | os.O.CREAT, mode);
|
||||
os.close(fd);
|
||||
|
||||
// Try opening as a directory which should fail.
|
||||
file_path = try fs.path.join(&arena.allocator, &[_][]const u8{ base_path, "some_file" });
|
||||
try expectError(error.NotDir, os.open(file_path, os.O_RDWR | os.O_DIRECTORY, mode));
|
||||
try expectError(error.NotDir, os.open(file_path, os.O.RDWR | os.O.DIRECTORY, mode));
|
||||
|
||||
// Create some directory
|
||||
file_path = try fs.path.join(&arena.allocator, &[_][]const u8{ base_path, "some_dir" });
|
||||
@ -92,12 +92,12 @@ test "open smoke test" {
|
||||
|
||||
// Open dir using `open`
|
||||
file_path = try fs.path.join(&arena.allocator, &[_][]const u8{ base_path, "some_dir" });
|
||||
fd = try os.open(file_path, os.O_RDONLY | os.O_DIRECTORY, mode);
|
||||
fd = try os.open(file_path, os.O.RDONLY | os.O.DIRECTORY, mode);
|
||||
os.close(fd);
|
||||
|
||||
// Try opening as file which should fail.
|
||||
file_path = try fs.path.join(&arena.allocator, &[_][]const u8{ base_path, "some_dir" });
|
||||
try expectError(error.IsDir, os.open(file_path, os.O_RDWR, mode));
|
||||
try expectError(error.IsDir, os.open(file_path, os.O.RDWR, mode));
|
||||
}
|
||||
|
||||
test "openat smoke test" {
|
||||
@ -112,28 +112,28 @@ test "openat smoke test" {
|
||||
const mode: os.mode_t = if (native_os == .windows) 0 else 0o666;
|
||||
|
||||
// Create some file using `openat`.
|
||||
fd = try os.openat(tmp.dir.fd, "some_file", os.O_RDWR | os.O_CREAT | os.O_EXCL, mode);
|
||||
fd = try os.openat(tmp.dir.fd, "some_file", os.O.RDWR | os.O.CREAT | os.O.EXCL, mode);
|
||||
os.close(fd);
|
||||
|
||||
// Try this again with the same flags. This op should fail with error.PathAlreadyExists.
|
||||
try expectError(error.PathAlreadyExists, os.openat(tmp.dir.fd, "some_file", os.O_RDWR | os.O_CREAT | os.O_EXCL, mode));
|
||||
try expectError(error.PathAlreadyExists, os.openat(tmp.dir.fd, "some_file", os.O.RDWR | os.O.CREAT | os.O.EXCL, mode));
|
||||
|
||||
// Try opening without `O_EXCL` flag.
|
||||
fd = try os.openat(tmp.dir.fd, "some_file", os.O_RDWR | os.O_CREAT, mode);
|
||||
// Try opening without `O.EXCL` flag.
|
||||
fd = try os.openat(tmp.dir.fd, "some_file", os.O.RDWR | os.O.CREAT, mode);
|
||||
os.close(fd);
|
||||
|
||||
// Try opening as a directory which should fail.
|
||||
try expectError(error.NotDir, os.openat(tmp.dir.fd, "some_file", os.O_RDWR | os.O_DIRECTORY, mode));
|
||||
try expectError(error.NotDir, os.openat(tmp.dir.fd, "some_file", os.O.RDWR | os.O.DIRECTORY, mode));
|
||||
|
||||
// Create some directory
|
||||
try os.mkdirat(tmp.dir.fd, "some_dir", mode);
|
||||
|
||||
// Open dir using `open`
|
||||
fd = try os.openat(tmp.dir.fd, "some_dir", os.O_RDONLY | os.O_DIRECTORY, mode);
|
||||
fd = try os.openat(tmp.dir.fd, "some_dir", os.O.RDONLY | os.O.DIRECTORY, mode);
|
||||
os.close(fd);
|
||||
|
||||
// Try opening as file which should fail.
|
||||
try expectError(error.IsDir, os.openat(tmp.dir.fd, "some_dir", os.O_RDWR, mode));
|
||||
try expectError(error.IsDir, os.openat(tmp.dir.fd, "some_dir", os.O.RDWR, mode));
|
||||
}
|
||||
|
||||
test "symlink with relative paths" {
|
||||
@ -273,7 +273,7 @@ test "fstatat" {
|
||||
defer file.close();
|
||||
|
||||
// now repeat but using `fstatat` instead
|
||||
const flags = if (native_os == .wasi) 0x0 else os.AT_SYMLINK_NOFOLLOW;
|
||||
const flags = if (native_os == .wasi) 0x0 else os.AT.SYMLINK_NOFOLLOW;
|
||||
const statat = try os.fstatat(tmp.dir.fd, "file.txt", flags);
|
||||
try expectEqual(stat, statat);
|
||||
}
|
||||
@ -508,8 +508,8 @@ test "mmap" {
|
||||
const data = try os.mmap(
|
||||
null,
|
||||
1234,
|
||||
os.PROT_READ | os.PROT_WRITE,
|
||||
os.MAP_ANONYMOUS | os.MAP_PRIVATE,
|
||||
os.PROT.READ | os.PROT.WRITE,
|
||||
os.MAP.ANONYMOUS | os.MAP.PRIVATE,
|
||||
-1,
|
||||
0,
|
||||
);
|
||||
@ -550,8 +550,8 @@ test "mmap" {
|
||||
const data = try os.mmap(
|
||||
null,
|
||||
alloc_size,
|
||||
os.PROT_READ,
|
||||
os.MAP_PRIVATE,
|
||||
os.PROT.READ,
|
||||
os.MAP.PRIVATE,
|
||||
file.handle,
|
||||
0,
|
||||
);
|
||||
@ -574,8 +574,8 @@ test "mmap" {
|
||||
const data = try os.mmap(
|
||||
null,
|
||||
alloc_size / 2,
|
||||
os.PROT_READ,
|
||||
os.MAP_PRIVATE,
|
||||
os.PROT.READ,
|
||||
os.MAP.PRIVATE,
|
||||
file.handle,
|
||||
alloc_size / 2,
|
||||
);
|
||||
@ -616,19 +616,19 @@ test "fcntl" {
|
||||
tmp.dir.deleteFile(test_out_file) catch {};
|
||||
}
|
||||
|
||||
// Note: The test assumes createFile opens the file with O_CLOEXEC
|
||||
// Note: The test assumes createFile opens the file with O.CLOEXEC
|
||||
{
|
||||
const flags = try os.fcntl(file.handle, os.F_GETFD, 0);
|
||||
const flags = try os.fcntl(file.handle, os.F.GETFD, 0);
|
||||
try expect((flags & os.FD_CLOEXEC) != 0);
|
||||
}
|
||||
{
|
||||
_ = try os.fcntl(file.handle, os.F_SETFD, 0);
|
||||
const flags = try os.fcntl(file.handle, os.F_GETFD, 0);
|
||||
_ = try os.fcntl(file.handle, os.F.SETFD, 0);
|
||||
const flags = try os.fcntl(file.handle, os.F.GETFD, 0);
|
||||
try expect((flags & os.FD_CLOEXEC) == 0);
|
||||
}
|
||||
{
|
||||
_ = try os.fcntl(file.handle, os.F_SETFD, os.FD_CLOEXEC);
|
||||
const flags = try os.fcntl(file.handle, os.F_GETFD, 0);
|
||||
_ = try os.fcntl(file.handle, os.F.SETFD, os.FD_CLOEXEC);
|
||||
const flags = try os.fcntl(file.handle, os.F.GETFD, 0);
|
||||
try expect((flags & os.FD_CLOEXEC) != 0);
|
||||
}
|
||||
}
|
||||
@ -698,7 +698,7 @@ test "shutdown socket" {
|
||||
std.os.windows.WSACleanup() catch unreachable;
|
||||
}
|
||||
}
|
||||
const sock = try os.socket(os.AF_INET, os.SOCK_STREAM, 0);
|
||||
const sock = try os.socket(os.AF.INET, os.SOCK.STREAM, 0);
|
||||
os.shutdown(sock, .both) catch |err| switch (err) {
|
||||
error.SocketNotConnected => {},
|
||||
else => |e| return e,
|
||||
@ -722,11 +722,11 @@ test "sigaction" {
|
||||
// Check that we received the correct signal.
|
||||
switch (native_os) {
|
||||
.netbsd => {
|
||||
if (sig == os.SIGUSR1 and sig == info.info.signo)
|
||||
if (sig == os.SIG.USR1 and sig == info.info.signo)
|
||||
signal_test_failed = false;
|
||||
},
|
||||
else => {
|
||||
if (sig == os.SIGUSR1 and sig == info.signo)
|
||||
if (sig == os.SIG.USR1 and sig == info.signo)
|
||||
signal_test_failed = false;
|
||||
},
|
||||
}
|
||||
@ -736,21 +736,21 @@ test "sigaction" {
|
||||
var sa = os.Sigaction{
|
||||
.handler = .{ .sigaction = S.handler },
|
||||
.mask = os.empty_sigset,
|
||||
.flags = os.SA_SIGINFO | os.SA_RESETHAND,
|
||||
.flags = os.SA.SIGINFO | os.SA.RESETHAND,
|
||||
};
|
||||
var old_sa: os.Sigaction = undefined;
|
||||
// Install the new signal handler.
|
||||
os.sigaction(os.SIGUSR1, &sa, null);
|
||||
os.sigaction(os.SIG.USR1, &sa, null);
|
||||
// Check that we can read it back correctly.
|
||||
os.sigaction(os.SIGUSR1, null, &old_sa);
|
||||
os.sigaction(os.SIG.USR1, null, &old_sa);
|
||||
try testing.expectEqual(S.handler, old_sa.handler.sigaction.?);
|
||||
try testing.expect((old_sa.flags & os.SA_SIGINFO) != 0);
|
||||
try testing.expect((old_sa.flags & os.SA.SIGINFO) != 0);
|
||||
// Invoke the handler.
|
||||
try os.raise(os.SIGUSR1);
|
||||
try os.raise(os.SIG.USR1);
|
||||
try testing.expect(signal_test_failed == false);
|
||||
// Check if the handler has been correctly reset to SIG_DFL
|
||||
os.sigaction(os.SIGUSR1, null, &old_sa);
|
||||
try testing.expectEqual(os.SIG_DFL, old_sa.handler.sigaction);
|
||||
os.sigaction(os.SIG.USR1, null, &old_sa);
|
||||
try testing.expectEqual(os.SIG.DFL, old_sa.handler.sigaction);
|
||||
}
|
||||
|
||||
test "dup & dup2" {
|
||||
|
||||
@ -382,8 +382,14 @@ pub const prestat_u_t = extern union {
|
||||
};
|
||||
|
||||
pub const riflags_t = u16;
|
||||
pub const SOCK_RECV_PEEK: riflags_t = 0x0001;
|
||||
pub const SOCK_RECV_WAITALL: riflags_t = 0x0002;
|
||||
pub const roflags_t = u16;
|
||||
|
||||
pub const SOCK = struct {
|
||||
pub const RECV_PEEK: riflags_t = 0x0001;
|
||||
pub const RECV_WAITALL: riflags_t = 0x0002;
|
||||
|
||||
pub const RECV_DATA_TRUNCATED: roflags_t = 0x0001;
|
||||
};
|
||||
|
||||
pub const rights_t = u64;
|
||||
pub const RIGHT_FD_DATASYNC: rights_t = 0x0000000000000001;
|
||||
@ -445,9 +451,6 @@ pub const RIGHT_ALL: rights_t = RIGHT_FD_DATASYNC |
|
||||
RIGHT_POLL_FD_READWRITE |
|
||||
RIGHT_SOCK_SHUTDOWN;
|
||||
|
||||
pub const roflags_t = u16;
|
||||
pub const SOCK_RECV_DATA_TRUNCATED: roflags_t = 0x0001;
|
||||
|
||||
pub const sdflags_t = u8;
|
||||
pub const SHUT_RD: sdflags_t = 0x01;
|
||||
pub const SHUT_WR: sdflags_t = 0x02;
|
||||
@ -541,7 +544,9 @@ pub const SEEK_SET = WHENCE_SET;
|
||||
pub const SEEK_CUR = WHENCE_CUR;
|
||||
pub const SEEK_END = WHENCE_END;
|
||||
|
||||
pub const LOCK_SH = 0x1;
|
||||
pub const LOCK_EX = 0x2;
|
||||
pub const LOCK_NB = 0x4;
|
||||
pub const LOCK_UN = 0x8;
|
||||
pub const LOCK = struct {
|
||||
pub const SH = 0x1;
|
||||
pub const EX = 0x2;
|
||||
pub const NB = 0x4;
|
||||
pub const UN = 0x8;
|
||||
};
|
||||
|
||||
@ -178,7 +178,6 @@ pub const RIO_CORRUPT_CQ = 4294967295;
|
||||
pub const WINDOWS_AF_IRDA = 26;
|
||||
pub const WCE_AF_IRDA = 22;
|
||||
pub const IRDA_PROTO_SOCK_STREAM = 1;
|
||||
pub const SOL_IRLMP = 255;
|
||||
pub const IRLMP_ENUMDEVICES = 16;
|
||||
pub const IRLMP_IAS_SET = 17;
|
||||
pub const IRLMP_IAS_QUERY = 18;
|
||||
@ -237,7 +236,6 @@ pub const IPX_MAX_ADAPTER_NUM = 16397;
|
||||
pub const IPX_RERIPNETNUMBER = 16398;
|
||||
pub const IPX_RECEIVE_BROADCAST = 16399;
|
||||
pub const IPX_IMMEDIATESPXACK = 16400;
|
||||
pub const IPPROTO_RM = 113;
|
||||
pub const MAX_MCAST_TTL = 255;
|
||||
pub const RM_OPTIONSBASE = 1000;
|
||||
pub const RM_RATE_WINDOW_SIZE = 1001;
|
||||
@ -449,75 +447,117 @@ pub const TCP_ICMP_ERROR_INFO = 19;
|
||||
pub const UDP_SEND_MSG_SIZE = 2;
|
||||
pub const UDP_RECV_MAX_COALESCED_SIZE = 3;
|
||||
pub const UDP_COALESCED_INFO = 3;
|
||||
pub const AF_UNSPEC = 0;
|
||||
pub const AF_UNIX = 1;
|
||||
pub const AF_INET = 2;
|
||||
pub const AF_IMPLINK = 3;
|
||||
pub const AF_PUP = 4;
|
||||
pub const AF_CHAOS = 5;
|
||||
pub const AF_NS = 6;
|
||||
pub const AF_ISO = 7;
|
||||
pub const AF_ECMA = 8;
|
||||
pub const AF_DATAKIT = 9;
|
||||
pub const AF_CCITT = 10;
|
||||
pub const AF_SNA = 11;
|
||||
pub const AF_DECnet = 12;
|
||||
pub const AF_DLI = 13;
|
||||
pub const AF_LAT = 14;
|
||||
pub const AF_HYLINK = 15;
|
||||
pub const AF_APPLETALK = 16;
|
||||
pub const AF_NETBIOS = 17;
|
||||
pub const AF_VOICEVIEW = 18;
|
||||
pub const AF_FIREFOX = 19;
|
||||
pub const AF_UNKNOWN1 = 20;
|
||||
pub const AF_BAN = 21;
|
||||
pub const AF_ATM = 22;
|
||||
pub const AF_INET6 = 23;
|
||||
pub const AF_CLUSTER = 24;
|
||||
pub const AF_12844 = 25;
|
||||
pub const AF_IRDA = 26;
|
||||
pub const AF_NETDES = 28;
|
||||
pub const AF_MAX = 29;
|
||||
pub const AF_TCNPROCESS = 29;
|
||||
pub const AF_TCNMESSAGE = 30;
|
||||
pub const AF_ICLFXBM = 31;
|
||||
pub const AF_LINK = 33;
|
||||
pub const AF_HYPERV = 34;
|
||||
pub const SOCK_STREAM = 1;
|
||||
pub const SOCK_DGRAM = 2;
|
||||
pub const SOCK_RAW = 3;
|
||||
pub const SOCK_RDM = 4;
|
||||
pub const SOCK_SEQPACKET = 5;
|
||||
pub const SOL_SOCKET = 65535;
|
||||
pub const SO_DEBUG = 1;
|
||||
pub const SO_ACCEPTCONN = 2;
|
||||
pub const SO_REUSEADDR = 4;
|
||||
pub const SO_KEEPALIVE = 8;
|
||||
pub const SO_DONTROUTE = 16;
|
||||
pub const SO_BROADCAST = 32;
|
||||
pub const SO_USELOOPBACK = 64;
|
||||
pub const SO_LINGER = 128;
|
||||
pub const SO_OOBINLINE = 256;
|
||||
pub const SO_SNDBUF = 4097;
|
||||
pub const SO_RCVBUF = 4098;
|
||||
pub const SO_SNDLOWAT = 4099;
|
||||
pub const SO_RCVLOWAT = 4100;
|
||||
pub const SO_SNDTIMEO = 4101;
|
||||
pub const SO_RCVTIMEO = 4102;
|
||||
pub const SO_ERROR = 4103;
|
||||
pub const SO_TYPE = 4104;
|
||||
pub const SO_BSP_STATE = 4105;
|
||||
pub const SO_GROUP_ID = 8193;
|
||||
pub const SO_GROUP_PRIORITY = 8194;
|
||||
pub const SO_MAX_MSG_SIZE = 8195;
|
||||
pub const SO_CONDITIONAL_ACCEPT = 12290;
|
||||
pub const SO_PAUSE_ACCEPT = 12291;
|
||||
pub const SO_COMPARTMENT_ID = 12292;
|
||||
pub const SO_RANDOMIZE_PORT = 12293;
|
||||
pub const SO_PORT_SCALABILITY = 12294;
|
||||
pub const SO_REUSE_UNICASTPORT = 12295;
|
||||
pub const SO_REUSE_MULTICASTPORT = 12296;
|
||||
pub const SO_ORIGINAL_DST = 12303;
|
||||
|
||||
pub const AF = struct {
|
||||
pub const UNSPEC = 0;
|
||||
pub const UNIX = 1;
|
||||
pub const INET = 2;
|
||||
pub const IMPLINK = 3;
|
||||
pub const PUP = 4;
|
||||
pub const CHAOS = 5;
|
||||
pub const NS = 6;
|
||||
pub const IPX = 6;
|
||||
pub const ISO = 7;
|
||||
pub const ECMA = 8;
|
||||
pub const DATAKIT = 9;
|
||||
pub const CCITT = 10;
|
||||
pub const SNA = 11;
|
||||
pub const DECnet = 12;
|
||||
pub const DLI = 13;
|
||||
pub const LAT = 14;
|
||||
pub const HYLINK = 15;
|
||||
pub const APPLETALK = 16;
|
||||
pub const NETBIOS = 17;
|
||||
pub const VOICEVIEW = 18;
|
||||
pub const FIREFOX = 19;
|
||||
pub const UNKNOWN1 = 20;
|
||||
pub const BAN = 21;
|
||||
pub const ATM = 22;
|
||||
pub const INET6 = 23;
|
||||
pub const CLUSTER = 24;
|
||||
pub const @"12844" = 25;
|
||||
pub const IRDA = 26;
|
||||
pub const NETDES = 28;
|
||||
pub const MAX = 29;
|
||||
pub const TCNPROCESS = 29;
|
||||
pub const TCNMESSAGE = 30;
|
||||
pub const ICLFXBM = 31;
|
||||
pub const LINK = 33;
|
||||
pub const HYPERV = 34;
|
||||
};
|
||||
|
||||
pub const SOCK = struct {
|
||||
pub const STREAM = 1;
|
||||
pub const DGRAM = 2;
|
||||
pub const RAW = 3;
|
||||
pub const RDM = 4;
|
||||
pub const SEQPACKET = 5;
|
||||
|
||||
/// WARNING: this flag is not supported by windows socket functions directly,
|
||||
/// it is only supported by std.os.socket. Be sure that this value does
|
||||
/// not share any bits with any of the `SOCK` values.
|
||||
pub const CLOEXEC = 0x10000;
|
||||
/// WARNING: this flag is not supported by windows socket functions directly,
|
||||
/// it is only supported by std.os.socket. Be sure that this value does
|
||||
/// not share any bits with any of the `SOCK` values.
|
||||
pub const NONBLOCK = 0x20000;
|
||||
};
|
||||
|
||||
pub const SOL = struct {
|
||||
pub const IRLMP = 255;
|
||||
pub const SOCKET = 65535;
|
||||
};
|
||||
|
||||
pub const SO = struct {
|
||||
pub const DEBUG = 1;
|
||||
pub const ACCEPTCONN = 2;
|
||||
pub const REUSEADDR = 4;
|
||||
pub const KEEPALIVE = 8;
|
||||
pub const DONTROUTE = 16;
|
||||
pub const BROADCAST = 32;
|
||||
pub const USELOOPBACK = 64;
|
||||
pub const LINGER = 128;
|
||||
pub const OOBINLINE = 256;
|
||||
pub const SNDBUF = 4097;
|
||||
pub const RCVBUF = 4098;
|
||||
pub const SNDLOWAT = 4099;
|
||||
pub const RCVLOWAT = 4100;
|
||||
pub const SNDTIMEO = 4101;
|
||||
pub const RCVTIMEO = 4102;
|
||||
pub const ERROR = 4103;
|
||||
pub const TYPE = 4104;
|
||||
pub const BSP_STATE = 4105;
|
||||
pub const GROUP_ID = 8193;
|
||||
pub const GROUP_PRIORITY = 8194;
|
||||
pub const MAX_MSG_SIZE = 8195;
|
||||
pub const CONDITIONAL_ACCEPT = 12290;
|
||||
pub const PAUSE_ACCEPT = 12291;
|
||||
pub const COMPARTMENT_ID = 12292;
|
||||
pub const RANDOMIZE_PORT = 12293;
|
||||
pub const PORT_SCALABILITY = 12294;
|
||||
pub const REUSE_UNICASTPORT = 12295;
|
||||
pub const REUSE_MULTICASTPORT = 12296;
|
||||
pub const ORIGINAL_DST = 12303;
|
||||
pub const PROTOCOL_INFOA = 8196;
|
||||
pub const PROTOCOL_INFOW = 8197;
|
||||
pub const CONNDATA = 28672;
|
||||
pub const CONNOPT = 28673;
|
||||
pub const DISCDATA = 28674;
|
||||
pub const DISCOPT = 28675;
|
||||
pub const CONNDATALEN = 28676;
|
||||
pub const CONNOPTLEN = 28677;
|
||||
pub const DISCDATALEN = 28678;
|
||||
pub const DISCOPTLEN = 28679;
|
||||
pub const OPENTYPE = 28680;
|
||||
pub const SYNCHRONOUS_ALERT = 16;
|
||||
pub const SYNCHRONOUS_NONALERT = 32;
|
||||
pub const MAXDG = 28681;
|
||||
pub const MAXPATHDG = 28682;
|
||||
pub const UPDATE_ACCEPT_CONTEXT = 28683;
|
||||
pub const CONNECT_TIME = 28684;
|
||||
pub const UPDATE_CONNECT_CONTEXT = 28688;
|
||||
};
|
||||
|
||||
pub const WSK_SO_BASE = 16384;
|
||||
pub const TCP_NODELAY = 1;
|
||||
pub const IOC_UNIX = 0;
|
||||
@ -529,7 +569,6 @@ pub const SIO_BSP_HANDLE = IOC_OUT | IOC_WS2 | 27;
|
||||
pub const SIO_BSP_HANDLE_SELECT = IOC_OUT | IOC_WS2 | 28;
|
||||
pub const SIO_BSP_HANDLE_POLL = IOC_OUT | IOC_WS2 | 29;
|
||||
pub const SIO_BASE_HANDLE = IOC_OUT | IOC_WS2 | 34;
|
||||
pub const IPPROTO_IP = 0;
|
||||
pub const IPPORT_TCPMUX = 1;
|
||||
pub const IPPORT_ECHO = 7;
|
||||
pub const IPPORT_DISCARD = 9;
|
||||
@ -596,27 +635,41 @@ pub const IOCPARM_MASK = 127;
|
||||
pub const IOC_VOID = 536870912;
|
||||
pub const IOC_OUT = 1073741824;
|
||||
pub const IOC_IN = 2147483648;
|
||||
pub const MSG_TRUNC = 256;
|
||||
pub const MSG_CTRUNC = 512;
|
||||
pub const MSG_BCAST = 1024;
|
||||
pub const MSG_MCAST = 2048;
|
||||
pub const MSG_ERRQUEUE = 4096;
|
||||
pub const AI_PASSIVE = 1;
|
||||
pub const AI_CANONNAME = 2;
|
||||
pub const AI_NUMERICHOST = 4;
|
||||
pub const AI_NUMERICSERV = 8;
|
||||
pub const AI_DNS_ONLY = 16;
|
||||
pub const AI_ALL = 256;
|
||||
pub const AI_ADDRCONFIG = 1024;
|
||||
pub const AI_V4MAPPED = 2048;
|
||||
pub const AI_NON_AUTHORITATIVE = 16384;
|
||||
pub const AI_SECURE = 32768;
|
||||
pub const AI_RETURN_PREFERRED_NAMES = 65536;
|
||||
pub const AI_FQDN = 131072;
|
||||
pub const AI_FILESERVER = 262144;
|
||||
pub const AI_DISABLE_IDN_ENCODING = 524288;
|
||||
pub const AI_EXTENDED = 2147483648;
|
||||
pub const AI_RESOLUTION_HANDLE = 1073741824;
|
||||
|
||||
pub const MSG = struct {
|
||||
pub const TRUNC = 256;
|
||||
pub const CTRUNC = 512;
|
||||
pub const BCAST = 1024;
|
||||
pub const MCAST = 2048;
|
||||
pub const ERRQUEUE = 4096;
|
||||
|
||||
pub const PEEK = 2;
|
||||
pub const WAITALL = 8;
|
||||
pub const PUSH_IMMEDIATE = 32;
|
||||
pub const PARTIAL = 32768;
|
||||
pub const INTERRUPT = 16;
|
||||
pub const MAXIOVLEN = 16;
|
||||
};
|
||||
|
||||
pub const AI = struct {
|
||||
pub const PASSIVE = 1;
|
||||
pub const CANONNAME = 2;
|
||||
pub const NUMERICHOST = 4;
|
||||
pub const NUMERICSERV = 8;
|
||||
pub const DNS_ONLY = 16;
|
||||
pub const ALL = 256;
|
||||
pub const ADDRCONFIG = 1024;
|
||||
pub const V4MAPPED = 2048;
|
||||
pub const NON_AUTHORITATIVE = 16384;
|
||||
pub const SECURE = 32768;
|
||||
pub const RETURN_PREFERRED_NAMES = 65536;
|
||||
pub const FQDN = 131072;
|
||||
pub const FILESERVER = 262144;
|
||||
pub const DISABLE_IDN_ENCODING = 524288;
|
||||
pub const EXTENDED = 2147483648;
|
||||
pub const RESOLUTION_HANDLE = 1073741824;
|
||||
};
|
||||
|
||||
pub const FIONBIO = -2147195266;
|
||||
pub const ADDRINFOEX_VERSION_2 = 2;
|
||||
pub const ADDRINFOEX_VERSION_3 = 3;
|
||||
@ -660,16 +713,8 @@ pub const WSADESCRIPTION_LEN = 256;
|
||||
pub const WSASYS_STATUS_LEN = 128;
|
||||
pub const SOCKET_ERROR = -1;
|
||||
pub const FROM_PROTOCOL_INFO = -1;
|
||||
pub const SO_PROTOCOL_INFOA = 8196;
|
||||
pub const SO_PROTOCOL_INFOW = 8197;
|
||||
pub const PVD_CONFIG = 12289;
|
||||
pub const SOMAXCONN = 2147483647;
|
||||
pub const MSG_PEEK = 2;
|
||||
pub const MSG_WAITALL = 8;
|
||||
pub const MSG_PUSH_IMMEDIATE = 32;
|
||||
pub const MSG_PARTIAL = 32768;
|
||||
pub const MSG_INTERRUPT = 16;
|
||||
pub const MSG_MAXIOVLEN = 16;
|
||||
pub const MAXGETHOSTSTRUCT = 1024;
|
||||
pub const FD_READ_BIT = 0;
|
||||
pub const FD_WRITE_BIT = 1;
|
||||
@ -770,30 +815,18 @@ pub const RESULT_IS_ALIAS = 1;
|
||||
pub const RESULT_IS_ADDED = 16;
|
||||
pub const RESULT_IS_CHANGED = 32;
|
||||
pub const RESULT_IS_DELETED = 64;
|
||||
pub const POLLRDNORM = 256;
|
||||
pub const POLLRDBAND = 512;
|
||||
pub const POLLPRI = 1024;
|
||||
pub const POLLWRNORM = 16;
|
||||
pub const POLLWRBAND = 32;
|
||||
pub const POLLERR = 1;
|
||||
pub const POLLHUP = 2;
|
||||
pub const POLLNVAL = 4;
|
||||
pub const SO_CONNDATA = 28672;
|
||||
pub const SO_CONNOPT = 28673;
|
||||
pub const SO_DISCDATA = 28674;
|
||||
pub const SO_DISCOPT = 28675;
|
||||
pub const SO_CONNDATALEN = 28676;
|
||||
pub const SO_CONNOPTLEN = 28677;
|
||||
pub const SO_DISCDATALEN = 28678;
|
||||
pub const SO_DISCOPTLEN = 28679;
|
||||
pub const SO_OPENTYPE = 28680;
|
||||
pub const SO_SYNCHRONOUS_ALERT = 16;
|
||||
pub const SO_SYNCHRONOUS_NONALERT = 32;
|
||||
pub const SO_MAXDG = 28681;
|
||||
pub const SO_MAXPATHDG = 28682;
|
||||
pub const SO_UPDATE_ACCEPT_CONTEXT = 28683;
|
||||
pub const SO_CONNECT_TIME = 28684;
|
||||
pub const SO_UPDATE_CONNECT_CONTEXT = 28688;
|
||||
|
||||
pub const POLL = struct {
|
||||
pub const RDNORM = 256;
|
||||
pub const RDBAND = 512;
|
||||
pub const PRI = 1024;
|
||||
pub const WRNORM = 16;
|
||||
pub const WRBAND = 32;
|
||||
pub const ERR = 1;
|
||||
pub const HUP = 2;
|
||||
pub const NVAL = 4;
|
||||
};
|
||||
|
||||
pub const TCP_BSDURGENT = 28672;
|
||||
pub const TF_DISCONNECT = 1;
|
||||
pub const TF_REUSE_SOCKET = 2;
|
||||
@ -817,20 +850,25 @@ pub const LSP_INBOUND_MODIFY = 16;
|
||||
pub const LSP_OUTBOUND_MODIFY = 32;
|
||||
pub const LSP_CRYPTO_COMPRESS = 64;
|
||||
pub const LSP_LOCAL_CACHE = 128;
|
||||
pub const IPPROTO_ICMP = 1;
|
||||
pub const IPPROTO_IGMP = 2;
|
||||
pub const IPPROTO_GGP = 3;
|
||||
pub const IPPROTO_TCP = 6;
|
||||
pub const IPPROTO_PUP = 12;
|
||||
pub const IPPROTO_UDP = 17;
|
||||
pub const IPPROTO_IDP = 22;
|
||||
pub const IPPROTO_ND = 77;
|
||||
pub const IPPROTO_RAW = 255;
|
||||
pub const IPPROTO_MAX = 256;
|
||||
|
||||
pub const IPPROTO = struct {
|
||||
pub const IP = 0;
|
||||
pub const ICMP = 1;
|
||||
pub const IGMP = 2;
|
||||
pub const GGP = 3;
|
||||
pub const TCP = 6;
|
||||
pub const PUP = 12;
|
||||
pub const UDP = 17;
|
||||
pub const IDP = 22;
|
||||
pub const ND = 77;
|
||||
pub const RM = 113;
|
||||
pub const RAW = 255;
|
||||
pub const MAX = 256;
|
||||
};
|
||||
|
||||
pub const IP_DEFAULT_MULTICAST_TTL = 1;
|
||||
pub const IP_DEFAULT_MULTICAST_LOOP = 1;
|
||||
pub const IP_MAX_MEMBERSHIPS = 20;
|
||||
pub const AF_IPX = 6;
|
||||
pub const FD_READ = 1;
|
||||
pub const FD_WRITE = 2;
|
||||
pub const FD_OOB = 4;
|
||||
@ -1051,31 +1089,31 @@ pub const addrinfoexA = extern struct {
|
||||
pub const sockaddr = extern struct {
|
||||
family: ADDRESS_FAMILY,
|
||||
data: [14]u8,
|
||||
};
|
||||
|
||||
pub const sockaddr_storage = std.x.os.Socket.Address.Native.Storage;
|
||||
pub const storage = std.x.os.Socket.Address.Native.Storage;
|
||||
|
||||
/// IPv4 socket address
|
||||
pub const sockaddr_in = extern struct {
|
||||
family: ADDRESS_FAMILY = AF_INET,
|
||||
port: USHORT,
|
||||
addr: u32,
|
||||
zero: [8]u8 = [8]u8{ 0, 0, 0, 0, 0, 0, 0, 0 },
|
||||
};
|
||||
/// IPv4 socket address
|
||||
pub const in = extern struct {
|
||||
family: ADDRESS_FAMILY = AF.INET,
|
||||
port: USHORT,
|
||||
addr: u32,
|
||||
zero: [8]u8 = [8]u8{ 0, 0, 0, 0, 0, 0, 0, 0 },
|
||||
};
|
||||
|
||||
/// IPv6 socket address
|
||||
pub const sockaddr_in6 = extern struct {
|
||||
family: ADDRESS_FAMILY = AF_INET6,
|
||||
port: USHORT,
|
||||
flowinfo: u32,
|
||||
addr: [16]u8,
|
||||
scope_id: u32,
|
||||
};
|
||||
/// IPv6 socket address
|
||||
pub const in6 = extern struct {
|
||||
family: ADDRESS_FAMILY = AF.INET6,
|
||||
port: USHORT,
|
||||
flowinfo: u32,
|
||||
addr: [16]u8,
|
||||
scope_id: u32,
|
||||
};
|
||||
|
||||
/// UNIX domain socket address
|
||||
pub const sockaddr_un = extern struct {
|
||||
family: ADDRESS_FAMILY = AF_UNIX,
|
||||
path: [108]u8,
|
||||
/// UNIX domain socket address
|
||||
pub const un = extern struct {
|
||||
family: ADDRESS_FAMILY = AF.UNIX,
|
||||
path: [108]u8,
|
||||
};
|
||||
};
|
||||
|
||||
pub const WSABUF = extern struct {
|
||||
@ -1237,9 +1275,9 @@ pub const WinsockError = enum(u16) {
|
||||
|
||||
/// Permission denied.
|
||||
/// An attempt was made to access a socket in a way forbidden by its access permissions.
|
||||
/// An example is using a broadcast address for sendto without broadcast permission being set using setsockopt(SO_BROADCAST).
|
||||
/// An example is using a broadcast address for sendto without broadcast permission being set using setsockopt(SO.BROADCAST).
|
||||
/// Another possible reason for the WSAEACCES error is that when the bind function is called (on Windows NT 4.0 with SP4 and later), another application, service, or kernel mode driver is bound to the same address with exclusive access.
|
||||
/// Such exclusive access is a new feature of Windows NT 4.0 with SP4 and later, and is implemented by using the SO_EXCLUSIVEADDRUSE option.
|
||||
/// Such exclusive access is a new feature of Windows NT 4.0 with SP4 and later, and is implemented by using the SO.EXCLUSIVEADDRUSE option.
|
||||
WSAEACCES = 10013,
|
||||
|
||||
/// Bad address.
|
||||
@ -1260,7 +1298,7 @@ pub const WinsockError = enum(u16) {
|
||||
/// Resource temporarily unavailable.
|
||||
/// This error is returned from operations on nonblocking sockets that cannot be completed immediately, for example recv when no data is queued to be read from the socket.
|
||||
/// It is a nonfatal error, and the operation should be retried later.
|
||||
/// It is normal for WSAEWOULDBLOCK to be reported as the result from calling connect on a nonblocking SOCK_STREAM socket, since some time must elapse for the connection to be established.
|
||||
/// It is normal for WSAEWOULDBLOCK to be reported as the result from calling connect on a nonblocking SOCK.STREAM socket, since some time must elapse for the connection to be established.
|
||||
WSAEWOULDBLOCK = 10035,
|
||||
|
||||
/// Operation now in progress.
|
||||
@ -1288,7 +1326,7 @@ pub const WinsockError = enum(u16) {
|
||||
|
||||
/// Protocol wrong type for socket.
|
||||
/// A protocol was specified in the socket function call that does not support the semantics of the socket type requested.
|
||||
/// For example, the ARPA Internet UDP protocol cannot be specified with a socket type of SOCK_STREAM.
|
||||
/// For example, the ARPA Internet UDP protocol cannot be specified with a socket type of SOCK.STREAM.
|
||||
WSAEPROTOTYPE = 10041,
|
||||
|
||||
/// Bad protocol option.
|
||||
@ -1297,12 +1335,12 @@ pub const WinsockError = enum(u16) {
|
||||
|
||||
/// Protocol not supported.
|
||||
/// The requested protocol has not been configured into the system, or no implementation for it exists.
|
||||
/// For example, a socket call requests a SOCK_DGRAM socket, but specifies a stream protocol.
|
||||
/// For example, a socket call requests a SOCK.DGRAM socket, but specifies a stream protocol.
|
||||
WSAEPROTONOSUPPORT = 10043,
|
||||
|
||||
/// Socket type not supported.
|
||||
/// The support for the specified socket type does not exist in this address family.
|
||||
/// For example, the optional type SOCK_RAW might be selected in a socket call, and the implementation does not support SOCK_RAW sockets at all.
|
||||
/// For example, the optional type SOCK.RAW might be selected in a socket call, and the implementation does not support SOCK.RAW sockets at all.
|
||||
WSAESOCKTNOSUPPORT = 10044,
|
||||
|
||||
/// Operation not supported.
|
||||
@ -1318,14 +1356,14 @@ pub const WinsockError = enum(u16) {
|
||||
|
||||
/// Address family not supported by protocol family.
|
||||
/// An address incompatible with the requested protocol was used.
|
||||
/// All sockets are created with an associated address family (that is, AF_INET for Internet Protocols) and a generic protocol type (that is, SOCK_STREAM).
|
||||
/// All sockets are created with an associated address family (that is, AF.INET for Internet Protocols) and a generic protocol type (that is, SOCK.STREAM).
|
||||
/// This error is returned if an incorrect protocol is explicitly requested in the socket call, or if an address of the wrong family is used for a socket, for example, in sendto.
|
||||
WSAEAFNOSUPPORT = 10047,
|
||||
|
||||
/// Address already in use.
|
||||
/// Typically, only one usage of each socket address (protocol/IP address/port) is permitted.
|
||||
/// This error occurs if an application attempts to bind a socket to an IP address/port that has already been used for an existing socket, or a socket that was not closed properly, or one that is still in the process of closing.
|
||||
/// For server applications that need to bind multiple sockets to the same port number, consider using setsockopt (SO_REUSEADDR).
|
||||
/// For server applications that need to bind multiple sockets to the same port number, consider using setsockopt (SO.REUSEADDR).
|
||||
/// Client applications usually need not call bind at all—connect chooses an unused port automatically.
|
||||
/// When bind is called with a wildcard address (involving ADDR_ANY), a WSAEADDRINUSE error could be delayed until the specific address is committed.
|
||||
/// This could happen with a call to another function later, including connect, listen, WSAConnect, or WSAJoinLeaf.
|
||||
@ -1349,7 +1387,7 @@ pub const WinsockError = enum(u16) {
|
||||
|
||||
/// Network dropped connection on reset.
|
||||
/// The connection has been broken due to keep-alive activity detecting a failure while the operation was in progress.
|
||||
/// It can also be returned by setsockopt if an attempt is made to set SO_KEEPALIVE on a connection that has already failed.
|
||||
/// It can also be returned by setsockopt if an attempt is made to set SO.KEEPALIVE on a connection that has already failed.
|
||||
WSAENETRESET = 10052,
|
||||
|
||||
/// Software caused connection abort.
|
||||
@ -1358,7 +1396,7 @@ pub const WinsockError = enum(u16) {
|
||||
|
||||
/// Connection reset by peer.
|
||||
/// An existing connection was forcibly closed by the remote host.
|
||||
/// This normally results if the peer application on the remote host is suddenly stopped, the host is rebooted, the host or remote network interface is disabled, or the remote host uses a hard close (see setsockopt for more information on the SO_LINGER option on the remote socket).
|
||||
/// This normally results if the peer application on the remote host is suddenly stopped, the host is rebooted, the host or remote network interface is disabled, or the remote host uses a hard close (see setsockopt for more information on the SO.LINGER option on the remote socket).
|
||||
/// This error may also result if a connection was broken due to keep-alive activity detecting a failure while one or more operations are in progress.
|
||||
/// Operations that were in progress fail with WSAENETRESET. Subsequent operations fail with WSAECONNRESET.
|
||||
WSAECONNRESET = 10054,
|
||||
@ -1369,12 +1407,12 @@ pub const WinsockError = enum(u16) {
|
||||
|
||||
/// Socket is already connected.
|
||||
/// A connect request was made on an already-connected socket.
|
||||
/// Some implementations also return this error if sendto is called on a connected SOCK_DGRAM socket (for SOCK_STREAM sockets, the to parameter in sendto is ignored) although other implementations treat this as a legal occurrence.
|
||||
/// Some implementations also return this error if sendto is called on a connected SOCK.DGRAM socket (for SOCK.STREAM sockets, the to parameter in sendto is ignored) although other implementations treat this as a legal occurrence.
|
||||
WSAEISCONN = 10056,
|
||||
|
||||
/// Socket is not connected.
|
||||
/// A request to send or receive data was disallowed because the socket is not connected and (when sending on a datagram socket using sendto) no address was supplied.
|
||||
/// Any other type of operation might also return this error—for example, setsockopt setting SO_KEEPALIVE if the connection has been reset.
|
||||
/// Any other type of operation might also return this error—for example, setsockopt setting SO.KEEPALIVE if the connection has been reset.
|
||||
WSAENOTCONN = 10057,
|
||||
|
||||
/// Cannot send after socket shutdown.
|
||||
|
||||
@ -86,12 +86,12 @@ pub fn nanoTimestamp() i128 {
|
||||
}
|
||||
if (builtin.os.tag == .wasi and !builtin.link_libc) {
|
||||
var ns: os.wasi.timestamp_t = undefined;
|
||||
const err = os.wasi.clock_time_get(os.wasi.CLOCK_REALTIME, 1, &ns);
|
||||
const err = os.wasi.clock_time_get(os.wasi.CLOCK.REALTIME, 1, &ns);
|
||||
assert(err == .SUCCESS);
|
||||
return ns;
|
||||
}
|
||||
var ts: os.timespec = undefined;
|
||||
os.clock_gettime(os.CLOCK_REALTIME, &ts) catch |err| switch (err) {
|
||||
os.clock_gettime(os.CLOCK.REALTIME, &ts) catch |err| switch (err) {
|
||||
error.UnsupportedClock, error.Unexpected => return 0, // "Precision of timing depends on hardware and OS".
|
||||
};
|
||||
return (@as(i128, ts.tv_sec) * ns_per_s) + ts.tv_nsec;
|
||||
|
||||
@ -46,8 +46,8 @@ pub const Connection = struct {
|
||||
|
||||
/// Possible domains that a TCP client/listener may operate over.
|
||||
pub const Domain = enum(u16) {
|
||||
ip = os.AF_INET,
|
||||
ipv6 = os.AF_INET6,
|
||||
ip = os.AF.INET,
|
||||
ipv6 = os.AF.INET6,
|
||||
};
|
||||
|
||||
/// A TCP client.
|
||||
@ -81,8 +81,8 @@ pub const Client = struct {
|
||||
return Client{
|
||||
.socket = try Socket.init(
|
||||
@enumToInt(domain),
|
||||
os.SOCK_STREAM,
|
||||
os.IPPROTO_TCP,
|
||||
os.SOCK.STREAM,
|
||||
os.IPPROTO.TCP,
|
||||
flags,
|
||||
),
|
||||
};
|
||||
@ -195,7 +195,7 @@ pub const Client = struct {
|
||||
pub fn setNoDelay(self: Client, enabled: bool) !void {
|
||||
if (comptime @hasDecl(os, "TCP_NODELAY")) {
|
||||
const bytes = mem.asBytes(&@as(usize, @boolToInt(enabled)));
|
||||
return self.socket.setOption(os.IPPROTO_TCP, os.TCP_NODELAY, bytes);
|
||||
return self.socket.setOption(os.IPPROTO.TCP, os.TCP_NODELAY, bytes);
|
||||
}
|
||||
return error.UnsupportedSocketOption;
|
||||
}
|
||||
@ -204,7 +204,7 @@ pub const Client = struct {
|
||||
/// `error.UnsupportedSocketOption` if the host does not support TCP Quick ACK.
|
||||
pub fn setQuickACK(self: Client, enabled: bool) !void {
|
||||
if (comptime @hasDecl(os, "TCP_QUICKACK")) {
|
||||
return self.socket.setOption(os.IPPROTO_TCP, os.TCP_QUICKACK, mem.asBytes(&@as(u32, @boolToInt(enabled))));
|
||||
return self.socket.setOption(os.IPPROTO.TCP, os.TCP_QUICKACK, mem.asBytes(&@as(u32, @boolToInt(enabled))));
|
||||
}
|
||||
return error.UnsupportedSocketOption;
|
||||
}
|
||||
@ -244,8 +244,8 @@ pub const Listener = struct {
|
||||
return Listener{
|
||||
.socket = try Socket.init(
|
||||
@enumToInt(domain),
|
||||
os.SOCK_STREAM,
|
||||
os.IPPROTO_TCP,
|
||||
os.SOCK.STREAM,
|
||||
os.IPPROTO.TCP,
|
||||
flags,
|
||||
),
|
||||
};
|
||||
@ -305,7 +305,7 @@ pub const Listener = struct {
|
||||
/// support TCP Fast Open.
|
||||
pub fn setFastOpen(self: Listener, enabled: bool) !void {
|
||||
if (comptime @hasDecl(os, "TCP_FASTOPEN")) {
|
||||
return self.socket.setOption(os.IPPROTO_TCP, os.TCP_FASTOPEN, mem.asBytes(&@as(u32, @boolToInt(enabled))));
|
||||
return self.socket.setOption(os.IPPROTO.TCP, os.TCP_FASTOPEN, mem.asBytes(&@as(u32, @boolToInt(enabled))));
|
||||
}
|
||||
return error.UnsupportedSocketOption;
|
||||
}
|
||||
|
||||
@ -4,6 +4,7 @@ const os = std.os;
|
||||
const mem = std.mem;
|
||||
const testing = std.testing;
|
||||
const native_os = std.Target.current.os;
|
||||
const linux = std.os.linux;
|
||||
|
||||
/// POSIX `iovec`, or Windows `WSABUF`. The difference between the two are the ordering
|
||||
/// of fields, alongside the length being represented as either a ULONG or a size_t.
|
||||
@ -67,7 +68,7 @@ pub const Reactor = struct {
|
||||
pub fn init(flags: std.enums.EnumFieldStruct(Reactor.InitFlags, bool, false)) !Reactor {
|
||||
var raw_flags: u32 = 0;
|
||||
const set = std.EnumSet(Reactor.InitFlags).init(flags);
|
||||
if (set.contains(.close_on_exec)) raw_flags |= os.EPOLL_CLOEXEC;
|
||||
if (set.contains(.close_on_exec)) raw_flags |= linux.EPOLL.CLOEXEC;
|
||||
return Reactor{ .fd = try os.epoll_create1(raw_flags) };
|
||||
}
|
||||
|
||||
@ -77,31 +78,31 @@ pub const Reactor = struct {
|
||||
|
||||
pub fn update(self: Reactor, fd: os.fd_t, identifier: usize, interest: Reactor.Interest) !void {
|
||||
var flags: u32 = 0;
|
||||
flags |= if (interest.oneshot) os.EPOLLONESHOT else os.EPOLLET;
|
||||
if (interest.hup) flags |= os.EPOLLRDHUP;
|
||||
if (interest.readable) flags |= os.EPOLLIN;
|
||||
if (interest.writable) flags |= os.EPOLLOUT;
|
||||
flags |= if (interest.oneshot) linux.EPOLL.ONESHOT else linux.EPOLL.ET;
|
||||
if (interest.hup) flags |= linux.EPOLL.RDHUP;
|
||||
if (interest.readable) flags |= linux.EPOLL.IN;
|
||||
if (interest.writable) flags |= linux.EPOLL.OUT;
|
||||
|
||||
const event = &os.epoll_event{
|
||||
const event = &linux.epoll_event{
|
||||
.events = flags,
|
||||
.data = .{ .ptr = identifier },
|
||||
};
|
||||
|
||||
os.epoll_ctl(self.fd, os.EPOLL_CTL_MOD, fd, event) catch |err| switch (err) {
|
||||
error.FileDescriptorNotRegistered => try os.epoll_ctl(self.fd, os.EPOLL_CTL_ADD, fd, event),
|
||||
os.epoll_ctl(self.fd, linux.EPOLL.CTL_MOD, fd, event) catch |err| switch (err) {
|
||||
error.FileDescriptorNotRegistered => try os.epoll_ctl(self.fd, linux.EPOLL.CTL_ADD, fd, event),
|
||||
else => return err,
|
||||
};
|
||||
}
|
||||
|
||||
pub fn poll(self: Reactor, comptime max_num_events: comptime_int, closure: anytype, timeout_milliseconds: ?u64) !void {
|
||||
var events: [max_num_events]os.epoll_event = undefined;
|
||||
var events: [max_num_events]linux.epoll_event = undefined;
|
||||
|
||||
const num_events = os.epoll_wait(self.fd, &events, if (timeout_milliseconds) |ms| @intCast(i32, ms) else -1);
|
||||
for (events[0..num_events]) |ev| {
|
||||
const is_error = ev.events & os.EPOLLERR != 0;
|
||||
const is_hup = ev.events & (os.EPOLLHUP | os.EPOLLRDHUP) != 0;
|
||||
const is_readable = ev.events & os.EPOLLIN != 0;
|
||||
const is_writable = ev.events & os.EPOLLOUT != 0;
|
||||
const is_error = ev.events & linux.EPOLL.ERR != 0;
|
||||
const is_hup = ev.events & (linux.EPOLL.HUP | linux.EPOLL.RDHUP) != 0;
|
||||
const is_readable = ev.events & linux.EPOLL.IN != 0;
|
||||
const is_writable = ev.events & linux.EPOLL.OUT != 0;
|
||||
|
||||
try closure.call(Reactor.Event{
|
||||
.data = ev.data.ptr,
|
||||
|
||||
@ -22,7 +22,7 @@ pub fn resolveScopeID(name: []const u8) !u32 {
|
||||
return os.windows.ws2_32.if_nametoindex(@ptrCast([*:0]const u8, &interface_name));
|
||||
}
|
||||
|
||||
const fd = try os.socket(os.AF_UNIX, os.SOCK_DGRAM, 0);
|
||||
const fd = try os.socket(os.AF.UNIX, os.SOCK.DGRAM, 0);
|
||||
defer os.closeSocket(fd);
|
||||
|
||||
var f: os.ifreq = undefined;
|
||||
|
||||
@ -35,7 +35,7 @@ pub const Socket = struct {
|
||||
|
||||
pub const Family = if (requires_prepended_length) u8 else c_ushort;
|
||||
|
||||
/// POSIX `sockaddr_storage`. The expected size and alignment is specified in IETF RFC 2553.
|
||||
/// POSIX `sockaddr.storage`. The expected size and alignment is specified in IETF RFC 2553.
|
||||
pub const Storage = extern struct {
|
||||
pub const expected_size = 128;
|
||||
pub const expected_alignment = 8;
|
||||
@ -71,14 +71,14 @@ pub const Socket = struct {
|
||||
/// Parses a `sockaddr` into a generic socket address.
|
||||
pub fn fromNative(address: *align(4) const os.sockaddr) Socket.Address {
|
||||
switch (address.family) {
|
||||
os.AF_INET => {
|
||||
const info = @ptrCast(*const os.sockaddr_in, address);
|
||||
os.AF.INET => {
|
||||
const info = @ptrCast(*const os.sockaddr.in, address);
|
||||
const host = net.IPv4{ .octets = @bitCast([4]u8, info.addr) };
|
||||
const port = mem.bigToNative(u16, info.port);
|
||||
return Socket.Address.initIPv4(host, port);
|
||||
},
|
||||
os.AF_INET6 => {
|
||||
const info = @ptrCast(*const os.sockaddr_in6, address);
|
||||
os.AF.INET6 => {
|
||||
const info = @ptrCast(*const os.sockaddr.in6, address);
|
||||
const host = net.IPv6{ .octets = info.addr, .scope_id = info.scope_id };
|
||||
const port = mem.bigToNative(u16, info.port);
|
||||
return Socket.Address.initIPv6(host, port);
|
||||
@ -90,8 +90,8 @@ pub const Socket = struct {
|
||||
/// Encodes a generic socket address into an extern union that may be reliably
|
||||
/// casted into a `sockaddr` which may be passed into socket syscalls.
|
||||
pub fn toNative(self: Socket.Address) extern union {
|
||||
ipv4: os.sockaddr_in,
|
||||
ipv6: os.sockaddr_in6,
|
||||
ipv4: os.sockaddr.in,
|
||||
ipv6: os.sockaddr.in6,
|
||||
} {
|
||||
return switch (self) {
|
||||
.ipv4 => |address| .{
|
||||
@ -114,8 +114,8 @@ pub const Socket = struct {
|
||||
/// Returns the number of bytes that make up the `sockaddr` equivalent to the address.
|
||||
pub fn getNativeSize(self: Socket.Address) u32 {
|
||||
return switch (self) {
|
||||
.ipv4 => @sizeOf(os.sockaddr_in),
|
||||
.ipv6 => @sizeOf(os.sockaddr_in6),
|
||||
.ipv4 => @sizeOf(os.sockaddr.in),
|
||||
.ipv6 => @sizeOf(os.sockaddr.in6),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@ -10,8 +10,8 @@ pub fn Mixin(comptime Socket: type) type {
|
||||
pub fn init(domain: u32, socket_type: u32, protocol: u32, flags: std.enums.EnumFieldStruct(Socket.InitFlags, bool, false)) !Socket {
|
||||
var raw_flags: u32 = socket_type;
|
||||
const set = std.EnumSet(Socket.InitFlags).init(flags);
|
||||
if (set.contains(.close_on_exec)) raw_flags |= os.SOCK_CLOEXEC;
|
||||
if (set.contains(.nonblocking)) raw_flags |= os.SOCK_NONBLOCK;
|
||||
if (set.contains(.close_on_exec)) raw_flags |= os.SOCK.CLOEXEC;
|
||||
if (set.contains(.nonblocking)) raw_flags |= os.SOCK.NONBLOCK;
|
||||
return Socket{ .fd = try os.socket(domain, raw_flags, protocol) };
|
||||
}
|
||||
|
||||
@ -48,8 +48,8 @@ pub fn Mixin(comptime Socket: type) type {
|
||||
|
||||
var raw_flags: u32 = 0;
|
||||
const set = std.EnumSet(Socket.InitFlags).init(flags);
|
||||
if (set.contains(.close_on_exec)) raw_flags |= os.SOCK_CLOEXEC;
|
||||
if (set.contains(.nonblocking)) raw_flags |= os.SOCK_NONBLOCK;
|
||||
if (set.contains(.close_on_exec)) raw_flags |= os.SOCK.CLOEXEC;
|
||||
if (set.contains(.nonblocking)) raw_flags |= os.SOCK.NONBLOCK;
|
||||
|
||||
const socket = Socket{ .fd = try os.accept(self.fd, @ptrCast(*os.sockaddr, &address), &address_len, raw_flags) };
|
||||
const socket_address = Socket.Address.fromNative(@ptrCast(*os.sockaddr, &address));
|
||||
@ -156,7 +156,7 @@ pub fn Mixin(comptime Socket: type) type {
|
||||
var value: u32 = undefined;
|
||||
var value_len: u32 = @sizeOf(u32);
|
||||
|
||||
const rc = os.system.getsockopt(self.fd, os.SOL_SOCKET, os.SO_RCVBUF, mem.asBytes(&value), &value_len);
|
||||
const rc = os.system.getsockopt(self.fd, os.SOL.SOCKET, os.SO.RCVBUF, mem.asBytes(&value), &value_len);
|
||||
return switch (os.errno(rc)) {
|
||||
.SUCCESS => value,
|
||||
.BADF => error.BadFileDescriptor,
|
||||
@ -173,7 +173,7 @@ pub fn Mixin(comptime Socket: type) type {
|
||||
var value: u32 = undefined;
|
||||
var value_len: u32 = @sizeOf(u32);
|
||||
|
||||
const rc = os.system.getsockopt(self.fd, os.SOL_SOCKET, os.SO_SNDBUF, mem.asBytes(&value), &value_len);
|
||||
const rc = os.system.getsockopt(self.fd, os.SOL.SOCKET, os.SO.SNDBUF, mem.asBytes(&value), &value_len);
|
||||
return switch (os.errno(rc)) {
|
||||
.SUCCESS => value,
|
||||
.BADF => error.BadFileDescriptor,
|
||||
@ -195,9 +195,9 @@ pub fn Mixin(comptime Socket: type) type {
|
||||
/// if the host does not support the option for a socket to linger around up until a timeout specified in
|
||||
/// seconds.
|
||||
pub fn setLinger(self: Socket, timeout_seconds: ?u16) !void {
|
||||
if (comptime @hasDecl(os, "SO_LINGER")) {
|
||||
if (@hasDecl(os.SO, "LINGER")) {
|
||||
const settings = Socket.Linger.init(timeout_seconds);
|
||||
return self.setOption(os.SOL_SOCKET, os.SO_LINGER, mem.asBytes(&settings));
|
||||
return self.setOption(os.SOL.SOCKET, os.SO.LINGER, mem.asBytes(&settings));
|
||||
}
|
||||
|
||||
return error.UnsupportedSocketOption;
|
||||
@ -207,8 +207,8 @@ pub fn Mixin(comptime Socket: type) type {
|
||||
/// messages are sent are dependant on operating system settings. It returns `error.UnsupportedSocketOption` if
|
||||
/// the host does not support periodically sending keep-alive messages on connection-oriented sockets.
|
||||
pub fn setKeepAlive(self: Socket, enabled: bool) !void {
|
||||
if (comptime @hasDecl(os, "SO_KEEPALIVE")) {
|
||||
return self.setOption(os.SOL_SOCKET, os.SO_KEEPALIVE, mem.asBytes(&@as(u32, @boolToInt(enabled))));
|
||||
if (@hasDecl(os.SO, "KEEPALIVE")) {
|
||||
return self.setOption(os.SOL.SOCKET, os.SO.KEEPALIVE, mem.asBytes(&@as(u32, @boolToInt(enabled))));
|
||||
}
|
||||
return error.UnsupportedSocketOption;
|
||||
}
|
||||
@ -216,8 +216,8 @@ pub fn Mixin(comptime Socket: type) type {
|
||||
/// Allow multiple sockets on the same host to listen on the same address. It returns `error.UnsupportedSocketOption` if
|
||||
/// the host does not support sockets listening the same address.
|
||||
pub fn setReuseAddress(self: Socket, enabled: bool) !void {
|
||||
if (comptime @hasDecl(os, "SO_REUSEADDR")) {
|
||||
return self.setOption(os.SOL_SOCKET, os.SO_REUSEADDR, mem.asBytes(&@as(u32, @boolToInt(enabled))));
|
||||
if (@hasDecl(os.SO, "REUSEADDR")) {
|
||||
return self.setOption(os.SOL.SOCKET, os.SO.REUSEADDR, mem.asBytes(&@as(u32, @boolToInt(enabled))));
|
||||
}
|
||||
return error.UnsupportedSocketOption;
|
||||
}
|
||||
@ -225,20 +225,20 @@ pub fn Mixin(comptime Socket: type) type {
|
||||
/// Allow multiple sockets on the same host to listen on the same port. It returns `error.UnsupportedSocketOption` if
|
||||
/// the host does not supports sockets listening on the same port.
|
||||
pub fn setReusePort(self: Socket, enabled: bool) !void {
|
||||
if (comptime @hasDecl(os, "SO_REUSEPORT")) {
|
||||
return self.setOption(os.SOL_SOCKET, os.SO_REUSEPORT, mem.asBytes(&@as(u32, @boolToInt(enabled))));
|
||||
if (@hasDecl(os.SO, "REUSEPORT")) {
|
||||
return self.setOption(os.SOL.SOCKET, os.SO.REUSEPORT, mem.asBytes(&@as(u32, @boolToInt(enabled))));
|
||||
}
|
||||
return error.UnsupportedSocketOption;
|
||||
}
|
||||
|
||||
/// Set the write buffer size of the socket.
|
||||
pub fn setWriteBufferSize(self: Socket, size: u32) !void {
|
||||
return self.setOption(os.SOL_SOCKET, os.SO_SNDBUF, mem.asBytes(&size));
|
||||
return self.setOption(os.SOL.SOCKET, os.SO.SNDBUF, mem.asBytes(&size));
|
||||
}
|
||||
|
||||
/// Set the read buffer size of the socket.
|
||||
pub fn setReadBufferSize(self: Socket, size: u32) !void {
|
||||
return self.setOption(os.SOL_SOCKET, os.SO_RCVBUF, mem.asBytes(&size));
|
||||
return self.setOption(os.SOL.SOCKET, os.SO.RCVBUF, mem.asBytes(&size));
|
||||
}
|
||||
|
||||
/// WARNING: Timeouts only affect blocking sockets. It is undefined behavior if a timeout is
|
||||
@ -253,7 +253,7 @@ pub fn Mixin(comptime Socket: type) type {
|
||||
.tv_usec = @intCast(i32, (milliseconds % time.ms_per_s) * time.us_per_ms),
|
||||
};
|
||||
|
||||
return self.setOption(os.SOL_SOCKET, os.SO_SNDTIMEO, mem.asBytes(&timeout));
|
||||
return self.setOption(os.SOL.SOCKET, os.SO.SNDTIMEO, mem.asBytes(&timeout));
|
||||
}
|
||||
|
||||
/// WARNING: Timeouts only affect blocking sockets. It is undefined behavior if a timeout is
|
||||
@ -269,7 +269,7 @@ pub fn Mixin(comptime Socket: type) type {
|
||||
.tv_usec = @intCast(i32, (milliseconds % time.ms_per_s) * time.us_per_ms),
|
||||
};
|
||||
|
||||
return self.setOption(os.SOL_SOCKET, os.SO_RCVTIMEO, mem.asBytes(&timeout));
|
||||
return self.setOption(os.SOL.SOCKET, os.SO.RCVTIMEO, mem.asBytes(&timeout));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@ -399,39 +399,39 @@ pub fn Mixin(comptime Socket: type) type {
|
||||
/// seconds.
|
||||
pub fn setLinger(self: Socket, timeout_seconds: ?u16) !void {
|
||||
const settings = Socket.Linger.init(timeout_seconds);
|
||||
return self.setOption(ws2_32.SOL_SOCKET, ws2_32.SO_LINGER, mem.asBytes(&settings));
|
||||
return self.setOption(ws2_32.SOL.SOCKET, ws2_32.SO.LINGER, mem.asBytes(&settings));
|
||||
}
|
||||
|
||||
/// On connection-oriented sockets, have keep-alive messages be sent periodically. The timing in which keep-alive
|
||||
/// messages are sent are dependant on operating system settings. It returns `error.UnsupportedSocketOption` if
|
||||
/// the host does not support periodically sending keep-alive messages on connection-oriented sockets.
|
||||
pub fn setKeepAlive(self: Socket, enabled: bool) !void {
|
||||
return self.setOption(ws2_32.SOL_SOCKET, ws2_32.SO_KEEPALIVE, mem.asBytes(&@as(u32, @boolToInt(enabled))));
|
||||
return self.setOption(ws2_32.SOL.SOCKET, ws2_32.SO.KEEPALIVE, mem.asBytes(&@as(u32, @boolToInt(enabled))));
|
||||
}
|
||||
|
||||
/// Allow multiple sockets on the same host to listen on the same address. It returns `error.UnsupportedSocketOption` if
|
||||
/// the host does not support sockets listening the same address.
|
||||
pub fn setReuseAddress(self: Socket, enabled: bool) !void {
|
||||
return self.setOption(ws2_32.SOL_SOCKET, ws2_32.SO_REUSEADDR, mem.asBytes(&@as(u32, @boolToInt(enabled))));
|
||||
return self.setOption(ws2_32.SOL.SOCKET, ws2_32.SO.REUSEADDR, mem.asBytes(&@as(u32, @boolToInt(enabled))));
|
||||
}
|
||||
|
||||
/// Allow multiple sockets on the same host to listen on the same port. It returns `error.UnsupportedSocketOption` if
|
||||
/// the host does not supports sockets listening on the same port.
|
||||
///
|
||||
/// TODO: verify if this truly mimicks SO_REUSEPORT behavior, or if SO_REUSE_UNICASTPORT provides the correct behavior
|
||||
/// TODO: verify if this truly mimicks SO.REUSEPORT behavior, or if SO.REUSE_UNICASTPORT provides the correct behavior
|
||||
pub fn setReusePort(self: Socket, enabled: bool) !void {
|
||||
try self.setOption(ws2_32.SOL_SOCKET, ws2_32.SO_BROADCAST, mem.asBytes(&@as(u32, @boolToInt(enabled))));
|
||||
try self.setOption(ws2_32.SOL.SOCKET, ws2_32.SO.BROADCAST, mem.asBytes(&@as(u32, @boolToInt(enabled))));
|
||||
try self.setReuseAddress(enabled);
|
||||
}
|
||||
|
||||
/// Set the write buffer size of the socket.
|
||||
pub fn setWriteBufferSize(self: Socket, size: u32) !void {
|
||||
return self.setOption(ws2_32.SOL_SOCKET, ws2_32.SO_SNDBUF, mem.asBytes(&size));
|
||||
return self.setOption(ws2_32.SOL.SOCKET, ws2_32.SO.SNDBUF, mem.asBytes(&size));
|
||||
}
|
||||
|
||||
/// Set the read buffer size of the socket.
|
||||
pub fn setReadBufferSize(self: Socket, size: u32) !void {
|
||||
return self.setOption(ws2_32.SOL_SOCKET, ws2_32.SO_RCVBUF, mem.asBytes(&size));
|
||||
return self.setOption(ws2_32.SOL.SOCKET, ws2_32.SO.RCVBUF, mem.asBytes(&size));
|
||||
}
|
||||
|
||||
/// WARNING: Timeouts only affect blocking sockets. It is undefined behavior if a timeout is
|
||||
@ -441,7 +441,7 @@ pub fn Mixin(comptime Socket: type) type {
|
||||
/// to its bound destination after a specified number of milliseconds. A subsequent write
|
||||
/// to the socket will thereafter return `error.WouldBlock` should the timeout be exceeded.
|
||||
pub fn setWriteTimeout(self: Socket, milliseconds: u32) !void {
|
||||
return self.setOption(ws2_32.SOL_SOCKET, ws2_32.SO_SNDTIMEO, mem.asBytes(&milliseconds));
|
||||
return self.setOption(ws2_32.SOL.SOCKET, ws2_32.SO.SNDTIMEO, mem.asBytes(&milliseconds));
|
||||
}
|
||||
|
||||
/// WARNING: Timeouts only affect blocking sockets. It is undefined behavior if a timeout is
|
||||
@ -452,7 +452,7 @@ pub fn Mixin(comptime Socket: type) type {
|
||||
/// read from the socket will thereafter return `error.WouldBlock` should the timeout be
|
||||
/// exceeded.
|
||||
pub fn setReadTimeout(self: Socket, milliseconds: u32) !void {
|
||||
return self.setOption(ws2_32.SOL_SOCKET, ws2_32.SO_RCVTIMEO, mem.asBytes(&milliseconds));
|
||||
return self.setOption(ws2_32.SOL.SOCKET, ws2_32.SO.RCVTIMEO, mem.asBytes(&milliseconds));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@ -3836,7 +3836,7 @@ fn gimmeMoreOfThoseSweetSweetFileDescriptors() void {
|
||||
// On Darwin, `NOFILE` is bounded by a hardcoded value `OPEN_MAX`.
|
||||
// According to the man pages for setrlimit():
|
||||
// setrlimit() now returns with errno set to EINVAL in places that historically succeeded.
|
||||
// It no longer accepts "rlim_cur = RLIM_INFINITY" for RLIM_NOFILE.
|
||||
// It no longer accepts "rlim_cur = RLIM.INFINITY" for RLIM.NOFILE.
|
||||
// Use "rlim_cur = min(OPEN_MAX, rlim_max)".
|
||||
lim.max = std.math.min(std.os.darwin.OPEN_MAX, lim.max);
|
||||
}
|
||||
@ -3846,7 +3846,7 @@ fn gimmeMoreOfThoseSweetSweetFileDescriptors() void {
|
||||
var min: posix.rlim_t = lim.cur;
|
||||
var max: posix.rlim_t = 1 << 20;
|
||||
// But if there's a defined upper bound, don't search, just set it.
|
||||
if (lim.max != posix.RLIM_INFINITY) {
|
||||
if (lim.max != posix.RLIM.INFINITY) {
|
||||
min = lim.max;
|
||||
max = lim.max;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user