Zephyr API Documentation 4.0.0-rc2
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
socket_service.h
Go to the documentation of this file.
1
9/*
10 * Copyright (c) 2023 Nordic Semiconductor ASA
11 *
12 * SPDX-License-Identifier: Apache-2.0
13 */
14
15#ifndef ZEPHYR_INCLUDE_NET_SOCKET_SERVICE_H_
16#define ZEPHYR_INCLUDE_NET_SOCKET_SERVICE_H_
17
27#include <sys/types.h>
28#include <zephyr/types.h>
29#include <zephyr/net/socket.h>
30
31#ifdef __cplusplus
32extern "C" {
33#endif
34
36
44
59
71#if CONFIG_NET_SOCKETS_LOG_LEVEL >= LOG_LEVEL_DBG
76 const char *owner;
77#endif
83 int *idx;
84};
85
88#define __z_net_socket_svc_get_name(_svc_id) __z_net_socket_service_##_svc_id
89#define __z_net_socket_svc_get_idx(_svc_id) __z_net_socket_service_idx_##_svc_id
90#define __z_net_socket_svc_get_owner __FILE__ ":" STRINGIFY(__LINE__)
91
92#if CONFIG_NET_SOCKETS_LOG_LEVEL >= LOG_LEVEL_DBG
93#define NET_SOCKET_SERVICE_OWNER .owner = __z_net_socket_svc_get_owner,
94#else
95#define NET_SOCKET_SERVICE_OWNER
96#endif
97
98#define __z_net_socket_service_define(_name, _cb, _count, ...) \
99 static int __z_net_socket_svc_get_idx(_name); \
100 static struct net_socket_service_event \
101 __z_net_socket_svc_get_name(_name)[_count] = { \
102 [0 ... ((_count) - 1)] = { \
103 .event.fd = -1, /* Invalid socket */ \
104 .callback = _cb, \
105 } \
106 }; \
107 COND_CODE_0(NUM_VA_ARGS_LESS_1(__VA_ARGS__), (), __VA_ARGS__) \
108 const STRUCT_SECTION_ITERABLE(net_socket_service_desc, _name) = { \
109 NET_SOCKET_SERVICE_OWNER \
110 .pev = __z_net_socket_svc_get_name(_name), \
111 .pev_len = (_count), \
112 .idx = &__z_net_socket_svc_get_idx(_name), \
113 }
114
135#define NET_SOCKET_SERVICE_SYNC_DEFINE(name, cb, count) \
136 __z_net_socket_service_define(name, cb, count)
137
148#define NET_SOCKET_SERVICE_SYNC_DEFINE_STATIC(name, cb, count) \
149 __z_net_socket_service_define(name, cb, count, static)
150
163__syscall int net_socket_service_register(const struct net_socket_service_desc *service,
164 struct zsock_pollfd *fds, int len, void *user_data);
165
175static inline int net_socket_service_unregister(const struct net_socket_service_desc *service)
176{
177 return net_socket_service_register(service, NULL, 0, NULL);
178}
179
187typedef void (*net_socket_service_cb_t)(const struct net_socket_service_desc *svc,
188 void *user_data);
189
197
198#ifdef __cplusplus
199}
200#endif
201
202#include <zephyr/syscalls/socket_service.h>
203
208#endif /* ZEPHYR_INCLUDE_NET_SOCKET_SERVICE_H_ */
void(* net_socket_service_cb_t)(const struct net_socket_service_desc *svc, void *user_data)
Callback used while iterating over socket services.
Definition socket_service.h:187
void(* net_socket_service_handler_t)(struct net_socket_service_event *pev)
The signature for a net socket service handler function.
Definition socket_service.h:43
int net_socket_service_register(const struct net_socket_service_desc *service, struct zsock_pollfd *fds, int len, void *user_data)
Register pollable sockets.
void net_socket_service_foreach(net_socket_service_cb_t cb, void *user_data)
Go through all the socket services and call callback for each service.
static int net_socket_service_unregister(const struct net_socket_service_desc *service)
Unregister pollable sockets.
Definition socket_service.h:175
BSD Sockets compatible API definitions.
Main structure holding socket service configuration information.
Definition socket_service.h:70
const char * owner
Owner name.
Definition socket_service.h:76
int * idx
Where are my pollfd entries in the global list.
Definition socket_service.h:83
int pev_len
Length of the pollable socket array for this service.
Definition socket_service.h:81
struct net_socket_service_event * pev
Pointer to the list of services that we are listening.
Definition socket_service.h:79
This struct contains information which socket triggered calls to the callback function.
Definition socket_service.h:49
struct net_socket_service_desc * svc
Service back pointer.
Definition socket_service.h:57
struct zsock_pollfd event
Socket information that triggered this event.
Definition socket_service.h:53
net_socket_service_handler_t callback
Callback to be called for desired socket activity.
Definition socket_service.h:51
void * user_data
User data.
Definition socket_service.h:55
Definition of the monitored socket/file descriptor.
Definition socket_poll.h:31