hare

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

commit d6e2a7e42554debce01c6e2b5b36fcd706991786
parent 7e4111ff454d6a2f742e32a27b867eb1cd4e0c8e
Author: Drew DeVault <sir@cmpwn.com>
Date:   Fri, 16 Dec 2022 09:28:46 +0100

net::udp: add recv

Signed-off-by: Drew DeVault <sir@cmpwn.com>

Diffstat:
Mnet/udp/+freebsd.ha | 15++++++++++++++-
Mnet/udp/+linux.ha | 15++++++++++++++-
2 files changed, 28 insertions(+), 2 deletions(-)

diff --git a/net/udp/+freebsd.ha b/net/udp/+freebsd.ha @@ -100,7 +100,7 @@ export fn listen( return io::fdopen(sockfd); }; -// Sends a UDP packet to the destination previously specified by [[connect]]. +// Sends a UDP packet to a [[connect]]ed UDP socket. export fn send(sock: net::socket, buf: []u8) (size | net::error) = { match (rt::send(sock, buf: *[*]u8, len(buf), 0)) { case let sz: size => @@ -127,6 +127,19 @@ export fn sendto( }; }; +// Receives a UDP packet from a [[connect]]ed UDP socket. +export fn recv( + sock: net::socket, + buf: []u8, +) (size | net::error) = { + match (rt::recv(sock, buf: *[*]u8, len(buf), 0)) { + case let sz: size => + return sz; + case let err: rt::errno => + return errors::errno(err); + }; +}; + // Receives a UDP packet from a bound socket. export fn recvfrom( sock: net::socket, diff --git a/net/udp/+linux.ha b/net/udp/+linux.ha @@ -100,7 +100,7 @@ export fn listen( return io::fdopen(sockfd); }; -// Sends a UDP packet to the destination previously specified by [[connect]]. +// Sends a UDP packet to a [[connect]]ed UDP socket. export fn send(sock: net::socket, buf: []u8) (size | net::error) = { match (rt::send(sock, buf: *[*]u8, len(buf), 0)) { case let sz: size => @@ -127,6 +127,19 @@ export fn sendto( }; }; +// Receives a UDP packet from a [[connect]]ed UDP socket. +export fn recv( + sock: net::socket, + buf: []u8, +) (size | net::error) = { + match (rt::recv(sock, buf: *[*]u8, len(buf), 0)) { + case let sz: size => + return sz; + case let err: rt::errno => + return errors::errno(err); + }; +}; + // Receives a UDP packet from a bound socket. export fn recvfrom( sock: net::socket,