Sys: PTR in place of the private bytes recvfrom, sendto and recvmsg take PTR(buf), now that BOOT, v0.20.0, has it. An empty slice gives what it holds, not nil, which the kernel and the C library never read with a length of 0. write, read and send keep their test for an empty slice, which is behaviour: no call is made.
| @@ -915,14 +915,6 @@ | ||
| 915 | 915 | return SYSCALL(72, fd, 4, flags); (* F_SETFL *) |
| 916 | 916 | end; |
| 917 | 917 | |
| 918 | -(* The address of b's first byte, or nil if it has none, for a system | |
| 919 | - call that takes an address and a length. *) | |
| 920 | -proc bytes(b: []U8): ^U8; | |
| 921 | -begin | |
| 922 | - if LEN(b) = 0 then return nil; end; | |
| 923 | - return ADR(b[0]); | |
| 924 | -end; | |
| 925 | - | |
| 926 | 918 | (* A stream socket connected to port at addr, as connectTcp makes it, |
| 927 | 919 | or -110 (ETIMEDOUT) if it isn't connected within ms milliseconds. |
| 928 | 920 | It starts to connect without waiting, then waits for the socket to |
| @@ -966,7 +958,7 @@ | ||
| 966 | 958 | var p: Peer; size: I32; n: INT; |
| 967 | 959 | begin |
| 968 | 960 | size := I32(SIZE(Sockaddr)); |
| 969 | - n := SYSCALL(45, fd, bytes(buf), LEN(buf), 0, ADR(p.a), ADR(size)); (* recvfrom *) | |
| 961 | + n := SYSCALL(45, fd, PTR(buf), LEN(buf), 0, ADR(p.a), ADR(size)); (* recvfrom *) | |
| 970 | 962 | p.size := INT(size); |
| 971 | 963 | return n, p; |
| 972 | 964 | end; |
| @@ -975,7 +967,7 @@ | ||
| 975 | 967 | gave it: the bytes sent, or minus an errno. *) |
| 976 | 968 | proc reply*(fd: INT; peer: Peer; s: []U8): INT; |
| 977 | 969 | begin |
| 978 | - return SYSCALL(44, fd, bytes(s), LEN(s), 4000H, ADR(peer.a), peer.size); (* sendto, MSG_NOSIGNAL *) | |
| 970 | + return SYSCALL(44, fd, PTR(s), LEN(s), 4000H, ADR(peer.a), peer.size); (* sendto, MSG_NOSIGNAL *) | |
| 979 | 971 | end; |
| 980 | 972 | |
| 981 | 973 | (* Sends s, at least one byte, to the Unix socket fd, as send does, and |
| @@ -1003,7 +995,7 @@ | ||
| 1003 | 995 | proc receiveFds*(fd: INT; buf: []U8; fds: []INT): (INT, INT); |
| 1004 | 996 | var m: Msghdr; v: Iovec; c: Rights; n, k, i: INT; |
| 1005 | 997 | begin |
| 1006 | - v := {base: bytes(buf), size: LEN(buf)}; | |
| 998 | + v := {base: PTR(buf), size: LEN(buf)}; | |
| 1007 | 999 | m := {iov: ADR(v), iovLen: 1, control: ^U8(ADR(c)), controlSize: SIZE(Rights)}; |
| 1008 | 1000 | n := SYSCALL(47, fd, ADR(m), 40000000H); (* recvmsg, MSG_CMSG_CLOEXEC *) |
| 1009 | 1001 | if n < 0 then return n, 0; end; |
| @@ -955,14 +955,6 @@ | ||
| 955 | 955 | return 0; |
| 956 | 956 | end; |
| 957 | 957 | |
| 958 | -(* The address of b's first byte, or nil if it has none, for a call | |
| 959 | - that takes an address and a length. *) | |
| 960 | -proc bytes(b: []U8): ^U8; | |
| 961 | -begin | |
| 962 | - if LEN(b) = 0 then return nil; end; | |
| 963 | - return ADR(b[0]); | |
| 964 | -end; | |
| 965 | - | |
| 966 | 958 | (* A stream socket connected to port at addr, as connectTcp makes it, |
| 967 | 959 | or -110 (ETIMEDOUT) if it isn't connected within ms milliseconds. |
| 968 | 960 | It starts to connect without waiting, then waits for the socket to |
| @@ -1009,7 +1001,7 @@ | ||
| 1009 | 1001 | var p: Peer; size: U32; n: INT; |
| 1010 | 1002 | begin |
| 1011 | 1003 | size := U32(SIZE(Sockaddr)); |
| 1012 | - n := C.recvfrom(I32(fd), bytes(buf), UINT(LEN(buf)), 0, ^U8(ADR(p.a)), ADR(size)); | |
| 1004 | + n := C.recvfrom(I32(fd), PTR(buf), UINT(LEN(buf)), 0, ^U8(ADR(p.a)), ADR(size)); | |
| 1013 | 1005 | if n < 0 then n := failed(); end; |
| 1014 | 1006 | p.size := INT(size); |
| 1015 | 1007 | return n, p; |
| @@ -1020,7 +1012,7 @@ | ||
| 1020 | 1012 | proc reply*(fd: INT; peer: Peer; s: []U8): INT; |
| 1021 | 1013 | var r: INT; |
| 1022 | 1014 | begin |
| 1023 | - r := C.sendto(I32(fd), bytes(s), UINT(LEN(s)), CAbi.msgNosignal, ^U8(ADR(peer.a)), U32(peer.size)); | |
| 1015 | + r := C.sendto(I32(fd), PTR(s), UINT(LEN(s)), CAbi.msgNosignal, ^U8(ADR(peer.a)), U32(peer.size)); | |
| 1024 | 1016 | if r < 0 then return failed(); end; |
| 1025 | 1017 | return r; |
| 1026 | 1018 | end; |
| @@ -1061,7 +1053,7 @@ | ||
| 1061 | 1053 | proc receiveFds*(fd: INT; buf: []U8; fds: []INT): (INT, INT); |
| 1062 | 1054 | var m: Msghdr; v: Iovec; c: Control; mp, cp: ^U8; got: ^I32; n, k, i, size: INT; |
| 1063 | 1055 | begin |
| 1064 | - v := {base: bytes(buf), size: LEN(buf)}; | |
| 1056 | + v := {base: PTR(buf), size: LEN(buf)}; | |
| 1065 | 1057 | mp := ^U8(ADR(m)); |
| 1066 | 1058 | cp := ^U8(ADR(c)); |
| 1067 | 1059 | setField(mp, CAbi.msgIovAt, SIZE(^U8), INT(ADR(v))); |