Skip to content

Commit 03a5f41

Browse files
maass-hamburgaescolar
authored andcommitted
net: sockets: socket_service: remove k_work related code
remove k_work related code and change the argument of the callback to `struct net_socket_service_event`. Signed-off-by: Fin Maaß <[email protected]>
1 parent 1f23e76 commit 03a5f41

File tree

13 files changed

+30
-46
lines changed

13 files changed

+30
-46
lines changed

include/zephyr/net/socket_service.h

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,23 @@
3232
extern "C" {
3333
#endif
3434

35+
struct net_socket_service_event;
36+
37+
/** @brief The signature for a net socket service handler function.
38+
*
39+
* The function will be invoked by the socket service.
40+
*
41+
* @param pev the socket service event that provided the handler.
42+
*/
43+
typedef void (*net_socket_service_handler_t)(struct net_socket_service_event *pev);
44+
3545
/**
3646
* This struct contains information which socket triggered
3747
* calls to the callback function.
3848
*/
3949
struct net_socket_service_event {
40-
/** k_work that is done when there is desired activity in file descriptor. */
41-
struct k_work work;
4250
/** Callback to be called for desired socket activity */
43-
k_work_handler_t callback;
51+
net_socket_service_handler_t callback;
4452
/** Socket information that triggered this event. */
4553
struct zsock_pollfd event;
4654
/** User data */

samples/net/sockets/echo_service/src/main.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,8 @@ static struct pollfd sockfd_tcp[1] = {
3434
static void receive_data(bool is_udp, struct net_socket_service_event *pev,
3535
char *buf, size_t buflen);
3636

37-
static void tcp_service_handler(struct k_work *work)
37+
static void tcp_service_handler(struct net_socket_service_event *pev)
3838
{
39-
struct net_socket_service_event *pev =
40-
CONTAINER_OF(work, struct net_socket_service_event, work);
4139
static char buf[1500];
4240

4341
/* Note that in this application we receive / send data from
@@ -48,10 +46,8 @@ static void tcp_service_handler(struct k_work *work)
4846
receive_data(false, pev, buf, sizeof(buf));
4947
}
5048

51-
static void udp_service_handler(struct k_work *work)
49+
static void udp_service_handler(struct net_socket_service_event *pev)
5250
{
53-
struct net_socket_service_event *pev =
54-
CONTAINER_OF(work, struct net_socket_service_event, work);
5551
static char buf[1500];
5652

5753
receive_data(true, pev, buf, sizeof(buf));

subsys/net/lib/dhcpv4/dhcpv4_server.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1489,10 +1489,8 @@ static void dhcpv4_process_data(struct dhcpv4_server_ctx *ctx, uint8_t *data,
14891489
k_mutex_unlock(&server_lock);
14901490
}
14911491

1492-
static void dhcpv4_server_cb(struct k_work *work)
1492+
static void dhcpv4_server_cb(struct net_socket_service_event *evt)
14931493
{
1494-
struct net_socket_service_event *evt =
1495-
CONTAINER_OF(work, struct net_socket_service_event, work);
14961494
struct dhcpv4_server_ctx *ctx = NULL;
14971495
uint8_t recv_buf[NET_IPV4_MTU];
14981496
int ret;

subsys/net/lib/dns/dispatcher.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,8 @@ static int recv_data(struct net_socket_service_event *pev)
184184
return ret;
185185
}
186186

187-
void dns_dispatcher_svc_handler(struct k_work *work)
187+
void dns_dispatcher_svc_handler(struct net_socket_service_event *pev)
188188
{
189-
struct net_socket_service_event *pev =
190-
CONTAINER_OF(work, struct net_socket_service_event, work);
191189
int ret;
192190

193191
ret = recv_data(pev);

subsys/net/lib/dns/llmnr_responder.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ static struct net_mgmt_event_callback mgmt_cb;
6767
/* Socket polling for each server connection */
6868
static struct zsock_pollfd fds[LLMNR_MAX_POLL];
6969

70-
static void svc_handler(struct k_work *work);
70+
static void svc_handler(struct net_socket_service_event *pev);
7171
NET_SOCKET_SERVICE_SYNC_DEFINE_STATIC(svc_llmnr, svc_handler, LLMNR_MAX_POLL);
7272

7373
NET_BUF_POOL_DEFINE(llmnr_msg_pool, DNS_RESOLVER_BUF_CTR,
@@ -564,10 +564,8 @@ static int recv_data(struct net_socket_service_event *pev)
564564
return ret;
565565
}
566566

567-
static void svc_handler(struct k_work *work)
567+
static void svc_handler(struct net_socket_service_event *pev)
568568
{
569-
struct net_socket_service_event *pev =
570-
CONTAINER_OF(work, struct net_socket_service_event, work);
571569
int ret;
572570

573571
ret = recv_data(pev);

subsys/net/lib/dns/mdns_responder.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ LOG_MODULE_REGISTER(net_mdns_responder, CONFIG_MDNS_RESPONDER_LOG_LEVEL);
4949
#pragma GCC diagnostic ignored "-Wstringop-overread"
5050
#endif
5151

52-
extern void dns_dispatcher_svc_handler(struct k_work *work);
52+
extern void dns_dispatcher_svc_handler(struct net_socket_service_event *pev);
5353

5454
#define MDNS_LISTEN_PORT 5353
5555

subsys/net/lib/dns/resolve.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ LOG_MODULE_REGISTER(net_dns_resolve, CONFIG_DNS_RESOLVER_LOG_LEVEL);
3434
#define DNS_SERVER_COUNT CONFIG_DNS_RESOLVER_MAX_SERVERS
3535
#define SERVER_COUNT (DNS_SERVER_COUNT + DNS_MAX_MCAST_SERVERS)
3636

37-
extern void dns_dispatcher_svc_handler(struct k_work *work);
37+
extern void dns_dispatcher_svc_handler(struct net_socket_service_event *pev);
3838

3939
NET_SOCKET_SERVICE_SYNC_DEFINE_STATIC(resolve_svc, dns_dispatcher_svc_handler,
4040
DNS_RESOLVER_MAX_POLL);

subsys/net/lib/sockets/sockets_service.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ void net_socket_service_callback(struct net_socket_service_event *pev)
124124
struct net_socket_service_desc *svc = pev->svc;
125125
struct net_socket_service_event ev = *pev;
126126

127-
ev.callback(&ev.work);
127+
ev.callback(&ev);
128128

129129
/* Copy back the socket fd to the global array because we marked
130130
* it as -1 when triggering the work.

subsys/net/lib/zperf/zperf_tcp_receiver.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ static struct sockaddr tcp_server_addr;
3939
static struct zsock_pollfd fds[SOCK_ID_MAX];
4040
static struct sockaddr sock_addr[SOCK_ID_MAX];
4141

42-
static void tcp_svc_handler(struct k_work *work);
42+
static void tcp_svc_handler(struct net_socket_service_event *pev);
4343

4444
NET_SOCKET_SERVICE_SYNC_DEFINE_STATIC(svc_tcp, tcp_svc_handler,
4545
SOCK_ID_MAX);
@@ -231,10 +231,8 @@ static int tcp_recv_data(struct net_socket_service_event *pev)
231231
return ret;
232232
}
233233

234-
static void tcp_svc_handler(struct k_work *work)
234+
static void tcp_svc_handler(struct net_socket_service_event *pev)
235235
{
236-
struct net_socket_service_event *pev =
237-
CONTAINER_OF(work, struct net_socket_service_event, work);
238236
int ret;
239237

240238
ret = tcp_recv_data(pev);

subsys/net/lib/zperf/zperf_udp_receiver.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ static struct sockaddr udp_server_addr;
4646

4747
struct zsock_pollfd fds[SOCK_ID_MAX] = { 0 };
4848

49-
static void udp_svc_handler(struct k_work *work);
49+
static void udp_svc_handler(struct net_socket_service_event *pev);
5050

5151
NET_SOCKET_SERVICE_SYNC_DEFINE_STATIC(svc_udp, udp_svc_handler,
5252
SOCK_ID_MAX);
@@ -364,10 +364,8 @@ static int udp_recv_data(struct net_socket_service_event *pev)
364364
return ret;
365365
}
366366

367-
static void udp_svc_handler(struct k_work *work)
367+
static void udp_svc_handler(struct net_socket_service_event *pev)
368368
{
369-
struct net_socket_service_event *pev =
370-
CONTAINER_OF(work, struct net_socket_service_event, work);
371369
int ret;
372370

373371
ret = udp_recv_data(pev);

0 commit comments

Comments
 (0)