hare

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

commit de82b496b581e60f9de25c414b7c05bd7cdbdf44
parent 111a367e000d269fe12fabf095a71099ae84c620
Author: Sebastian <sebastian@sebsite.pw>
Date:   Sun,  5 Jun 2022 00:19:39 -0400

net: replace net::shutdown with net::close

Signed-off-by: Sebastian <sebastian@sebsite.pw>

Diffstat:
Mnet/+freebsd.ha | 24+++++++++++++++---------
Mnet/+linux.ha | 24+++++++++++++++---------
Mnet/tcp/listener.ha | 5-----
Mnet/unix/listener.ha | 4----
Mscripts/gen-stdlib | 6+++---
Mstdlib.mk | 12++++++------
6 files changed, 39 insertions(+), 36 deletions(-)

diff --git a/net/+freebsd.ha b/net/+freebsd.ha @@ -3,12 +3,8 @@ // (c) 2021 Eyal Sawady <ecs@d2evs.net> // (c) 2022 Noah Pederson <noah@packetlost.dev> use errors; -use fmt; use io; -use net::ip; -use os; use rt; -use strings; // A network socket. export type socket = io::file; @@ -42,11 +38,6 @@ export fn accept(sock: socket, flags: sockflags...) (socket | error) = { return io::fdopen(fd); }; -// Shuts down a listening socket. -export fn shutdown(sock: socket) void = { - io::close(sock)!; -}; - fn msg_to_native(msg: *msghdr) *rt::msghdr = { let native = &msg.native; if (len(msg.vectors) != 0) { @@ -81,3 +72,18 @@ export fn recvmsg(sock: socket, msg: *msghdr) (size | error) = { return errors::errno(err); }; }; + +// Closes a [[socket]]. No further operations against this socket are permitted +// after calling this function. Closing a socket can fail only under certain +// conditions (for example, closing a socket twice, or an interrupted syscall). +// However, the user should not attempt to close the file again on failure - at +// best the user should print a diagnostic message and move on. See close(2) for +// details. +// +// On FreeBSD, this function is an alias for [[io::close]]. +export fn close(sock: socket) (void | error) = match (io::close(sock)) { +case void => void; +case io::underread => abort(); +case let err: errors::error => + yield err; +}; diff --git a/net/+linux.ha b/net/+linux.ha @@ -3,12 +3,8 @@ // (c) 2021 Eyal Sawady <ecs@d2evs.net> // (c) 2022 Noah Pederson <noah@packetlost.dev> use errors; -use fmt; use io; -use net::ip; -use os; use rt; -use strings; // A network socket. export type socket = io::file; @@ -42,11 +38,6 @@ export fn accept(sock: socket, flags: sockflags...) (socket | error) = { return io::fdopen(fd); }; -// Shuts down a listening socket. -export fn shutdown(sock: socket) void = { - io::close(sock)!; -}; - fn msg_to_native(msg: *msghdr) *rt::msghdr = { let native = &msg.native; if (len(msg.vectors) != 0) { @@ -81,3 +72,18 @@ export fn recvmsg(sock: socket, msg: *msghdr) (size | error) = { return errors::errno(err); }; }; + +// Closes a [[socket]]. No further operations against this socket are permitted +// after calling this function. Closing a socket can fail only under certain +// conditions (for example, closing a socket twice, or an interrupted syscall). +// However, the user should not attempt to close the file again on failure - at +// best the user should print a diagnostic message and move on. See close(2) for +// details. +// +// On Linux, this function is an alias for [[io::close]]. +export fn close(sock: socket) (void | error) = match (io::close(sock)) { +case void => void; +case io::underread => abort(); +case let err: errors::error => + yield err; +}; diff --git a/net/tcp/listener.ha b/net/tcp/listener.ha @@ -1,6 +1,5 @@ // License: MPL-2.0 // (c) 2021 Drew DeVault <sir@cmpwn.com> -use io; use net; // Accepts the next connection from a socket. Blocks until a new connection is @@ -9,7 +8,3 @@ export fn accept( sock: net::socket, flags: net::sockflags... ) (net::socket | net::error) = net::accept(sock, flags...); - -// Shuts down a listening socket. This is a convenience wrapper around -// [[net::shutdown]]. -export fn shutdown(sock: net::socket) void = net::shutdown(sock); diff --git a/net/unix/listener.ha b/net/unix/listener.ha @@ -8,7 +8,3 @@ export fn accept( sock: net::socket, flags: net::sockflags... ) (net::socket | net::error) = net::accept(sock, flags...); - -// Shuts down a listening socket. This is a convenience wrapper around -// [[net::shutdown]]. -export fn shutdown(sock: net::socket) void = net::shutdown(sock); diff --git a/scripts/gen-stdlib b/scripts/gen-stdlib @@ -942,13 +942,13 @@ net() { +linux.ha \ errors.ha \ msg.ha - gen_ssa -plinux net io os strings net::ip errors rt fmt + gen_ssa -plinux net io errors rt fmt gen_srcs -pfreebsd net \ +freebsd.ha \ errors.ha \ msg.ha - gen_ssa -pfreebsd net io os strings net::ip errors rt fmt + gen_ssa -pfreebsd net io errors rt fmt } net_dial() { @@ -969,7 +969,7 @@ net_dns() { query.ha \ types.ha gen_ssa net::dns ascii endian net net::udp net::ip fmt strings \ - unix::resolvconf unix::poll rt time errors io + unix::resolvconf unix::poll rt time errors } gensrcs_net_ip() { diff --git a/stdlib.mk b/stdlib.mk @@ -1538,7 +1538,7 @@ stdlib_net_linux_srcs = \ $(STDLIB)/net/errors.ha \ $(STDLIB)/net/msg.ha -$(HARECACHE)/net/net-linux.ssa: $(stdlib_net_linux_srcs) $(stdlib_rt) $(stdlib_io_$(PLATFORM)) $(stdlib_os_$(PLATFORM)) $(stdlib_strings_$(PLATFORM)) $(stdlib_net_ip_$(PLATFORM)) $(stdlib_errors_$(PLATFORM)) $(stdlib_rt_$(PLATFORM)) $(stdlib_fmt_$(PLATFORM)) +$(HARECACHE)/net/net-linux.ssa: $(stdlib_net_linux_srcs) $(stdlib_rt) $(stdlib_io_$(PLATFORM)) $(stdlib_errors_$(PLATFORM)) $(stdlib_rt_$(PLATFORM)) $(stdlib_fmt_$(PLATFORM)) @printf 'HAREC \t$@\n' @mkdir -p $(HARECACHE)/net @HARECACHE=$(HARECACHE) $(HAREC) $(HAREFLAGS) -o $@ -Nnet \ @@ -1550,7 +1550,7 @@ stdlib_net_freebsd_srcs = \ $(STDLIB)/net/errors.ha \ $(STDLIB)/net/msg.ha -$(HARECACHE)/net/net-freebsd.ssa: $(stdlib_net_freebsd_srcs) $(stdlib_rt) $(stdlib_io_$(PLATFORM)) $(stdlib_os_$(PLATFORM)) $(stdlib_strings_$(PLATFORM)) $(stdlib_net_ip_$(PLATFORM)) $(stdlib_errors_$(PLATFORM)) $(stdlib_rt_$(PLATFORM)) $(stdlib_fmt_$(PLATFORM)) +$(HARECACHE)/net/net-freebsd.ssa: $(stdlib_net_freebsd_srcs) $(stdlib_rt) $(stdlib_io_$(PLATFORM)) $(stdlib_errors_$(PLATFORM)) $(stdlib_rt_$(PLATFORM)) $(stdlib_fmt_$(PLATFORM)) @printf 'HAREC \t$@\n' @mkdir -p $(HARECACHE)/net @HARECACHE=$(HARECACHE) $(HAREC) $(HAREFLAGS) -o $@ -Nnet \ @@ -1577,7 +1577,7 @@ stdlib_net_dns_any_srcs = \ $(STDLIB)/net/dns/query.ha \ $(STDLIB)/net/dns/types.ha -$(HARECACHE)/net/dns/net_dns-any.ssa: $(stdlib_net_dns_any_srcs) $(stdlib_rt) $(stdlib_ascii_$(PLATFORM)) $(stdlib_endian_$(PLATFORM)) $(stdlib_net_$(PLATFORM)) $(stdlib_net_udp_$(PLATFORM)) $(stdlib_net_ip_$(PLATFORM)) $(stdlib_fmt_$(PLATFORM)) $(stdlib_strings_$(PLATFORM)) $(stdlib_unix_resolvconf_$(PLATFORM)) $(stdlib_unix_poll_$(PLATFORM)) $(stdlib_rt_$(PLATFORM)) $(stdlib_time_$(PLATFORM)) $(stdlib_errors_$(PLATFORM)) $(stdlib_io_$(PLATFORM)) +$(HARECACHE)/net/dns/net_dns-any.ssa: $(stdlib_net_dns_any_srcs) $(stdlib_rt) $(stdlib_ascii_$(PLATFORM)) $(stdlib_endian_$(PLATFORM)) $(stdlib_net_$(PLATFORM)) $(stdlib_net_udp_$(PLATFORM)) $(stdlib_net_ip_$(PLATFORM)) $(stdlib_fmt_$(PLATFORM)) $(stdlib_strings_$(PLATFORM)) $(stdlib_unix_resolvconf_$(PLATFORM)) $(stdlib_unix_poll_$(PLATFORM)) $(stdlib_rt_$(PLATFORM)) $(stdlib_time_$(PLATFORM)) $(stdlib_errors_$(PLATFORM)) @printf 'HAREC \t$@\n' @mkdir -p $(HARECACHE)/net/dns @HARECACHE=$(HARECACHE) $(HAREC) $(HAREFLAGS) -o $@ -Nnet::dns \ @@ -3699,7 +3699,7 @@ testlib_net_linux_srcs = \ $(STDLIB)/net/errors.ha \ $(STDLIB)/net/msg.ha -$(TESTCACHE)/net/net-linux.ssa: $(testlib_net_linux_srcs) $(testlib_rt) $(testlib_io_$(PLATFORM)) $(testlib_os_$(PLATFORM)) $(testlib_strings_$(PLATFORM)) $(testlib_net_ip_$(PLATFORM)) $(testlib_errors_$(PLATFORM)) $(testlib_rt_$(PLATFORM)) $(testlib_fmt_$(PLATFORM)) +$(TESTCACHE)/net/net-linux.ssa: $(testlib_net_linux_srcs) $(testlib_rt) $(testlib_io_$(PLATFORM)) $(testlib_errors_$(PLATFORM)) $(testlib_rt_$(PLATFORM)) $(testlib_fmt_$(PLATFORM)) @printf 'HAREC \t$@\n' @mkdir -p $(TESTCACHE)/net @HARECACHE=$(TESTCACHE) $(HAREC) $(TESTHAREFLAGS) -o $@ -Nnet \ @@ -3711,7 +3711,7 @@ testlib_net_freebsd_srcs = \ $(STDLIB)/net/errors.ha \ $(STDLIB)/net/msg.ha -$(TESTCACHE)/net/net-freebsd.ssa: $(testlib_net_freebsd_srcs) $(testlib_rt) $(testlib_io_$(PLATFORM)) $(testlib_os_$(PLATFORM)) $(testlib_strings_$(PLATFORM)) $(testlib_net_ip_$(PLATFORM)) $(testlib_errors_$(PLATFORM)) $(testlib_rt_$(PLATFORM)) $(testlib_fmt_$(PLATFORM)) +$(TESTCACHE)/net/net-freebsd.ssa: $(testlib_net_freebsd_srcs) $(testlib_rt) $(testlib_io_$(PLATFORM)) $(testlib_errors_$(PLATFORM)) $(testlib_rt_$(PLATFORM)) $(testlib_fmt_$(PLATFORM)) @printf 'HAREC \t$@\n' @mkdir -p $(TESTCACHE)/net @HARECACHE=$(TESTCACHE) $(HAREC) $(TESTHAREFLAGS) -o $@ -Nnet \ @@ -3738,7 +3738,7 @@ testlib_net_dns_any_srcs = \ $(STDLIB)/net/dns/query.ha \ $(STDLIB)/net/dns/types.ha -$(TESTCACHE)/net/dns/net_dns-any.ssa: $(testlib_net_dns_any_srcs) $(testlib_rt) $(testlib_ascii_$(PLATFORM)) $(testlib_endian_$(PLATFORM)) $(testlib_net_$(PLATFORM)) $(testlib_net_udp_$(PLATFORM)) $(testlib_net_ip_$(PLATFORM)) $(testlib_fmt_$(PLATFORM)) $(testlib_strings_$(PLATFORM)) $(testlib_unix_resolvconf_$(PLATFORM)) $(testlib_unix_poll_$(PLATFORM)) $(testlib_rt_$(PLATFORM)) $(testlib_time_$(PLATFORM)) $(testlib_errors_$(PLATFORM)) $(testlib_io_$(PLATFORM)) +$(TESTCACHE)/net/dns/net_dns-any.ssa: $(testlib_net_dns_any_srcs) $(testlib_rt) $(testlib_ascii_$(PLATFORM)) $(testlib_endian_$(PLATFORM)) $(testlib_net_$(PLATFORM)) $(testlib_net_udp_$(PLATFORM)) $(testlib_net_ip_$(PLATFORM)) $(testlib_fmt_$(PLATFORM)) $(testlib_strings_$(PLATFORM)) $(testlib_unix_resolvconf_$(PLATFORM)) $(testlib_unix_poll_$(PLATFORM)) $(testlib_rt_$(PLATFORM)) $(testlib_time_$(PLATFORM)) $(testlib_errors_$(PLATFORM)) @printf 'HAREC \t$@\n' @mkdir -p $(TESTCACHE)/net/dns @HARECACHE=$(TESTCACHE) $(HAREC) $(TESTHAREFLAGS) -o $@ -Nnet::dns \