From d84daf84d2ced072782ef3c61e5088b06d950939 Mon Sep 17 00:00:00 2001 From: "Luke T. Shumaker" Date: Sun, 10 Nov 2024 22:08:02 -0700 Subject: libhw: net.h: Add listener close(), add 'iface' --- libhw/host_net.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'libhw/host_net.c') diff --git a/libhw/host_net.c b/libhw/host_net.c index 75486aa..88bda49 100644 --- a/libhw/host_net.c +++ b/libhw/host_net.c @@ -92,14 +92,16 @@ static inline ssize_t hostnet_map_negerrno(ssize_t v) { /* TCP init() ( AKA socket(3) + listen(3) )************************************/ -static implements_net_stream_conn *hostnet_tcp_accept(implements_net_stream_listener *_listener); +static implements_net_stream_conn *hostnet_tcplist_accept(implements_net_stream_listener *); +static int hostnet_tcplist_close(implements_net_stream_listener *); static void hostnet_tcp_set_read_deadline(implements_net_stream_conn *conn, uint64_t ts_ns); static ssize_t hostnet_tcp_read(implements_net_stream_conn *conn, void *buf, size_t count); static ssize_t hostnet_tcp_write(implements_net_stream_conn *conn, void *buf, size_t count); static int hostnet_tcp_close(implements_net_stream_conn *conn, bool rd, bool wr); static struct net_stream_listener_vtable hostnet_tcp_listener_vtable = { - .accept = hostnet_tcp_accept, + .accept = hostnet_tcplist_accept, + .close = hostnet_tcplist_close, }; static struct net_stream_conn_vtable hostnet_tcp_conn_vtable = { @@ -136,7 +138,7 @@ void hostnet_tcp_listener_init(struct hostnet_tcp_listener *self, uint16_t port) self->fd = listenerfd; } -/* TCP accept() ***************************************************************/ +/* TCP listener accept() ******************************************************/ struct hostnet_pthread_accept_args { pthread_t cr_thread; @@ -156,7 +158,7 @@ static void *hostnet_pthread_accept(void *_args) { return NULL; } -static implements_net_stream_conn *hostnet_tcp_accept(implements_net_stream_listener *_listener) { +static implements_net_stream_conn *hostnet_tcplist_accept(implements_net_stream_listener *_listener) { struct hostnet_tcp_listener *listener = VCALL_SELF(struct hostnet_tcp_listener, implements_net_stream_listener, _listener); assert(listener); @@ -176,6 +178,16 @@ static implements_net_stream_conn *hostnet_tcp_accept(implements_net_stream_list return &listener->active_conn; } +/* TCP listener close() *******************************************************/ + +static int hostnet_tcplist_close(implements_net_stream_listener *_listener) { + struct hostnet_tcp_listener *listener = + VCALL_SELF(struct hostnet_tcp_listener, implements_net_stream_listener, _listener); + assert(listener); + + return hostnet_map_negerrno(close(listener->fd) ? -errno : 0); +} + /* TCP read() *****************************************************************/ static void hostnet_tcp_set_read_deadline(implements_net_stream_conn *_conn, uint64_t ts_ns) { -- cgit v1.2.3-2-g168b