authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-01-02 19:29:20 -08:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-01-02 19:29:20 -08:00
log588abaa4a6ebad4603da60c1d270c7bf7c367215
tree04bb0092b4c58e6edd16f3ff605a4949665f4748
parentbe47f81f8219ed513b68acd398a3e24bb8276afc

bits to bootstrap zig-net


2 files changed, 286 insertions(+), 12 deletions(-)

mod.zig+276-12
...@@ -927,6 +927,36 @@ pub const errno = struct {...@@ -927,6 +927,36 @@ pub const errno = struct {
927 }927 }
928};928};
929929
930pub const eai = struct {
931 pub const Error = error{
932 EAI_BADFLAGS,
933 EAI_NONAME,
934 EAI_AGAIN,
935 EAI_FAIL,
936 EAI_NODATA,
937 EAI_FAMILY,
938 EAI_SOCKTYPE,
939 EAI_SERVICE,
940 EAI_MEMORY,
941 EAI_SYSTEM,
942 EAI_OVERFLOW,
943 };
944
945 pub const Enum = enum(c_int) {
946 EAI_BADFLAGS = -1,
947 EAI_NONAME = -2,
948 EAI_AGAIN = -3,
949 EAI_FAIL = -4,
950 EAI_NODATA = -5,
951 EAI_FAMILY = -6,
952 EAI_SOCKTYPE = -7,
953 EAI_SERVICE = -8,
954 EAI_MEMORY = -10,
955 EAI_SYSTEM = -11,
956 EAI_OVERFLOW = -12,
957 };
958};
959
930pub const libc = struct {960pub const libc = struct {
931 /// void _Exit(int status);961 /// void _Exit(int status);
932 /// https://pubs.opengroup.org/onlinepubs/9699919799.orig/functions/_Exit.html962 /// https://pubs.opengroup.org/onlinepubs/9699919799.orig/functions/_Exit.html
...@@ -1044,6 +1074,10 @@ pub const libc = struct {...@@ -1044,6 +1074,10 @@ pub const libc = struct {
1044 /// https://pubs.opengroup.org/onlinepubs/9699919799.orig/functions/atanl.html1074 /// https://pubs.opengroup.org/onlinepubs/9699919799.orig/functions/atanl.html
1045 pub extern fn atanl(x: c_longdouble) c_longdouble;1075 pub extern fn atanl(x: c_longdouble) c_longdouble;
10461076
1077 /// int bind(int socket, const struct sockaddr *address, socklen_t address_len);
1078 /// https://pubs.opengroup.org/onlinepubs/9699919799.orig/functions/bind.html
1079 pub extern fn bind(socket: c_int, address: *const struct_sockaddr, address_len: socklen_t) c_int;
1080
1047 /// double cbrt(double x);1081 /// double cbrt(double x);
1048 /// https://pubs.opengroup.org/onlinepubs/9699919799.orig/functions/cbrt.html1082 /// https://pubs.opengroup.org/onlinepubs/9699919799.orig/functions/cbrt.html
1049 pub extern fn cbrt(x: f64) f64;1083 pub extern fn cbrt(x: f64) f64;
...@@ -1104,6 +1138,10 @@ pub const libc = struct {...@@ -1104,6 +1138,10 @@ pub const libc = struct {
1104 /// https://pubs.opengroup.org/onlinepubs/9699919799.orig/functions/closelog.html1138 /// https://pubs.opengroup.org/onlinepubs/9699919799.orig/functions/closelog.html
1105 pub extern fn closelog() void;1139 pub extern fn closelog() void;
11061140
1141 /// int connect(int socket, const struct sockaddr *address, socklen_t address_len);
1142 /// https://pubs.opengroup.org/onlinepubs/9699919799.orig/functions/connect.html
1143 pub extern fn connect(socket: c_int, address: *const struct_sockaddr, address_len: socklen_t) c_int;
1144
1107 /// double copysign(double x, double y);1145 /// double copysign(double x, double y);
1108 /// https://pubs.opengroup.org/onlinepubs/9699919799.orig/functions/copysign.html1146 /// https://pubs.opengroup.org/onlinepubs/9699919799.orig/functions/copysign.html
1109 pub extern fn copysign(x: f64, y: f64) f64;1147 pub extern fn copysign(x: f64, y: f64) f64;
...@@ -2144,6 +2182,10 @@ pub const libc = struct {...@@ -2144,6 +2182,10 @@ pub const libc = struct {
2144 /// https://pubs.opengroup.org/onlinepubs/9699919799.orig/functions/read.html2182 /// https://pubs.opengroup.org/onlinepubs/9699919799.orig/functions/read.html
2145 pub extern fn read(fd: c_int, buf: [*]u8, count: usize) isize;2183 pub extern fn read(fd: c_int, buf: [*]u8, count: usize) isize;
21462184
2185 /// ssize_t recv(int socket, void *buffer, size_t length, int flags);
2186 /// https://pubs.opengroup.org/onlinepubs/9699919799.orig/functions/recv.html
2187 pub extern fn recv(fd: c_int, buffer: [*]u8, length: usize, flags: c_int) isize;
2188
2147 /// double remainder(double x, double y);2189 /// double remainder(double x, double y);
2148 /// https://pubs.opengroup.org/onlinepubs/9699919799.orig/functions/remainder.html2190 /// https://pubs.opengroup.org/onlinepubs/9699919799.orig/functions/remainder.html
2149 pub extern fn remainder(x: f64, y: f64) f64;2191 pub extern fn remainder(x: f64, y: f64) f64;
...@@ -2232,6 +2274,10 @@ pub const libc = struct {...@@ -2232,6 +2274,10 @@ pub const libc = struct {
2232 /// https://pubs.opengroup.org/onlinepubs/9699919799.orig/functions/semctl.html2274 /// https://pubs.opengroup.org/onlinepubs/9699919799.orig/functions/semctl.html
2233 pub extern fn semctl(semid: c_int, semnum: c_int, cmd: c_int, ...) c_int;2275 pub extern fn semctl(semid: c_int, semnum: c_int, cmd: c_int, ...) c_int;
22342276
2277 /// ssize_t send(int socket, const void *buffer, size_t length, int flags);
2278 /// https://pubs.opengroup.org/onlinepubs/9699919799.orig/functions/send.html
2279 pub extern fn send(fd: c_int, buffer: [*]const u8, length: usize, flags: c_int) isize;
2280
2235 /// int setegid(gid_t gid);2281 /// int setegid(gid_t gid);
2236 /// https://pubs.opengroup.org/onlinepubs/9699919799.orig/functions/setegid.html2282 /// https://pubs.opengroup.org/onlinepubs/9699919799.orig/functions/setegid.html
2237 pub extern fn setegid(gid: gid_t) c_int;2283 pub extern fn setegid(gid: gid_t) c_int;
...@@ -2288,6 +2334,10 @@ pub const libc = struct {...@@ -2288,6 +2334,10 @@ pub const libc = struct {
2288 /// https://pubs.opengroup.org/onlinepubs/9699919799.orig/functions/setsid.html2334 /// https://pubs.opengroup.org/onlinepubs/9699919799.orig/functions/setsid.html
2289 pub extern fn setsid() pid_t;2335 pub extern fn setsid() pid_t;
22902336
2337 /// int setsockopt(int socket, int level, int option_name, const void *option_value, socklen_t option_len);
2338 /// https://pubs.opengroup.org/onlinepubs/9699919799.orig/functions/setsockopt.html
2339 pub extern fn setsockopt(fd: c_int, level: c_int, optname: c_int, optval: *const anyopaque, optlen: socklen_t) c_int;
2340
2291 /// int setuid(uid_t uid);2341 /// int setuid(uid_t uid);
2292 /// https://pubs.opengroup.org/onlinepubs/9699919799.orig/functions/setuid.html2342 /// https://pubs.opengroup.org/onlinepubs/9699919799.orig/functions/setuid.html
2293 pub extern fn setuid(uid: uid_t) c_int;2343 pub extern fn setuid(uid: uid_t) c_int;
...@@ -2557,6 +2607,7 @@ pub const libc = struct {...@@ -2557,6 +2607,7 @@ pub const libc = struct {
25572607
2558 pub extern fn __errno_location() *c_int;2608 pub extern fn __errno_location() *c_int;
2559 pub extern fn gettid() pid_t;2609 pub extern fn gettid() pid_t;
2610 pub extern fn accept4(socket: c_int, noalias address: ?*struct_sockaddr, noalias address_len: *socklen_t, flags: c_int) c_int;
2560};2611};
25612612
2562pub const clock_t = c_long;2613pub const clock_t = c_long;
...@@ -2580,7 +2631,6 @@ pub const nl_catd = *const opaque {};...@@ -2580,7 +2631,6 @@ pub const nl_catd = *const opaque {};
2580pub const intmax_t = i64;2631pub const intmax_t = i64;
2581pub const wchar_t = c_int;2632pub const wchar_t = c_int;
2582pub const mode_t = c_uint;2633pub const mode_t = c_uint;
2583pub const struct_sockaddr = linux.sockaddr;
2584pub const socklen_t = c_uint;2634pub const socklen_t = c_uint;
2585pub const clockid_t = c_int;2635pub const clockid_t = c_int;
2586pub const struct_timespec = linux.timespec;2636pub const struct_timespec = linux.timespec;
...@@ -2591,6 +2641,16 @@ pub const off_t = linux.off_t;...@@ -2591,6 +2641,16 @@ pub const off_t = linux.off_t;
2591pub const ino_t = linux.ino_t;2641pub const ino_t = linux.ino_t;
2592pub const struct_stat = linux.Stat;2642pub const struct_stat = linux.Stat;
2593pub const struct_iovec = extern struct { base: [*]u8, len: usize };2643pub const struct_iovec = extern struct { base: [*]u8, len: usize };
2644pub const in_addr_t = u32;
2645pub const in_port_t = u16;
2646pub const sa_family_t = c_ushort;
2647pub const struct_in_addr = extern struct { addr: in_addr_t };
2648pub const struct_in6_addr = extern struct { addr: [16]u8 };
2649pub const struct_sockaddr = extern struct { family: AF, data: [14]u8 };
2650pub const struct_sockaddr_in = extern struct { family: AF = .INET, port: in_port_t, addr: struct_in_addr, zero: [8]u8 = @splat(0) };
2651pub const struct_sockaddr_in6 = extern struct { family: AF = .INET6, port: in_port_t, flowinfo: u32, addr: struct_in6_addr, scope_id: u32 };
2652pub const struct_sockaddr_un = extern struct { family: AF = .UNIX, path: [108]u8 };
2653pub const struct_addrinfo = extern struct { flags: c_int, family: c_int, socktype: c_int, protocol: c_int, addrlen: socklen_t, addr: ?*struct_sockaddr, canonname: ?[*:0]u8, next: ?*struct_addrinfo };
25942654
2595pub const AT = struct {2655pub const AT = struct {
2596 pub const FDCWD = -100;2656 pub const FDCWD = -100;
...@@ -2740,37 +2800,197 @@ pub const TZNAME_MAX = 6;...@@ -2740,37 +2800,197 @@ pub const TZNAME_MAX = 6;
2740pub const TTY_NAME_MAX = 32;2800pub const TTY_NAME_MAX = 32;
2741pub const HOST_NAME_MAX = 255;2801pub const HOST_NAME_MAX = 255;
27422802
2803pub const AF = enum(sa_family_t) {
2804 UNSPEC = 0,
2805 LOCAL = 1,
2806 INET = 2,
2807 AX25 = 3,
2808 IPX = 4,
2809 APPLETALK = 5,
2810 NETROM = 6,
2811 BRIDGE = 7,
2812 ATMPVC = 8,
2813 X25 = 9,
2814 INET6 = 10,
2815 ROSE = 11,
2816 DECnet = 12,
2817 NETBEUI = 13,
2818 SECURITY = 14,
2819 KEY = 15,
2820 NETLINK = 16,
2821 PACKET = 17,
2822 ASH = 18,
2823 ECONET = 19,
2824 ATMSVC = 20,
2825 RDS = 21,
2826 SNA = 22,
2827 IRDA = 23,
2828 PPPOX = 24,
2829 WANPIPE = 25,
2830 LLC = 26,
2831 IB = 27,
2832 MPLS = 28,
2833 CAN = 29,
2834 TIPC = 30,
2835 BLUETOOTH = 31,
2836 IUCV = 32,
2837 RXRPC = 33,
2838 ISDN = 34,
2839 PHONET = 35,
2840 IEEE802154 = 36,
2841 CAIF = 37,
2842 ALG = 38,
2843 NFC = 39,
2844 VSOCK = 40,
2845 KCM = 41,
2846 QIPCRTR = 42,
2847 SMC = 43,
2848 XDP = 44,
2849
2850 pub const UNIX: AF = .LOCAL;
2851 pub const FILE: AF = .LOCAL;
2852 pub const ROUTE: AF = .NETLINK;
2853};
2854
2855pub const SOCK = struct {
2856 pub const STREAM = 1;
2857 pub const DGRAM = 2;
2858 pub const RAW = 3;
2859 pub const RDM = 4;
2860 pub const SEQPACKET = 5;
2861 pub const DCCP = 6;
2862 pub const PACKET = 10;
2863 pub const CLOEXEC = 0o2000000;
2864 pub const NONBLOCK = 0o4000;
2865};
2866
2867pub const SHUT = enum(c_int) {
2868 RD = 0,
2869 WR = 1,
2870 RDWR = 2,
2871};
2872
2873pub const IPPROTO = struct {
2874 pub const IP = 0;
2875 pub const HOPOPTS = 0;
2876 pub const ICMP = 1;
2877 pub const IGMP = 2;
2878 pub const IPIP = 4;
2879 pub const TCP = 6;
2880 pub const EGP = 8;
2881 pub const PUP = 12;
2882 pub const UDP = 17;
2883 pub const IDP = 22;
2884 pub const TP = 29;
2885 pub const DCCP = 33;
2886 pub const IPV6 = 41;
2887 pub const ROUTING = 43;
2888 pub const FRAGMENT = 44;
2889 pub const RSVP = 46;
2890 pub const GRE = 47;
2891 pub const ESP = 50;
2892 pub const AH = 51;
2893 pub const ICMPV6 = 58;
2894 pub const NONE = 59;
2895 pub const DSTOPTS = 60;
2896 pub const MTP = 92;
2897 pub const BEETPH = 94;
2898 pub const ENCAP = 98;
2899 pub const PIM = 103;
2900 pub const COMP = 108;
2901 pub const SCTP = 132;
2902 pub const MH = 135;
2903 pub const UDPLITE = 136;
2904 pub const MPLS = 137;
2905 pub const ETHERNET = 143;
2906 pub const RAW = 255;
2907 pub const MPTCP = 262;
2908};
2909
2910pub const SOL = struct {
2911 pub const SOCKET = 1;
2912 pub const IP = 0;
2913 pub const IPV6 = 41;
2914 pub const ICMPV6 = 58;
2915 pub const RAW = 255;
2916 pub const DECNET = 261;
2917 pub const X25 = 262;
2918 pub const PACKET = 263;
2919 pub const ATM = 264;
2920 pub const AAL = 265;
2921 pub const IRDA = 266;
2922 pub const NETBEUI = 267;
2923 pub const LLC = 268;
2924 pub const DCCP = 269;
2925 pub const NETLINK = 270;
2926 pub const TIPC = 271;
2927 pub const RXRPC = 272;
2928 pub const PPPOL2TP = 273;
2929 pub const BLUETOOTH = 274;
2930 pub const PNPIPE = 275;
2931 pub const RDS = 276;
2932 pub const IUCV = 277;
2933 pub const CAIF = 278;
2934 pub const ALG = 279;
2935 pub const NFC = 280;
2936 pub const KCM = 281;
2937 pub const TLS = 282;
2938 pub const XDP = 283;
2939};
2940
2941pub const SO = struct {
2942 pub const DEBUG = 1;
2943 pub const REUSEADDR = 2;
2944 pub const TYPE = 3;
2945 pub const ERROR = 4;
2946 pub const DONTROUTE = 5;
2947 pub const BROADCAST = 6;
2948 pub const SNDBUF = 7;
2949 pub const RCVBUF = 8;
2950 pub const KEEPALIVE = 9;
2951 pub const OOBINLINE = 10;
2952 pub const NO_CHECK = 11;
2953 pub const PRIORITY = 12;
2954 pub const LINGER = 13;
2955 pub const BSDCOMPAT = 14;
2956 pub const REUSEPORT = 15;
2957 pub const PASSCRED = 16;
2958 pub const PEERCRED = 17;
2959 pub const RCVLOWAT = 18;
2960 pub const SNDLOWAT = 19;
2961 pub const ACCEPTCONN = 30;
2962 pub const PEERSEC = 31;
2963 pub const SNDBUFFORCE = 32;
2964 pub const RCVBUFFORCE = 33;
2965 pub const PROTOCOL = 38;
2966 pub const DOMAIN = 39;
2967};
2968
2743pub fn getpid() pid_t {2969pub fn getpid() pid_t {
2744 return libc.getpid();2970 return libc.getpid();
2745}2971}
2746
2747pub fn exit(status: c_int) noreturn {2972pub fn exit(status: c_int) noreturn {
2748 return libc.exit(status);2973 return libc.exit(status);
2749}2974}
2750
2751pub fn getenv(name: [:0]const u8) ?[:0]u8 {2975pub fn getenv(name: [:0]const u8) ?[:0]u8 {
2752 return std.mem.sliceTo(libc.getenv(name.ptr) orelse return null, 0);2976 return std.mem.sliceTo(libc.getenv(name.ptr) orelse return null, 0);
2753}2977}
2754
2755pub fn openat(fd: c_int, file: [*:0]const u8, oflag: c_int) errno.Error!c_int {2978pub fn openat(fd: c_int, file: [*:0]const u8, oflag: c_int) errno.Error!c_int {
2756 const rc = libc.openat(fd, file, oflag);2979 const rc = libc.openat(fd, file, oflag);
2757 if (rc == -1) return errno.fromInt(errno.fromLibC());2980 if (rc == -1) return errno.fromInt(errno.fromLibC());
2758 return rc;2981 return rc;
2759}2982}
2760
2761pub fn close(fd: c_int) errno.Error!void {2983pub fn close(fd: c_int) errno.Error!void {
2762 const rc = libc.close(fd);2984 const rc = libc.close(fd);
2763 if (rc == -1) return errno.fromInt(errno.fromLibC());2985 if (rc == -1) return errno.fromInt(errno.fromLibC());
2764 std.debug.assert(rc == 0);2986 std.debug.assert(rc == 0);
2765}2987}
2766
2767pub fn read(fd: c_int, buf: []u8) errno.Error!usize {2988pub fn read(fd: c_int, buf: []u8) errno.Error!usize {
2768 const rc = libc.read(fd, buf.ptr, buf.len);2989 const rc = libc.read(fd, buf.ptr, buf.len);
2769 if (rc == -1) return errno.fromInt(errno.fromLibC());2990 if (rc == -1) return errno.fromInt(errno.fromLibC());
2770 std.debug.assert(rc >= 0);2991 std.debug.assert(rc >= 0);
2771 return @intCast(rc);2992 return @intCast(rc);
2772}2993}
2773
2774pub fn fstat(fd: c_int) errno.Error!struct_stat {2994pub fn fstat(fd: c_int) errno.Error!struct_stat {
2775 var buf: struct_stat = undefined;2995 var buf: struct_stat = undefined;
2776 const rc = libc.fstat(fd, &buf);2996 const rc = libc.fstat(fd, &buf);
...@@ -2778,7 +2998,6 @@ pub fn fstat(fd: c_int) errno.Error!struct_stat {...@@ -2778,7 +2998,6 @@ pub fn fstat(fd: c_int) errno.Error!struct_stat {
2778 std.debug.assert(rc == 0);2998 std.debug.assert(rc == 0);
2779 return buf;2999 return buf;
2780}3000}
2781
2782pub fn readv(fd: c_int, bufs: []const struct_iovec) errno.Error!usize {3001pub fn readv(fd: c_int, bufs: []const struct_iovec) errno.Error!usize {
2783 std.debug.assert(bufs.len > 0);3002 std.debug.assert(bufs.len > 0);
2784 std.debug.assert(bufs.len <= IOV_MAX);3003 std.debug.assert(bufs.len <= IOV_MAX);
...@@ -2787,21 +3006,17 @@ pub fn readv(fd: c_int, bufs: []const struct_iovec) errno.Error!usize {...@@ -2787,21 +3006,17 @@ pub fn readv(fd: c_int, bufs: []const struct_iovec) errno.Error!usize {
2787 std.debug.assert(rc >= 0);3006 std.debug.assert(rc >= 0);
2788 return @intCast(rc);3007 return @intCast(rc);
2789}3008}
2790
2791pub fn mkdirat(fd: c_int, path: [*:0]const u8, mode: mode_t) errno.Error!void {3009pub fn mkdirat(fd: c_int, path: [*:0]const u8, mode: mode_t) errno.Error!void {
2792 const rc = libc.mkdirat(fd, path, mode);3010 const rc = libc.mkdirat(fd, path, mode);
2793 if (rc == -1) return errno.fromInt(errno.fromLibC());3011 if (rc == -1) return errno.fromInt(errno.fromLibC());
2794 std.debug.assert(rc == 0);3012 std.debug.assert(rc == 0);
2795}3013}
2796
2797pub fn pthread_self() pthread_t {3014pub fn pthread_self() pthread_t {
2798 return libc.pthread_self();3015 return libc.pthread_self();
2799}3016}
2800
2801pub fn gettid() pid_t {3017pub fn gettid() pid_t {
2802 return libc.gettid();3018 return libc.gettid();
2803}3019}
2804
2805pub fn fstatat(fd: c_int, path: [*:0]const u8, flag: c_int) errno.Error!struct_stat {3020pub fn fstatat(fd: c_int, path: [*:0]const u8, flag: c_int) errno.Error!struct_stat {
2806 var buf: struct_stat = undefined;3021 var buf: struct_stat = undefined;
2807 const rc = libc.fstatat(fd, path, &buf, flag);3022 const rc = libc.fstatat(fd, path, &buf, flag);
...@@ -2809,3 +3024,52 @@ pub fn fstatat(fd: c_int, path: [*:0]const u8, flag: c_int) errno.Error!struct_s...@@ -2809,3 +3024,52 @@ pub fn fstatat(fd: c_int, path: [*:0]const u8, flag: c_int) errno.Error!struct_s
2809 std.debug.assert(rc == 0);3024 std.debug.assert(rc == 0);
2810 return buf;3025 return buf;
2811}3026}
3027pub fn socket(domain: AF, ty: c_int, protocol: c_int) errno.Error!c_uint {
3028 const rc = libc.socket(@intFromEnum(domain), ty, protocol);
3029 if (rc == -1) return errno.fromInt(errno.fromLibC());
3030 std.debug.assert(rc > 0);
3031 return @intCast(rc);
3032}
3033pub fn listen(socketfd: c_uint, backlog: c_int) errno.Error!void {
3034 const rc = libc.listen(@intCast(socketfd), backlog);
3035 if (rc == -1) return errno.fromInt(errno.fromLibC());
3036 std.debug.assert(rc == 0);
3037}
3038pub fn bind(socketfd: c_uint, address: *const struct_sockaddr, address_len: socklen_t) errno.Error!void {
3039 const rc = libc.bind(@intCast(socketfd), address, address_len);
3040 if (rc == -1) return errno.fromInt(errno.fromLibC());
3041 std.debug.assert(rc == 0);
3042}
3043pub fn connect(socketfd: c_uint, address: *const struct_sockaddr, address_len: socklen_t) errno.Error!void {
3044 const rc = libc.connect(@intCast(socketfd), address, address_len);
3045 if (rc == -1) return errno.fromInt(errno.fromLibC());
3046 std.debug.assert(rc == 0);
3047}
3048pub fn shutdown(socketfd: c_uint, how: SHUT) errno.Error!void {
3049 const rc = libc.shutdown(@intCast(socketfd), @intFromEnum(how));
3050 if (rc == -1) return errno.fromInt(errno.fromLibC());
3051 std.debug.assert(rc == 0);
3052}
3053pub fn setsockopt(socketfd: c_uint, level: c_int, optname: c_int, opaque_opt: []const u8) errno.Error!void {
3054 const rc = libc.setsockopt(@intCast(socketfd), level, optname, opaque_opt.ptr, @intCast(opaque_opt.len));
3055 if (rc == -1) return errno.fromInt(errno.fromLibC());
3056 std.debug.assert(rc == 0);
3057}
3058pub fn accept4(socketfd: c_uint, noalias address: ?*struct_sockaddr, noalias address_len: *socklen_t, flags: c_int) errno.Error!c_uint {
3059 const rc = libc.accept4(@intCast(socketfd), address, address_len, flags);
3060 if (rc == -1) return errno.fromInt(errno.fromLibC());
3061 std.debug.assert(rc > 0);
3062 return @intCast(rc);
3063}
3064pub fn send(socketfd: c_uint, buffer: []const u8, flags: c_int) errno.Error!usize {
3065 const rc = libc.send(@intCast(socketfd), buffer.ptr, buffer.len, flags);
3066 if (rc == -1) return errno.fromInt(errno.fromLibC());
3067 std.debug.assert(rc >= 0);
3068 return @intCast(rc);
3069}
3070pub fn recv(socketfd: c_uint, buffer: []u8, flags: c_int) errno.Error!usize {
3071 const rc = libc.recv(@intCast(socketfd), buffer.ptr, buffer.len, flags);
3072 if (rc == -1) return errno.fromInt(errno.fromLibC());
3073 std.debug.assert(rc >= 0);
3074 return @intCast(rc);
3075}
test.zig+10
...@@ -15,4 +15,14 @@ test {...@@ -15,4 +15,14 @@ test {
15 _ = &linux.mkdirat;15 _ = &linux.mkdirat;
16 _ = &linux.pthread_self;16 _ = &linux.pthread_self;
17 _ = &linux.gettid;17 _ = &linux.gettid;
18 _ = &linux.fstatat;
19 _ = &linux.socket;
20 _ = &linux.listen;
21 _ = &linux.bind;
22 _ = &linux.connect;
23 _ = &linux.shutdown;
24 _ = &linux.setsockopt;
25 _ = &linux.accept4;
26 _ = &linux.send;
27 _ = &linux.recv;
18}28}