commit dfa3a0becad55306a168c28cd7d95a7a4c81c047
parent 4cf3fe287657d4ff9668640611fa84a7af052662
Author: Drew DeVault <sir@cmpwn.com>
Date: Mon, 21 Jun 2021 14:20:45 -0400
net::udp: add socket_for
Signed-off-by: Drew DeVault <sir@cmpwn.com>
Diffstat:
1 file changed, 9 insertions(+), 0 deletions(-)
diff --git a/net/udp/+linux.ha b/net/udp/+linux.ha
@@ -37,6 +37,15 @@ export fn stream(sock: socket) *io::stream = {
io::mode::READ | io::mode::WRITE);
};
+// Obtains a [[socket]] for a given [[io::stream]], or returns void if it is not
+// a socket stream.
+export fn socket_for(stream: *io::stream) (socket | void) = {
+ return match (os::streamfd(stream, false)) {
+ fd: int => fd: socket,
+ void => void,
+ };
+};
+
// Creates a UDP socket bound to an interface.
export fn listen(
addr: ip::addr,