diff options
author | Luke T. Shumaker <lukeshu@lukeshu.com> | 2024-11-10 22:08:02 -0700 |
---|---|---|
committer | Luke T. Shumaker <lukeshu@lukeshu.com> | 2024-11-10 22:08:02 -0700 |
commit | d84daf84d2ced072782ef3c61e5088b06d950939 (patch) | |
tree | fff4e2f44f01113dff27328e9e74caf4a12f962a /libhw/host_net.c | |
parent | 1e8897a61addec5c2067ffbab38122d6c236ced3 (diff) |
libhw: net.h: Add listener close(), add 'iface'
Diffstat (limited to 'libhw/host_net.c')
-rw-r--r-- | libhw/host_net.c | 20 |
1 files changed, 16 insertions, 4 deletions
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) { |