raz / commit 3543de16

commit
3543de16864b082764a176983502c7041e3743fe
author
Luis <42945842+ldiaz94@users.noreply.github.com>
date
parent
40e64d12
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.

patch · log

2 files changed, +6 -22

lib/Sys.linux-x86_64.raz (history) modified +3 -11

@@ -915,14 +915,6 @@
915915 return SYSCALL(72, fd, 4, flags); (* F_SETFL *)
916916 end;
917917
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-
926918 (* A stream socket connected to port at addr, as connectTcp makes it,
927919 or -110 (ETIMEDOUT) if it isn't connected within ms milliseconds.
928920 It starts to connect without waiting, then waits for the socket to
@@ -966,7 +958,7 @@
966958 var p: Peer; size: I32; n: INT;
967959 begin
968960 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 *)
970962 p.size := INT(size);
971963 return n, p;
972964 end;
@@ -975,7 +967,7 @@
975967 gave it: the bytes sent, or minus an errno. *)
976968 proc reply*(fd: INT; peer: Peer; s: []U8): INT;
977969 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 *)
979971 end;
980972
981973 (* Sends s, at least one byte, to the Unix socket fd, as send does, and
@@ -1003,7 +995,7 @@
1003995 proc receiveFds*(fd: INT; buf: []U8; fds: []INT): (INT, INT);
1004996 var m: Msghdr; v: Iovec; c: Rights; n, k, i: INT;
1005997 begin
1006- v := {base: bytes(buf), size: LEN(buf)};
998+ v := {base: PTR(buf), size: LEN(buf)};
1007999 m := {iov: ADR(v), iovLen: 1, control: ^U8(ADR(c)), controlSize: SIZE(Rights)};
10081000 n := SYSCALL(47, fd, ADR(m), 40000000H); (* recvmsg, MSG_CMSG_CLOEXEC *)
10091001 if n < 0 then return n, 0; end;

lib/Sys.raz (history) modified +3 -11

@@ -955,14 +955,6 @@
955955 return 0;
956956 end;
957957
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-
966958 (* A stream socket connected to port at addr, as connectTcp makes it,
967959 or -110 (ETIMEDOUT) if it isn't connected within ms milliseconds.
968960 It starts to connect without waiting, then waits for the socket to
@@ -1009,7 +1001,7 @@
10091001 var p: Peer; size: U32; n: INT;
10101002 begin
10111003 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));
10131005 if n < 0 then n := failed(); end;
10141006 p.size := INT(size);
10151007 return n, p;
@@ -1020,7 +1012,7 @@
10201012 proc reply*(fd: INT; peer: Peer; s: []U8): INT;
10211013 var r: INT;
10221014 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));
10241016 if r < 0 then return failed(); end;
10251017 return r;
10261018 end;
@@ -1061,7 +1053,7 @@
10611053 proc receiveFds*(fd: INT; buf: []U8; fds: []INT): (INT, INT);
10621054 var m: Msghdr; v: Iovec; c: Control; mp, cp: ^U8; got: ^I32; n, k, i, size: INT;
10631055 begin
1064- v := {base: bytes(buf), size: LEN(buf)};
1056+ v := {base: PTR(buf), size: LEN(buf)};
10651057 mp := ^U8(ADR(m));
10661058 cp := ^U8(ADR(c));
10671059 setField(mp, CAbi.msgIovAt, SIZE(^U8), INT(ADR(v)));