commit 53081a0b2e5c289a425f8728f86c3de9c606d22d
parent 87f4c645f4c969a179c6dd6da5bf877191c7dfdb
Author: Sebastian <sebastian@sebsite.pw>
Date: Fri, 12 May 2023 21:20:38 -0400
net: implement shutdown
Implements: https://todo.sr.ht/~sircmpwn/hare/512
Signed-off-by: Sebastian <sebastian@sebsite.pw>
Diffstat:
5 files changed, 36 insertions(+), 6 deletions(-)
diff --git a/net/+freebsd.ha b/net/+freebsd.ha
@@ -85,3 +85,12 @@ case io::underread => abort();
case let err: errors::error =>
yield err;
};
+
+// Shuts down part of a full-duplex connection.
+export fn shutdown(sock: socket, how: shut) (void | error) = {
+ match (rt::shutdown(sock, how)) {
+ case void => void;
+ case let err: rt::errno =>
+ return errors::errno(err);
+ };
+};
diff --git a/net/+linux.ha b/net/+linux.ha
@@ -85,3 +85,12 @@ case io::underread => abort();
case let err: errors::error =>
yield err;
};
+
+// Shuts down part of a full-duplex connection.
+export fn shutdown(sock: socket, how: shut) (void | error) = {
+ match (rt::shutdown(sock, how)) {
+ case void => void;
+ case let err: rt::errno =>
+ return errors::errno(err);
+ };
+};
diff --git a/net/types.ha b/net/types.ha
@@ -0,0 +1,6 @@
+// The end of the full-duplex connection that should be [[shutdown]].
+export type shut = enum {
+ RD, // Disables further receptions.
+ WR, // Disables further transmissions.
+ RDWR, // Disables further receptions and transmissions.
+};
diff --git a/scripts/gen-stdlib b/scripts/gen-stdlib
@@ -1004,13 +1004,15 @@ net() {
gen_srcs -plinux net \
+linux.ha \
errors.ha \
- msg.ha
+ msg.ha \
+ types.ha
gen_ssa -plinux net io errors rt fmt slices
gen_srcs -pfreebsd net \
+freebsd.ha \
errors.ha \
- msg.ha
+ msg.ha \
+ types.ha
gen_ssa -pfreebsd net io errors rt fmt slices
}
diff --git a/stdlib.mk b/stdlib.mk
@@ -1715,7 +1715,8 @@ $(HARECACHE)/math/random/math_random-any.ssa: $(stdlib_math_random_any_srcs) $(s
stdlib_net_linux_srcs = \
$(STDLIB)/net/+linux.ha \
$(STDLIB)/net/errors.ha \
- $(STDLIB)/net/msg.ha
+ $(STDLIB)/net/msg.ha \
+ $(STDLIB)/net/types.ha
$(HARECACHE)/net/net-linux.ssa: $(stdlib_net_linux_srcs) $(stdlib_rt) $(stdlib_io_$(PLATFORM)) $(stdlib_errors_$(PLATFORM)) $(stdlib_rt_$(PLATFORM)) $(stdlib_fmt_$(PLATFORM)) $(stdlib_slices_$(PLATFORM))
@printf 'HAREC \t$@\n'
@@ -1727,7 +1728,8 @@ $(HARECACHE)/net/net-linux.ssa: $(stdlib_net_linux_srcs) $(stdlib_rt) $(stdlib_i
stdlib_net_freebsd_srcs = \
$(STDLIB)/net/+freebsd.ha \
$(STDLIB)/net/errors.ha \
- $(STDLIB)/net/msg.ha
+ $(STDLIB)/net/msg.ha \
+ $(STDLIB)/net/types.ha
$(HARECACHE)/net/net-freebsd.ssa: $(stdlib_net_freebsd_srcs) $(stdlib_rt) $(stdlib_io_$(PLATFORM)) $(stdlib_errors_$(PLATFORM)) $(stdlib_rt_$(PLATFORM)) $(stdlib_fmt_$(PLATFORM)) $(stdlib_slices_$(PLATFORM))
@printf 'HAREC \t$@\n'
@@ -4163,7 +4165,8 @@ $(TESTCACHE)/math/random/math_random-any.ssa: $(testlib_math_random_any_srcs) $(
testlib_net_linux_srcs = \
$(STDLIB)/net/+linux.ha \
$(STDLIB)/net/errors.ha \
- $(STDLIB)/net/msg.ha
+ $(STDLIB)/net/msg.ha \
+ $(STDLIB)/net/types.ha
$(TESTCACHE)/net/net-linux.ssa: $(testlib_net_linux_srcs) $(testlib_rt) $(testlib_io_$(PLATFORM)) $(testlib_errors_$(PLATFORM)) $(testlib_rt_$(PLATFORM)) $(testlib_fmt_$(PLATFORM)) $(testlib_slices_$(PLATFORM))
@printf 'HAREC \t$@\n'
@@ -4175,7 +4178,8 @@ $(TESTCACHE)/net/net-linux.ssa: $(testlib_net_linux_srcs) $(testlib_rt) $(testli
testlib_net_freebsd_srcs = \
$(STDLIB)/net/+freebsd.ha \
$(STDLIB)/net/errors.ha \
- $(STDLIB)/net/msg.ha
+ $(STDLIB)/net/msg.ha \
+ $(STDLIB)/net/types.ha
$(TESTCACHE)/net/net-freebsd.ssa: $(testlib_net_freebsd_srcs) $(testlib_rt) $(testlib_io_$(PLATFORM)) $(testlib_errors_$(PLATFORM)) $(testlib_rt_$(PLATFORM)) $(testlib_fmt_$(PLATFORM)) $(testlib_slices_$(PLATFORM))
@printf 'HAREC \t$@\n'