diff --git a/include/zephyr/net/socket_service.h b/include/zephyr/net/socket_service.h index e63703f5d1e256e..4b6aaf23bbbd209 100644 --- a/include/zephyr/net/socket_service.h +++ b/include/zephyr/net/socket_service.h @@ -32,15 +32,23 @@ extern "C" { #endif +struct net_socket_service_event; + +/** @brief The signature for a net socket service handler function. + * + * The function will be invoked by the socket service. + * + * @param pev the socket service event that provided the handler. + */ +typedef void (*net_socket_service_handler_t)(struct net_socket_service_event *pev); + /** * This struct contains information which socket triggered * calls to the callback function. */ struct net_socket_service_event { - /** k_work that is done when there is desired activity in file descriptor. */ - struct k_work work; /** Callback to be called for desired socket activity */ - k_work_handler_t callback; + net_socket_service_handler_t callback; /** Socket information that triggered this event. */ struct zsock_pollfd event; /** User data */ diff --git a/subsys/net/lib/dhcpv4/dhcpv4_server.c b/subsys/net/lib/dhcpv4/dhcpv4_server.c index 8aca61963df33ac..d56bf83f33b41d7 100644 --- a/subsys/net/lib/dhcpv4/dhcpv4_server.c +++ b/subsys/net/lib/dhcpv4/dhcpv4_server.c @@ -1489,10 +1489,8 @@ static void dhcpv4_process_data(struct dhcpv4_server_ctx *ctx, uint8_t *data, k_mutex_unlock(&server_lock); } -static void dhcpv4_server_cb(struct k_work *work) +static void dhcpv4_server_cb(struct net_socket_service_event *evt) { - struct net_socket_service_event *evt = - CONTAINER_OF(work, struct net_socket_service_event, work); struct dhcpv4_server_ctx *ctx = NULL; uint8_t recv_buf[NET_IPV4_MTU]; int ret; diff --git a/subsys/net/lib/dns/dispatcher.c b/subsys/net/lib/dns/dispatcher.c index 380c4699a8ab31e..79a76b9b438b81e 100644 --- a/subsys/net/lib/dns/dispatcher.c +++ b/subsys/net/lib/dns/dispatcher.c @@ -181,10 +181,8 @@ static int recv_data(struct net_socket_service_event *pev) return ret; } -void dns_dispatcher_svc_handler(struct k_work *work) +void dns_dispatcher_svc_handler(struct net_socket_service_event *pev) { - struct net_socket_service_event *pev = - CONTAINER_OF(work, struct net_socket_service_event, work); int ret; ret = recv_data(pev); diff --git a/subsys/net/lib/dns/llmnr_responder.c b/subsys/net/lib/dns/llmnr_responder.c index d41429f9d31dd05..f0dead6d98c879b 100644 --- a/subsys/net/lib/dns/llmnr_responder.c +++ b/subsys/net/lib/dns/llmnr_responder.c @@ -564,10 +564,8 @@ static int recv_data(struct net_socket_service_event *pev) return ret; } -static void svc_handler(struct k_work *work) +static void svc_handler(struct net_socket_service_event *pev) { - struct net_socket_service_event *pev = - CONTAINER_OF(work, struct net_socket_service_event, work); int ret; ret = recv_data(pev); diff --git a/subsys/net/lib/dns/mdns_responder.c b/subsys/net/lib/dns/mdns_responder.c index 0eadf856c9522ad..bdf406f8f4ec386 100644 --- a/subsys/net/lib/dns/mdns_responder.c +++ b/subsys/net/lib/dns/mdns_responder.c @@ -49,7 +49,7 @@ LOG_MODULE_REGISTER(net_mdns_responder, CONFIG_MDNS_RESPONDER_LOG_LEVEL); #pragma GCC diagnostic ignored "-Wstringop-overread" #endif -extern void dns_dispatcher_svc_handler(struct k_work *work); +extern void dns_dispatcher_svc_handler(struct net_socket_service_event *pev); #define MDNS_LISTEN_PORT 5353 diff --git a/subsys/net/lib/dns/resolve.c b/subsys/net/lib/dns/resolve.c index 33514ecf553f6fb..21377cb0fa6173a 100644 --- a/subsys/net/lib/dns/resolve.c +++ b/subsys/net/lib/dns/resolve.c @@ -34,7 +34,7 @@ LOG_MODULE_REGISTER(net_dns_resolve, CONFIG_DNS_RESOLVER_LOG_LEVEL); #define DNS_SERVER_COUNT CONFIG_DNS_RESOLVER_MAX_SERVERS #define SERVER_COUNT (DNS_SERVER_COUNT + DNS_MAX_MCAST_SERVERS) -extern void dns_dispatcher_svc_handler(struct k_work *work); +extern void dns_dispatcher_svc_handler(struct net_socket_service_event *pev); NET_SOCKET_SERVICE_SYNC_DEFINE_STATIC(resolve_svc, dns_dispatcher_svc_handler, DNS_RESOLVER_MAX_POLL); diff --git a/subsys/net/lib/sockets/sockets_service.c b/subsys/net/lib/sockets/sockets_service.c index e767bacaf9cbf5a..827c78bc10b7374 100644 --- a/subsys/net/lib/sockets/sockets_service.c +++ b/subsys/net/lib/sockets/sockets_service.c @@ -124,7 +124,7 @@ void net_socket_service_callback(struct net_socket_service_event *pev) struct net_socket_service_desc *svc = pev->svc; struct net_socket_service_event ev = *pev; - ev.callback(&ev.work); + ev.callback(&ev); /* Copy back the socket fd to the global array because we marked * it as -1 when triggering the work. diff --git a/subsys/net/lib/zperf/zperf_tcp_receiver.c b/subsys/net/lib/zperf/zperf_tcp_receiver.c index b4e63ac2da13e23..3d7504313852df9 100644 --- a/subsys/net/lib/zperf/zperf_tcp_receiver.c +++ b/subsys/net/lib/zperf/zperf_tcp_receiver.c @@ -39,7 +39,7 @@ static struct sockaddr tcp_server_addr; static struct zsock_pollfd fds[SOCK_ID_MAX]; static struct sockaddr sock_addr[SOCK_ID_MAX]; -static void tcp_svc_handler(struct k_work *work); +static void tcp_svc_handler(struct net_socket_service_event *pev); NET_SOCKET_SERVICE_SYNC_DEFINE_STATIC(svc_tcp, tcp_svc_handler, SOCK_ID_MAX); @@ -231,10 +231,8 @@ static int tcp_recv_data(struct net_socket_service_event *pev) return ret; } -static void tcp_svc_handler(struct k_work *work) +static void tcp_svc_handler(struct net_socket_service_event *pev) { - struct net_socket_service_event *pev = - CONTAINER_OF(work, struct net_socket_service_event, work); int ret; ret = tcp_recv_data(pev); diff --git a/subsys/net/lib/zperf/zperf_udp_receiver.c b/subsys/net/lib/zperf/zperf_udp_receiver.c index 085cbf6ac288ea9..c29fb022f255d2a 100644 --- a/subsys/net/lib/zperf/zperf_udp_receiver.c +++ b/subsys/net/lib/zperf/zperf_udp_receiver.c @@ -46,7 +46,7 @@ static struct sockaddr udp_server_addr; struct zsock_pollfd fds[SOCK_ID_MAX] = { 0 }; -static void udp_svc_handler(struct k_work *work); +static void udp_svc_handler(struct net_socket_service_event *pev); NET_SOCKET_SERVICE_SYNC_DEFINE_STATIC(svc_udp, udp_svc_handler, SOCK_ID_MAX); @@ -364,10 +364,8 @@ static int udp_recv_data(struct net_socket_service_event *pev) return ret; } -static void udp_svc_handler(struct k_work *work) +static void udp_svc_handler(struct net_socket_service_event *pev) { - struct net_socket_service_event *pev = - CONTAINER_OF(work, struct net_socket_service_event, work); int ret; ret = udp_recv_data(pev); diff --git a/subsys/shell/backends/shell_telnet.c b/subsys/shell/backends/shell_telnet.c index 862c7d80ac8beea..d05570f6d062795 100644 --- a/subsys/shell/backends/shell_telnet.c +++ b/subsys/shell/backends/shell_telnet.c @@ -39,7 +39,7 @@ struct shell_telnet *sh_telnet; /* Basic TELNET implementation. */ -static void telnet_server_cb(struct k_work *work); +static void telnet_server_cb(struct net_socket_service_event *evt); static int telnet_init(struct shell_telnet *ctx); NET_SOCKET_SERVICE_SYNC_DEFINE_STATIC(telnet_server, telnet_server_cb, @@ -462,10 +462,8 @@ static void telnet_accept(struct zsock_pollfd *pollfd) } } -static void telnet_server_cb(struct k_work *work) +static void telnet_server_cb(struct net_socket_service_event *evt) { - struct net_socket_service_event *evt = - CONTAINER_OF(work, struct net_socket_service_event, work); int sock_error; socklen_t optlen = sizeof(int); diff --git a/subsys/shell/backends/shell_websocket.c b/subsys/shell/backends/shell_websocket.c index 27188020e87f570..28ff07048323208 100644 --- a/subsys/shell/backends/shell_websocket.c +++ b/subsys/shell/backends/shell_websocket.c @@ -24,7 +24,7 @@ LOG_MODULE_REGISTER(shell_websocket, CONFIG_SHELL_WEBSOCKET_INIT_LOG_LEVEL); #define WEBSOCKET_MIN_COMMAND_LEN 2 #define WEBSOCKET_WILL_DO_COMMAND_LEN 3 -static void ws_server_cb(struct k_work *work); +static void ws_server_cb(struct net_socket_service_event *evt); NET_SOCKET_SERVICE_SYNC_DEFINE_STATIC(websocket_server, NULL, ws_server_cb, SHELL_WEBSOCKET_SERVICE_COUNT); @@ -157,10 +157,8 @@ static void ws_recv(struct shell_websocket *ws, struct zsock_pollfd *pollfd) ws_end_client_connection(ws); } -static void ws_server_cb(struct k_work *work) +static void ws_server_cb(struct net_socket_service_event *evt) { - struct net_socket_service_event *evt = - CONTAINER_OF(work, struct net_socket_service_event, work); socklen_t optlen = sizeof(int); struct shell_websocket *ws; int sock_error; diff --git a/tests/net/socket/service/src/main.c b/tests/net/socket/service/src/main.c index dc476cf92a5854c..4e90d71cb893408 100644 --- a/tests/net/socket/service/src/main.c +++ b/tests/net/socket/service/src/main.c @@ -31,21 +31,15 @@ K_SEM_DEFINE(wait_data, 0, UINT_MAX); K_SEM_DEFINE(wait_data_tcp, 0, UINT_MAX); #define WAIT_TIME 500 -static void server_handler(struct k_work *work) +static void server_handler(struct net_socket_service_event *pev) { - struct net_socket_service_event *pev = - CONTAINER_OF(work, struct net_socket_service_event, work); - ARG_UNUSED(pev); k_sem_give(&wait_data); } -static void tcp_server_handler(struct k_work *work) +static void tcp_server_handler(struct net_socket_service_event *pev) { - struct net_socket_service_event *pev = - CONTAINER_OF(work, struct net_socket_service_event, work); - ARG_UNUSED(pev); k_sem_give(&wait_data_tcp);