hare

The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

commit aeacd2187c3123b901f7cd0f0df6b53edc9ae895
parent d7256d34cde6066a1e897d02f2b1da9137333650
Author: Mykyta Holubakha <hilobakho@gmail.com>
Date:   Sat, 13 Mar 2021 16:33:12 +0200

rt: add send(to), recv(from) syscalls

Diffstat:
Mrt/+linux/socket.ha | 29+++++++++++++++++++++++++++++
Mrt/+linux/syscalls.ha | 24++++++++++++++++++++++++
2 files changed, 53 insertions(+), 0 deletions(-)

diff --git a/rt/+linux/socket.ha b/rt/+linux/socket.ha @@ -126,3 +126,32 @@ export def IPPROTO_MPLS: int = 137; // MPLS in IP (RFC 4023) export def IPPROTO_ETHERNET: int = 143; // Ethernet-within-IPv6 Encapsulation export def IPPROTO_RAW: int = 255; // Raw IP packets export def IPPROTO_MPTCP: int = 262; // Multipath TCP connection + +// send/rcv flags +export def MSG_OOB: int = 1; +export def MSG_PEEK: int = 2; +export def MSG_DONTROUTE: int = 4; +export def MSG_TRYHARD: int = 4; // Synonym for MSG_DONTROUTE for DECnet +export def MSG_CTRUNC: int = 8; +export def MSG_PROBE: int = 0x10; // Do not send. Only probe path f.e. for MTU +export def MSG_TRUNC: int = 0x20; +export def MSG_DONTWAIT: int = 0x40; // Nonblocking io +export def MSG_EOR: int = 0x80; // End of record +export def MSG_WAITALL: int = 0x100; // Wait for a full request +export def MSG_FIN: int = 0x200; +export def MSG_SYN: int = 0x400; +export def MSG_CONFIRM: int = 0x800; // Confirm path validity +export def MSG_RST: int = 0x1000; +export def MSG_ERRQUEUE: int = 0x2000; // Fetch message from error queue +export def MSG_NOSIGNAL: int = 0x4000; // Do not generate SIGPIPE +export def MSG_MORE: int = 0x8000; // Sender will send more +export def MSG_WAITFORONE: int = 0x10000; // recvmmsg(): block until 1+ packets avail +export def MSG_SENDPAGE_NOPOLICY: int = 0x10000; // sendpage() internal : do no apply policy +export def MSG_SENDPAGE_NOTLAST: int = 0x20000; // sendpage() internal : not the last page +export def MSG_BATCH: int = 0x40000; // sendmmsg(): more messages coming +export def MSG_EOF: int = MSG_FIN; +export def MSG_NO_SHARED_FRAGS: int = 0x80000; // sendpage() internal : page frags are not shared +export def MSG_SENDPAGE_DECRYPTED: int = 0x100000; // sendpage() internal : page may carry * plain text and require encryption +export def MSG_ZEROCOPY: int = 0x4000000; // Use user data in kernel path +export def MSG_FASTOPEN: int = 0x20000000; // Send data in TCP SYN +export def MSG_CMSG_CLOEXEC: int = 0x40000000; // Set close_on_exec for file descriptor received through SCM_RIGHTS diff --git a/rt/+linux/syscalls.ha b/rt/+linux/syscalls.ha @@ -386,3 +386,27 @@ export fn accept(sockfd: int, addr: nullable *sockaddr, addrlen: nullable *u32) return wrap_return(syscall3(SYS_accept, sockfd: u64, addr: uintptr: u64, addrlen: uintptr: u64))?: int; }; + +export fn recvfrom(sockfd: int, buf: *void, len_: size, flags: int, + src_addr: nullable *sockaddr, addrlen: nullable *u32 +) (size | errno) = { + return wrap_return(syscall6(SYS_recvfrom, + sockfd: u64, buf: uintptr: u64, len_: u64, flags: u64, + src_addr: uintptr: u64, addrlen: uintptr: u64))?: size; +}; + +export fn sendto(sockfd: int, buf: *void, len_: size, flags: int, + dest_addr: nullable *sockaddr, addrlen: nullable *u32 +) (size | errno) = { + return wrap_return(syscall6(SYS_sendto, + sockfd: u64, buf: uintptr: u64, len_: u64, flags: u64, + dest_addr: uintptr: u64, addrlen: uintptr: u64))?: size; +}; + +export fn recv(sockfd: int, buf: *void, len_: size, flags: int) (size | errno) = { + return recvfrom(sockfd, buf, len_, flags, null, null); +}; + +export fn send(sockfd: int, buf: *void, len_: size, flags: int) (size | errno) = { + return sendto(sockfd, buf, len_, flags, null, null); +};