Skip to content

Commit

Permalink
net: sockets: socket_service: remove k_work related code
Browse files Browse the repository at this point in the history
remove k_work related code and change
the argument of the callback to `struct net_socket_service_event`.

Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
  • Loading branch information
maass-hamburg committed Oct 18, 2024
1 parent e03b247 commit 4c9bb69
Show file tree
Hide file tree
Showing 12 changed files with 27 additions and 39 deletions.
14 changes: 11 additions & 3 deletions include/zephyr/net/socket_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
4 changes: 1 addition & 3 deletions subsys/net/lib/dhcpv4/dhcpv4_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 1 addition & 3 deletions subsys/net/lib/dns/dispatcher.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 1 addition & 3 deletions subsys/net/lib/dns/llmnr_responder.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion subsys/net/lib/dns/mdns_responder.c
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion subsys/net/lib/dns/resolve.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion subsys/net/lib/sockets/sockets_service.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 2 additions & 4 deletions subsys/net/lib/zperf/zperf_tcp_receiver.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 2 additions & 4 deletions subsys/net/lib/zperf/zperf_udp_receiver.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 2 additions & 4 deletions subsys/shell/backends/shell_telnet.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);

Expand Down
6 changes: 2 additions & 4 deletions subsys/shell/backends/shell_websocket.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
10 changes: 2 additions & 8 deletions tests/net/socket/service/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 4c9bb69

Please sign in to comment.