commit 3e91f9f48112fdac1cd2714af5266d1b155dc364
parent 2c1911d1aa537dd0f3c1a313a1438f04d8315ba8
Author: Armin Preiml <apreiml@strohwolke.at>
Date: Tue, 31 Dec 2024 15:44:42 +0100
net: add sockflag::DGRAM to +linux
Signed-off-by: Armin Preiml <apreiml@strohwolke.at>
Diffstat:
2 files changed, 10 insertions(+), 2 deletions(-)
diff --git a/net/+linux.ha b/net/+linux.ha
@@ -13,7 +13,8 @@ export type socket = io::file;
// Note that CLOEXEC is on by default, and NOCLOEXEC flag disables it.
export type sockflag = enum int {
NOCLOEXEC = rt::SOCK_CLOEXEC,
- NONBLOCK = rt::SOCK_NONBLOCK
+ NONBLOCK = rt::SOCK_NONBLOCK,
+ DGRAM = rt::SOCK_DGRAM,
};
// Accepts the next connection from a socket. Blocks until a new connection is
diff --git a/net/unix/+linux.ha b/net/unix/+linux.ha
@@ -25,7 +25,14 @@ export fn connect(
f |= options[i];
};
f ^= rt::SOCK_CLOEXEC; // invert CLOEXEC
- const sockfd = match (rt::socket(rt::AF_UNIX: int, rt::SOCK_STREAM | f, 0)) {
+
+ // set default type if none provided. assumes that socket types will
+ // not outgrow 0xf and additional flags will not be added within 0xf.
+ if (f & 0xf == 0) {
+ f |= rt::SOCK_STREAM;
+ };
+
+ const sockfd = match (rt::socket(rt::AF_UNIX: int, f, 0)) {
case let err: rt::errno =>
return errors::errno(err);
case let fd: int =>