hare

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

commit 2ad93f870f1f9c021b318574923d57f2b0699c0d
parent bcb5b4b04e5dcf9ff56da84d1546f0d60cefc8ab
Author: Thomas Bracht Laumann Jespersen <t@laumann.xyz>
Date:   Mon,  8 Nov 2021 15:45:12 +0100

net/unix: Add socketpair()

Adds a thin wrapper around around the socketpair(2) system call, that
assumes AF_UNIX, SOCK_STREAM and returns a pair of io::file handles.

Signed-off-by: Thomas Bracht Laumann Jespersen <t@laumann.xyz>

Diffstat:
Anet/unix/socketpair.ha | 18++++++++++++++++++
Mscripts/gen-stdlib | 6++++--
Mstdlib.mk | 12++++++++----
3 files changed, 30 insertions(+), 6 deletions(-)

diff --git a/net/unix/socketpair.ha b/net/unix/socketpair.ha @@ -0,0 +1,18 @@ +use rt; +use io; +use net; +use errors; +use io; + +// A thin wrapper around socketpair(2) that presumes [[rt::AF_UNIX]] for the +// domain and returns an unnamed pair of sockets of type [[rt::SOCK_STREAM]]. +export fn socketpair() ((io::file, io::file) | net::error) = { + let sv: [2]int = [0...]; + match (rt::socketpair(rt::AF_UNIX : int, rt::SOCK_STREAM : int, 0, &sv)) { + case err: rt::errno => + return errors::errno(err); + case => + return (io::fdopen(sv[0]), io::fdopen(sv[1])); + }; +}; + diff --git a/scripts/gen-stdlib b/scripts/gen-stdlib @@ -783,7 +783,8 @@ net_unix() { addr.ha \ dial.ha \ listener.ha \ - options.ha + options.ha \ + socketpair.ha gen_ssa -plinux net::unix net errors os io strings types fmt net::dial gen_srcs -pfreebsd net::unix \ @@ -791,7 +792,8 @@ net_unix() { addr.ha \ dial.ha \ listener.ha \ - options.ha + options.ha \ + socketpair.ha gen_ssa -pfreebsd net::unix net errors os io strings types fmt net::dial } diff --git a/stdlib.mk b/stdlib.mk @@ -1296,7 +1296,8 @@ stdlib_net_unix_linux_srcs= \ $(STDLIB)/net/unix/addr.ha \ $(STDLIB)/net/unix/dial.ha \ $(STDLIB)/net/unix/listener.ha \ - $(STDLIB)/net/unix/options.ha + $(STDLIB)/net/unix/options.ha \ + $(STDLIB)/net/unix/socketpair.ha $(HARECACHE)/net/unix/net_unix-linux.ssa: $(stdlib_net_unix_linux_srcs) $(stdlib_rt) $(stdlib_net_$(PLATFORM)) $(stdlib_errors_$(PLATFORM)) $(stdlib_os_$(PLATFORM)) $(stdlib_io_$(PLATFORM)) $(stdlib_strings_$(PLATFORM)) $(stdlib_types_$(PLATFORM)) $(stdlib_fmt_$(PLATFORM)) $(stdlib_net_dial_$(PLATFORM)) @printf 'HAREC \t$@\n' @@ -1310,7 +1311,8 @@ stdlib_net_unix_freebsd_srcs= \ $(STDLIB)/net/unix/addr.ha \ $(STDLIB)/net/unix/dial.ha \ $(STDLIB)/net/unix/listener.ha \ - $(STDLIB)/net/unix/options.ha + $(STDLIB)/net/unix/options.ha \ + $(STDLIB)/net/unix/socketpair.ha $(HARECACHE)/net/unix/net_unix-freebsd.ssa: $(stdlib_net_unix_freebsd_srcs) $(stdlib_rt) $(stdlib_net_$(PLATFORM)) $(stdlib_errors_$(PLATFORM)) $(stdlib_os_$(PLATFORM)) $(stdlib_io_$(PLATFORM)) $(stdlib_strings_$(PLATFORM)) $(stdlib_types_$(PLATFORM)) $(stdlib_fmt_$(PLATFORM)) $(stdlib_net_dial_$(PLATFORM)) @printf 'HAREC \t$@\n' @@ -2990,7 +2992,8 @@ testlib_net_unix_linux_srcs= \ $(STDLIB)/net/unix/addr.ha \ $(STDLIB)/net/unix/dial.ha \ $(STDLIB)/net/unix/listener.ha \ - $(STDLIB)/net/unix/options.ha + $(STDLIB)/net/unix/options.ha \ + $(STDLIB)/net/unix/socketpair.ha $(TESTCACHE)/net/unix/net_unix-linux.ssa: $(testlib_net_unix_linux_srcs) $(testlib_rt) $(testlib_net_$(PLATFORM)) $(testlib_errors_$(PLATFORM)) $(testlib_os_$(PLATFORM)) $(testlib_io_$(PLATFORM)) $(testlib_strings_$(PLATFORM)) $(testlib_types_$(PLATFORM)) $(testlib_fmt_$(PLATFORM)) $(testlib_net_dial_$(PLATFORM)) @printf 'HAREC \t$@\n' @@ -3004,7 +3007,8 @@ testlib_net_unix_freebsd_srcs= \ $(STDLIB)/net/unix/addr.ha \ $(STDLIB)/net/unix/dial.ha \ $(STDLIB)/net/unix/listener.ha \ - $(STDLIB)/net/unix/options.ha + $(STDLIB)/net/unix/options.ha \ + $(STDLIB)/net/unix/socketpair.ha $(TESTCACHE)/net/unix/net_unix-freebsd.ssa: $(testlib_net_unix_freebsd_srcs) $(testlib_rt) $(testlib_net_$(PLATFORM)) $(testlib_errors_$(PLATFORM)) $(testlib_os_$(PLATFORM)) $(testlib_io_$(PLATFORM)) $(testlib_strings_$(PLATFORM)) $(testlib_types_$(PLATFORM)) $(testlib_fmt_$(PLATFORM)) $(testlib_net_dial_$(PLATFORM)) @printf 'HAREC \t$@\n'