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ß <f.maass@vogl-electronic.com>
This commit is contained in:
parent
1f23e769c0
commit
03a5f417d1
13 changed files with 30 additions and 46 deletions
|
@ -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 */
|
||||
|
|
|
@ -34,10 +34,8 @@ static struct pollfd sockfd_tcp[1] = {
|
|||
static void receive_data(bool is_udp, struct net_socket_service_event *pev,
|
||||
char *buf, size_t buflen);
|
||||
|
||||
static void tcp_service_handler(struct k_work *work)
|
||||
static void tcp_service_handler(struct net_socket_service_event *pev)
|
||||
{
|
||||
struct net_socket_service_event *pev =
|
||||
CONTAINER_OF(work, struct net_socket_service_event, work);
|
||||
static char buf[1500];
|
||||
|
||||
/* Note that in this application we receive / send data from
|
||||
|
@ -48,10 +46,8 @@ static void tcp_service_handler(struct k_work *work)
|
|||
receive_data(false, pev, buf, sizeof(buf));
|
||||
}
|
||||
|
||||
static void udp_service_handler(struct k_work *work)
|
||||
static void udp_service_handler(struct net_socket_service_event *pev)
|
||||
{
|
||||
struct net_socket_service_event *pev =
|
||||
CONTAINER_OF(work, struct net_socket_service_event, work);
|
||||
static char buf[1500];
|
||||
|
||||
receive_data(true, pev, buf, sizeof(buf));
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -184,10 +184,8 @@ unlock:
|
|||
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);
|
||||
|
|
|
@ -67,7 +67,7 @@ static struct net_mgmt_event_callback mgmt_cb;
|
|||
/* Socket polling for each server connection */
|
||||
static struct zsock_pollfd fds[LLMNR_MAX_POLL];
|
||||
|
||||
static void svc_handler(struct k_work *work);
|
||||
static void svc_handler(struct net_socket_service_event *pev);
|
||||
NET_SOCKET_SERVICE_SYNC_DEFINE_STATIC(svc_llmnr, svc_handler, LLMNR_MAX_POLL);
|
||||
|
||||
NET_BUF_POOL_DEFINE(llmnr_msg_pool, DNS_RESOLVER_BUF_CTR,
|
||||
|
@ -564,10 +564,8 @@ quit:
|
|||
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);
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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 @@ error:
|
|||
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);
|
||||
|
|
|
@ -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 @@ error:
|
|||
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);
|
||||
|
|
|
@ -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 @@ error:
|
|||
}
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
|
|
|
@ -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 @@ error:
|
|||
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;
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue