sock_async: add optional callback argument
This commit is contained in:
parent
fd618ae211
commit
6e6e435c65
@ -312,7 +312,7 @@ static void _netconn_cb(struct netconn *conn, enum netconn_evt evt,
|
||||
break;
|
||||
}
|
||||
if (flags && sock->async_cb.gen) {
|
||||
sock->async_cb.gen(sock, flags);
|
||||
sock->async_cb.gen(sock, flags, NULL);
|
||||
}
|
||||
}
|
||||
#else
|
||||
|
||||
@ -40,7 +40,8 @@ typedef struct lwip_sock_base lwip_sock_base_t;
|
||||
* @internal
|
||||
*/
|
||||
typedef void (*lwip_sock_cb_t)(lwip_sock_base_t *sock,
|
||||
sock_async_flags_t flags);
|
||||
sock_async_flags_t flags,
|
||||
void *arg);
|
||||
#endif /* SOCK_HAS_ASYNC */
|
||||
|
||||
/**
|
||||
|
||||
@ -36,8 +36,9 @@
|
||||
* event_queue_t queue;
|
||||
* uint8_t buf[128];
|
||||
*
|
||||
* void handler(sock_udp_t *sock, sock_async_flags_t type)
|
||||
* void handler(sock_udp_t *sock, sock_async_flags_t type, void *arg)
|
||||
* {
|
||||
* (void)arg;
|
||||
* if (type & SOCK_ASYNC_MSG_RECV) {
|
||||
* sock_udp_ep_t remote;
|
||||
* ssize_t res;
|
||||
@ -101,8 +102,9 @@
|
||||
* send, we print an according message:
|
||||
*
|
||||
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ {.c}
|
||||
* void handler(sock_udp_t *sock, sock_async_flags_t type)
|
||||
* void handler(sock_udp_t *sock, sock_async_flags_t type, void *arg)
|
||||
* {
|
||||
* (void)arg;
|
||||
* if (type & SOCK_ASYNC_MSG_RECV) {
|
||||
* sock_udp_ep_t remote;
|
||||
* ssize_t res;
|
||||
|
||||
@ -54,8 +54,11 @@ typedef struct sock_dtls sock_dtls_t; /**< forward declare for async */
|
||||
* - @ref SOCK_ASYNC_MSG_SENT,
|
||||
* - @ref SOCK_ASYNC_PATH_PROP, or
|
||||
* - a combination of them.
|
||||
* @param[in] arg Argument provided when setting the callback using
|
||||
* @ref sock_dtls_set_cb(). May be NULL.
|
||||
*/
|
||||
typedef void (*sock_dtls_cb_t)(sock_dtls_t *sock, sock_async_flags_t flags);
|
||||
typedef void (*sock_dtls_cb_t)(sock_dtls_t *sock, sock_async_flags_t flags,
|
||||
void *arg);
|
||||
#endif /* defined(MODULE_SOCK_DTLS) || defined(DOXYGEN) */
|
||||
|
||||
#if defined(MODULE_SOCK_IP) || defined(DOXYGEN)
|
||||
@ -74,8 +77,11 @@ typedef struct sock_ip sock_ip_t; /**< forward declare for async */
|
||||
* - @ref SOCK_ASYNC_MSG_SENT,
|
||||
* - @ref SOCK_ASYNC_PATH_PROP, or
|
||||
* - a combination of them.
|
||||
* @param[in] arg Argument provided when setting the callback using
|
||||
* @ref sock_ip_set_cb(). May be NULL.
|
||||
*/
|
||||
typedef void (*sock_ip_cb_t)(sock_ip_t *sock, sock_async_flags_t flags);
|
||||
typedef void (*sock_ip_cb_t)(sock_ip_t *sock, sock_async_flags_t flags,
|
||||
void *arg);
|
||||
#endif /* defined(MODULE_SOCK_IP) || defined(DOXYGEN) */
|
||||
|
||||
#if defined(MODULE_SOCK_TCP) || defined(DOXYGEN)
|
||||
@ -97,8 +103,11 @@ typedef struct sock_tcp_queue sock_tcp_queue_t;/**< forward declare for async */
|
||||
* - @ref SOCK_ASYNC_MSG_SENT,
|
||||
* - @ref SOCK_ASYNC_PATH_PROP, or
|
||||
* - a combination of them.
|
||||
* @param[in] arg Argument provided when setting the callback using
|
||||
* @ref sock_tcp_set_cb(). May be NULL.
|
||||
*/
|
||||
typedef void (*sock_tcp_cb_t)(sock_tcp_t *sock, sock_async_flags_t flags);
|
||||
typedef void (*sock_tcp_cb_t)(sock_tcp_t *sock, sock_async_flags_t flags,
|
||||
void *arg);
|
||||
|
||||
/**
|
||||
* @brief Event callback for @ref sock_tcp_queue_t
|
||||
@ -110,9 +119,12 @@ typedef void (*sock_tcp_cb_t)(sock_tcp_t *sock, sock_async_flags_t flags);
|
||||
* @param[in] queue The TCP listening queue the event happened on
|
||||
* @param[in] flags The event flags. The only expected value is @ref
|
||||
* SOCK_ASYNC_CONN_RECV.
|
||||
* @param[in] arg Argument provided when setting the callback using
|
||||
* @ref sock_tcp_queue_set_cb(). May be NULL.
|
||||
*/
|
||||
typedef void (*sock_tcp_queue_cb_t)(sock_tcp_queue_t *queue,
|
||||
sock_async_flags_t flags);
|
||||
sock_async_flags_t flags,
|
||||
void *arg);
|
||||
#endif /* defined(MODULE_SOCK_TCP) || defined(DOXYGEN) */
|
||||
|
||||
#if defined(MODULE_SOCK_UDP) || defined(DOXYGEN)
|
||||
@ -131,8 +143,11 @@ typedef struct sock_udp sock_udp_t; /**< forward declare for async */
|
||||
* - @ref SOCK_ASYNC_MSG_SENT,
|
||||
* - @ref SOCK_ASYNC_PATH_PROP, or
|
||||
* - a combination of them.
|
||||
* @param[in] arg Argument provided when setting the callback using
|
||||
* @ref sock_udp_set_cb(). May be NULL.
|
||||
*/
|
||||
typedef void (*sock_udp_cb_t)(sock_udp_t *sock, sock_async_flags_t type);
|
||||
typedef void (*sock_udp_cb_t)(sock_udp_t *sock, sock_async_flags_t type,
|
||||
void *arg);
|
||||
#endif /* defined(MODULE_SOCK_UDP) || defined(DOXYGEN) */
|
||||
|
||||
#ifdef SOCK_HAS_ASYNC_CTX
|
||||
|
||||
@ -46,7 +46,7 @@
|
||||
|
||||
/* Internal functions */
|
||||
static void *_event_loop(void *arg);
|
||||
static void _on_sock_evt(sock_udp_t *sock, sock_async_flags_t type);
|
||||
static void _on_sock_evt(sock_udp_t *sock, sock_async_flags_t type, void *arg);
|
||||
static ssize_t _well_known_core_handler(coap_pkt_t* pdu, uint8_t *buf, size_t len, void *ctx);
|
||||
static size_t _handle_req(coap_pkt_t *pdu, uint8_t *buf, size_t len,
|
||||
sock_udp_ep_t *remote);
|
||||
@ -128,12 +128,13 @@ static void *_event_loop(void *arg)
|
||||
}
|
||||
|
||||
/* Handles sock events from the event queue. */
|
||||
static void _on_sock_evt(sock_udp_t *sock, sock_async_flags_t type)
|
||||
static void _on_sock_evt(sock_udp_t *sock, sock_async_flags_t type, void *arg)
|
||||
{
|
||||
coap_pkt_t pdu;
|
||||
sock_udp_ep_t remote;
|
||||
gcoap_request_memo_t *memo = NULL;
|
||||
|
||||
(void)arg;
|
||||
if (type & SOCK_ASYNC_MSG_RECV) {
|
||||
ssize_t res = sock_udp_recv(sock, _listen_buf, sizeof(_listen_buf),
|
||||
0, &remote);
|
||||
|
||||
@ -58,7 +58,7 @@ static void _netapi_cb(uint16_t cmd, gnrc_pktsnip_t *pkt, void *ctx)
|
||||
(void *)®->mbox);
|
||||
}
|
||||
if (reg->async_cb.generic) {
|
||||
reg->async_cb.generic(reg, SOCK_ASYNC_MSG_RECV);
|
||||
reg->async_cb.generic(reg, SOCK_ASYNC_MSG_RECV, NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -55,7 +55,8 @@ typedef struct gnrc_sock_reg gnrc_sock_reg_t;
|
||||
* @internal
|
||||
*/
|
||||
typedef void (*gnrc_sock_reg_cb_t)(gnrc_sock_reg_t *sock,
|
||||
sock_async_flags_t flags);
|
||||
sock_async_flags_t flags,
|
||||
void *arg);
|
||||
#endif /* SOCK_HAS_ASYNC */
|
||||
|
||||
/**
|
||||
|
||||
@ -197,7 +197,8 @@ ssize_t sock_ip_send(sock_ip_t *sock, const void *data, size_t len,
|
||||
}
|
||||
#ifdef SOCK_HAS_ASYNC
|
||||
if ((sock != NULL) && (sock->reg.async_cb.ip)) {
|
||||
sock->reg.async_cb.ip(sock, SOCK_ASYNC_MSG_SENT);
|
||||
sock->reg.async_cb.ip(sock, SOCK_ASYNC_MSG_SENT,
|
||||
NULL);
|
||||
}
|
||||
#endif /* SOCK_HAS_ASYNC */
|
||||
return res;
|
||||
|
||||
@ -319,7 +319,8 @@ ssize_t sock_udp_send(sock_udp_t *sock, const void *data, size_t len,
|
||||
}
|
||||
#ifdef SOCK_HAS_ASYNC
|
||||
if ((sock != NULL) && (sock->reg.async_cb.udp)) {
|
||||
sock->reg.async_cb.udp(sock, SOCK_ASYNC_MSG_SENT);
|
||||
sock->reg.async_cb.udp(sock, SOCK_ASYNC_MSG_SENT,
|
||||
NULL);
|
||||
}
|
||||
#endif /* SOCK_HAS_ASYNC */
|
||||
return res;
|
||||
|
||||
@ -28,7 +28,10 @@ extern "C" {
|
||||
* @brief Generalized callback type
|
||||
*/
|
||||
typedef union {
|
||||
void (*generic)(void *, sock_async_flags_t); /**< anything goes */
|
||||
/**
|
||||
* @brief anything goes
|
||||
*/
|
||||
void (*generic)(void *, sock_async_flags_t, void *);
|
||||
#ifdef MODULE_SOCK_DTLS
|
||||
sock_dtls_cb_t dtls; /**< DTLS callback */
|
||||
#endif
|
||||
|
||||
@ -25,7 +25,7 @@ static void _event_handler(event_t *ev)
|
||||
event->type = 0;
|
||||
irq_restore(state);
|
||||
if (_type) {
|
||||
event->cb.generic(event->sock, _type);
|
||||
event->cb.generic(event->sock, _type, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
@ -46,8 +46,9 @@ static void _set_ctx(sock_async_ctx_t *ctx, event_queue_t *ev_queue)
|
||||
}
|
||||
|
||||
#ifdef MODULE_SOCK_DTLS
|
||||
static void _dtls_cb(sock_dtls_t *sock, sock_async_flags_t type)
|
||||
static void _dtls_cb(sock_dtls_t *sock, sock_async_flags_t type, void *arg)
|
||||
{
|
||||
(void)arg;
|
||||
_cb(sock, type, sock_dtls_get_async_ctx(sock));
|
||||
}
|
||||
|
||||
@ -63,8 +64,9 @@ void sock_dtls_event_init(sock_dtls_t *sock, event_queue_t *ev_queue,
|
||||
#endif /* MODULE_SOCK_DTLS */
|
||||
|
||||
#ifdef MODULE_SOCK_IP
|
||||
static void _ip_cb(sock_ip_t *sock, sock_async_flags_t type)
|
||||
static void _ip_cb(sock_ip_t *sock, sock_async_flags_t type, void *arg)
|
||||
{
|
||||
(void)arg;
|
||||
_cb(sock, type, sock_ip_get_async_ctx(sock));
|
||||
}
|
||||
|
||||
@ -80,8 +82,9 @@ void sock_ip_event_init(sock_ip_t *sock, event_queue_t *ev_queue,
|
||||
#endif /* MODULE_SOCK_IP */
|
||||
|
||||
#ifdef MODULE_SOCK_TCP
|
||||
static void _tcp_cb(sock_tcp_t *sock, sock_async_flags_t type)
|
||||
static void _tcp_cb(sock_tcp_t *sock, sock_async_flags_t type, void *arg)
|
||||
{
|
||||
(void)arg;
|
||||
_cb(sock, type, sock_tcp_get_async_ctx(sock));
|
||||
}
|
||||
|
||||
@ -95,8 +98,10 @@ void sock_tcp_event_init(sock_tcp_t *sock, event_queue_t *ev_queue,
|
||||
sock_tcp_set_cb(sock, _tcp_cb);
|
||||
}
|
||||
|
||||
static void _tcp_queue_cb(sock_tcp_queue_t *queue, sock_async_flags_t type)
|
||||
static void _tcp_queue_cb(sock_tcp_queue_t *queue, sock_async_flags_t type,
|
||||
void *arg)
|
||||
{
|
||||
(void)arg;
|
||||
_cb(queue, type, sock_tcp_queue_get_async_ctx(queue));
|
||||
}
|
||||
|
||||
@ -113,8 +118,9 @@ void sock_tcp_queue_event_init(sock_tcp_queue_t *queue,
|
||||
#endif /* MODULE_SOCK_TCP */
|
||||
|
||||
#ifdef MODULE_SOCK_UDP
|
||||
static void _udp_cb(sock_udp_t *sock, sock_async_flags_t type)
|
||||
static void _udp_cb(sock_udp_t *sock, sock_async_flags_t type, void *arg)
|
||||
{
|
||||
(void)arg;
|
||||
_cb(sock, type, sock_udp_get_async_ctx(sock));
|
||||
}
|
||||
|
||||
|
||||
@ -69,8 +69,9 @@ ipv6_hdr_t *gnrc_ipv6_get_header(gnrc_pktsnip_t *pkt)
|
||||
return ((ipv6_hdr_t*) tmp->data);
|
||||
}
|
||||
|
||||
static void _recv_udp(sock_udp_t *sock, sock_async_flags_t flags)
|
||||
static void _recv_udp(sock_udp_t *sock, sock_async_flags_t flags, void *arg)
|
||||
{
|
||||
(void)arg;
|
||||
printf("UDP event triggered: %04X\n", flags);
|
||||
if (flags & SOCK_ASYNC_MSG_RECV) {
|
||||
sock_udp_ep_t remote;
|
||||
@ -90,8 +91,9 @@ static void _recv_udp(sock_udp_t *sock, sock_async_flags_t flags)
|
||||
}
|
||||
}
|
||||
|
||||
static void _recv_ip(sock_ip_t *sock, sock_async_flags_t flags)
|
||||
static void _recv_ip(sock_ip_t *sock, sock_async_flags_t flags, void *arg)
|
||||
{
|
||||
(void)arg;
|
||||
printf("IP event triggered: %04X\n", flags);
|
||||
if (flags & SOCK_ASYNC_MSG_RECV) {
|
||||
sock_ip_ep_t remote;
|
||||
|
||||
@ -44,8 +44,9 @@ static sock_ip_t server_sock;
|
||||
static char server_stack[THREAD_STACKSIZE_DEFAULT];
|
||||
static msg_t server_msg_queue[SERVER_MSG_QUEUE_SIZE];
|
||||
|
||||
static void _ip_recv(sock_ip_t *sock, sock_async_flags_t flags)
|
||||
static void _ip_recv(sock_ip_t *sock, sock_async_flags_t flags, void *arg)
|
||||
{
|
||||
(void)arg;
|
||||
if (flags & SOCK_ASYNC_MSG_RECV) {
|
||||
sock_ip_ep_t src;
|
||||
int res;
|
||||
|
||||
@ -47,10 +47,11 @@ static msg_t server_msg_queue[SERVER_MSG_QUEUE_SIZE];
|
||||
static char _addr_str[IPV6_ADDR_MAX_STR_LEN];
|
||||
static event_queue_t _ev_queue;
|
||||
|
||||
static void _tcp_recv(sock_tcp_t *sock, sock_async_flags_t flags)
|
||||
static void _tcp_recv(sock_tcp_t *sock, sock_async_flags_t flags, void *arg)
|
||||
{
|
||||
sock_tcp_ep_t client;
|
||||
|
||||
(void)arg;
|
||||
if (sock_tcp_get_remote(sock, &client) < 0) {
|
||||
/* socket was disconnected between event firing and this handler */
|
||||
return;
|
||||
@ -85,8 +86,10 @@ static void _tcp_recv(sock_tcp_t *sock, sock_async_flags_t flags)
|
||||
}
|
||||
}
|
||||
|
||||
static void _tcp_accept(sock_tcp_queue_t *queue, sock_async_flags_t flags)
|
||||
static void _tcp_accept(sock_tcp_queue_t *queue, sock_async_flags_t flags,
|
||||
void *arg)
|
||||
{
|
||||
(void)arg;
|
||||
if (flags & SOCK_ASYNC_CONN_RECV) {
|
||||
sock_tcp_t *sock = NULL;
|
||||
int res;
|
||||
|
||||
@ -44,8 +44,9 @@ static sock_udp_t server_sock;
|
||||
static char server_stack[THREAD_STACKSIZE_DEFAULT];
|
||||
static msg_t server_msg_queue[SERVER_MSG_QUEUE_SIZE];
|
||||
|
||||
static void _udp_recv(sock_udp_t *sock, sock_async_flags_t flags)
|
||||
static void _udp_recv(sock_udp_t *sock, sock_async_flags_t flags, void *arg)
|
||||
{
|
||||
(void)arg;
|
||||
if (flags & SOCK_ASYNC_MSG_RECV) {
|
||||
sock_udp_ep_t src;
|
||||
int res;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user