summaryrefslogtreecommitdiff
path: root/libhw_generic/include/libhw/generic/net.h
diff options
context:
space:
mode:
authorLuke T. Shumaker <lukeshu@lukeshu.com>2025-06-06 23:57:00 -0600
committerLuke T. Shumaker <lukeshu@lukeshu.com>2025-06-06 23:57:00 -0600
commit53d0b11262177cd212803fc9330e055871c348b3 (patch)
treead09857ab8b7a1e0f8c5bddd2b7af0bf093275cc /libhw_generic/include/libhw/generic/net.h
parentb5a29a4c57f09ed11b4591f99493fd57fdcee593 (diff)
parentb85e2a4c1bc272cb6ede732751beb55906f7e298 (diff)
Merge branch 'lukeshu/error'
Diffstat (limited to 'libhw_generic/include/libhw/generic/net.h')
-rw-r--r--libhw_generic/include/libhw/generic/net.h52
1 files changed, 20 insertions, 32 deletions
diff --git a/libhw_generic/include/libhw/generic/net.h b/libhw_generic/include/libhw/generic/net.h
index 55e4a6f..d1d4194 100644
--- a/libhw_generic/include/libhw/generic/net.h
+++ b/libhw_generic/include/libhw/generic/net.h
@@ -9,23 +9,10 @@
#include <stddef.h> /* for size_t */
#include <stdint.h> /* for uint{n}_t} */
-#include <sys/types.h> /* for ssize_t */
#include <libhw/generic/io.h>
#include <libmisc/fmt.h>
-/* Errnos *********************************************************************/
-
-#define NET_EOTHER 1
-#define NET_EARP_TIMEOUT 2
-#define NET_EACK_TIMEOUT 3
-#define NET_ERECV_TIMEOUT 4
-#define NET_ETHREAD 5
-#define NET_ECLOSED 6
-#define NET_EMSGSIZE 7
-
-const char *net_strerror(int net_errno);
-
/* Address types **************************************************************/
struct net_ip4_addr {
@@ -44,22 +31,6 @@ void fmt_print_net_eth_addr(lo_interface fmt_dest, struct net_eth_addr);
/* Streams (e.g. TCP) *********************************************************/
-lo_interface net_stream_conn;
-
-#define net_stream_listener_LO_IFACE \
- /** \
- * It is invalid to accept() a new connection if an existing \
- * connection is still open. \
- */ \
- LO_FUNC(lo_interface net_stream_conn, accept) \
- \
- /** \
- * The net_stream_conn returned from accept() may still be \
- * valid after the listener is closed. \
- */ \
- LO_NEST(io_closer)
-LO_INTERFACE(net_stream_listener);
-
#define net_stream_conn_LO_IFACE \
LO_NEST(io_readwriter) \
LO_NEST(io_bidi_closer) \
@@ -78,10 +49,27 @@ LO_INTERFACE(net_stream_listener);
LO_FUNC(void, set_read_deadline, uint64_t ns_since_boot)
LO_INTERFACE(net_stream_conn);
+typedef lo_interface net_stream_conn net_stream_conn;
+DECLARE_ERROR_OR(net_stream_conn);
+
+#define net_stream_listener_LO_IFACE \
+ /** \
+ * It is invalid to accept() a new connection if an existing \
+ * connection is still open. \
+ */ \
+ LO_FUNC(net_stream_conn_or_error, accept) \
+ \
+ /** \
+ * The net_stream_conn returned from accept() may still be \
+ * valid after the listener is closed. \
+ */ \
+ LO_NEST(io_closer)
+LO_INTERFACE(net_stream_listener);
+
/* Packets (e.g. UDP) *********************************************************/
#define net_packet_conn_LO_IFACE \
- LO_FUNC(ssize_t, sendto, \
+ LO_FUNC(error, sendto, \
void *buf, size_t len, \
struct net_ip4_addr node, uint16_t port) \
\
@@ -90,7 +78,7 @@ LO_INTERFACE(net_stream_conn);
* than the given `len` (as if the Linux MSG_TRUNC flag were \
* given). \
*/ \
- LO_FUNC(ssize_t, recvfrom, \
+ LO_FUNC(size_t_or_error, recvfrom, \
void *buf, size_t len, \
struct net_ip4_addr *ret_node, uint16_t *ret_port) \
\
@@ -125,7 +113,7 @@ struct net_iface_config {
LO_FUNC(void , ifdown ) \
\
LO_FUNC(lo_interface net_stream_listener, tcp_listen, uint16_t local_port) \
- LO_FUNC(lo_interface net_stream_conn , tcp_dial , struct net_ip4_addr remote_node, uint16_t remote_port) \
+ LO_FUNC(net_stream_conn_or_error , tcp_dial , struct net_ip4_addr remote_node, uint16_t remote_port) \
LO_FUNC(lo_interface net_packet_conn , udp_conn , uint16_t local_port) \
\
/** FIXME: arp_ping should probably have an explicit timeout or something. */ \