2018-12-14 13:52:31 +01:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2019 Freie Universität Berlin
|
|
|
|
*
|
|
|
|
* This file is subject to the terms and conditions of the GNU Lesser
|
|
|
|
* General Public License v2.1. See the file LICENSE in the top level
|
|
|
|
* directory for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @defgroup net_sock_async Sock extension for asynchronous access
|
|
|
|
* @ingroup net_sock
|
|
|
|
* @brief Provides backend functionality for asynchronous sock access.
|
|
|
|
* @experimental This API extension is still under development and should
|
|
|
|
* not be used in production yet.
|
|
|
|
*
|
|
|
|
* @{
|
|
|
|
*
|
|
|
|
* @file
|
|
|
|
* @brief Definitions for sock extension for asynchronous access
|
|
|
|
*
|
|
|
|
* @author Martine Lenders <m.lenders@fu-berlin.de>
|
|
|
|
*/
|
|
|
|
#ifndef NET_SOCK_ASYNC_H
|
|
|
|
#define NET_SOCK_ASYNC_H
|
|
|
|
|
2019-12-11 09:55:49 +01:00
|
|
|
#include "net/sock/async/types.h"
|
2018-12-14 13:52:31 +01:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2019-10-31 15:59:14 +01:00
|
|
|
#if defined(SOCK_HAS_ASYNC) || defined(DOXYGEN)
|
|
|
|
#if defined(MODULE_SOCK_DTLS) || defined(DOXYGEN)
|
2018-12-14 13:52:31 +01:00
|
|
|
|
2021-01-12 19:19:33 +01:00
|
|
|
/**
|
|
|
|
* @brief Gets the asynchronous event session from sock object
|
|
|
|
*
|
|
|
|
* @pre `(sock != NULL) && (session != NULL)`
|
|
|
|
*
|
|
|
|
* @note Only available with @ref SOCK_HAS_ASYNC defined.
|
|
|
|
* Should only be called within a DTLS event and session is only available
|
|
|
|
* for the event types @ref SOCK_ASYNC_CONN_RDY and @ref SOCK_ASYNC_CONN_FIN.
|
|
|
|
* For other event types use @ref sock_dtls_recv() to get the session.
|
|
|
|
*
|
|
|
|
* @param[in] sock The DTLS sock object of the current event.
|
|
|
|
* @param[out] session Session object of the current event.
|
|
|
|
*
|
|
|
|
* @return true if the event session is available, false otherwise.
|
|
|
|
*/
|
|
|
|
bool sock_dtls_get_event_session(sock_dtls_t *sock,
|
|
|
|
sock_dtls_session_t *session);
|
|
|
|
|
2018-12-14 13:52:31 +01:00
|
|
|
/**
|
2021-01-12 19:21:21 +01:00
|
|
|
* @brief Sets the asynchronous event context from sock object
|
2018-12-14 13:52:31 +01:00
|
|
|
*
|
|
|
|
* @pre `(sock != NULL)`
|
|
|
|
*
|
|
|
|
* @warning Never handle the callback in the caller's context! You might block
|
|
|
|
* the operation of the network stack or the DTLS library with that.
|
|
|
|
*
|
|
|
|
* @note Only available with @ref SOCK_HAS_ASYNC defined.
|
|
|
|
*
|
2020-03-11 12:17:30 +01:00
|
|
|
* @param[in] sock A DTLS sock object.
|
|
|
|
* @param[in] cb An event callback. May be NULL to unset event callback.
|
|
|
|
* @param[in] cb_arg Argument to provide to @p cb. May be NULL.
|
2018-12-14 13:52:31 +01:00
|
|
|
*/
|
2020-03-11 12:17:30 +01:00
|
|
|
void sock_dtls_set_cb(sock_dtls_t *sock, sock_dtls_cb_t cb, void *cb_arg);
|
2019-10-31 15:59:14 +01:00
|
|
|
#endif /* defined(MODULE_SOCK_DTLS) || defined(DOXYGEN) */
|
2018-12-14 13:52:31 +01:00
|
|
|
|
2019-10-31 15:59:14 +01:00
|
|
|
#if defined(MODULE_SOCK_IP) || defined(DOXYGEN)
|
2018-12-14 13:52:31 +01:00
|
|
|
/**
|
|
|
|
* @brief Sets event callback for @ref sock_ip_t
|
|
|
|
*
|
|
|
|
* @pre `(sock != NULL)`
|
|
|
|
*
|
|
|
|
* @warning Never handle the callback in the caller's context! You might block
|
|
|
|
* the operation of the network stack with that.
|
|
|
|
*
|
|
|
|
* @note Only available with @ref SOCK_HAS_ASYNC defined.
|
|
|
|
*
|
|
|
|
* @param[in] sock A raw IPv4/IPv6 sock object.
|
|
|
|
* @param[in] cb An event callback. May be NULL to unset event callback.
|
2020-03-11 12:17:30 +01:00
|
|
|
* @param[in] cb_arg Argument to provide to @p cb. May be NULL.
|
2018-12-14 13:52:31 +01:00
|
|
|
*/
|
2020-03-11 12:17:30 +01:00
|
|
|
void sock_ip_set_cb(sock_ip_t *sock, sock_ip_cb_t cb, void *cb_arg);
|
2019-10-31 15:59:14 +01:00
|
|
|
#endif /* defined(MODULE_SOCK_IP) || defined(DOXYGEN) */
|
2018-12-14 13:52:31 +01:00
|
|
|
|
2019-10-31 15:59:14 +01:00
|
|
|
#if defined(MODULE_SOCK_TCP) || defined(DOXYGEN)
|
2018-12-14 13:52:31 +01:00
|
|
|
/**
|
|
|
|
* @brief Sets event callback for @ref sock_tcp_t
|
|
|
|
*
|
|
|
|
* @pre `(sock != NULL)`
|
|
|
|
*
|
|
|
|
* @warning Never handle the callback in the caller's context! You might block
|
|
|
|
* the operation of the network stack with that.
|
|
|
|
*
|
|
|
|
* @note Only available with @ref SOCK_HAS_ASYNC defined.
|
|
|
|
*
|
2020-03-11 12:17:30 +01:00
|
|
|
* @param[in] sock A TCP sock object.
|
|
|
|
* @param[in] cb An event callback. May be NULL to unset event callback.
|
|
|
|
* @param[in] cb_arg Argument to provide to @p cb. May be NULL.
|
2018-12-14 13:52:31 +01:00
|
|
|
*/
|
2020-03-11 12:17:30 +01:00
|
|
|
void sock_tcp_set_cb(sock_tcp_t *sock, sock_tcp_cb_t cb, void *cb_arg);
|
2018-12-14 13:52:31 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Sets event callback for @ref sock_tcp_queue_t
|
|
|
|
*
|
|
|
|
* @pre `(sock != NULL)`
|
|
|
|
*
|
|
|
|
* @warning Never handle the callback in the caller's context! You might block
|
|
|
|
* the operation of the network stack with that.
|
|
|
|
*
|
|
|
|
* @note Only available with @ref SOCK_HAS_ASYNC defined.
|
|
|
|
*
|
2020-03-11 12:17:30 +01:00
|
|
|
* @param[in] queue A TCP listening queue.
|
|
|
|
* @param[in] cb An event callback. May be NULL to unset event callback.
|
|
|
|
* @param[in] cb_arg Argument to provide to @p cb. May be NULL.
|
2018-12-14 13:52:31 +01:00
|
|
|
*/
|
2020-03-11 12:17:30 +01:00
|
|
|
void sock_tcp_queue_set_cb(sock_tcp_queue_t *queue, sock_tcp_queue_cb_t cb,
|
|
|
|
void *cb_arg);
|
2019-10-31 15:59:14 +01:00
|
|
|
#endif /* defined(MODULE_SOCK_TCP) || defined(DOXYGEN) */
|
2018-12-14 13:52:31 +01:00
|
|
|
|
2019-10-31 15:59:14 +01:00
|
|
|
#if defined(MODULE_SOCK_UDP) || defined(DOXYGEN)
|
2018-12-14 13:52:31 +01:00
|
|
|
/**
|
|
|
|
* @brief Gets the asynchronous event context from sock object
|
|
|
|
*
|
|
|
|
* @pre `(sock != NULL)`
|
|
|
|
*
|
|
|
|
* @warning Never handle the callback in the caller's context! You might block
|
|
|
|
* the operation of the network stack with that.
|
|
|
|
*
|
|
|
|
* @note Only available with @ref SOCK_HAS_ASYNC defined.
|
|
|
|
*
|
2020-03-11 12:17:30 +01:00
|
|
|
* @param[in] sock A UDP sock object.
|
|
|
|
* @param[in] cb An event callback. May be NULL to unset event callback.
|
|
|
|
* @param[in] cb_arg Argument to provide to @p cb
|
2018-12-14 13:52:31 +01:00
|
|
|
*/
|
2020-03-11 12:17:30 +01:00
|
|
|
void sock_udp_set_cb(sock_udp_t *sock, sock_udp_cb_t cb, void *cb_arg);
|
2019-10-31 15:59:14 +01:00
|
|
|
#endif /* defined(MODULE_SOCK_UDP) || defined(DOXYGEN) */
|
2018-12-14 13:52:31 +01:00
|
|
|
|
2019-10-31 15:59:14 +01:00
|
|
|
#if defined(SOCK_HAS_ASYNC_CTX) || defined(DOXYGEN)
|
2019-12-11 09:55:49 +01:00
|
|
|
#include "sock_async_ctx.h" /* defines sock_async_ctx_t */
|
|
|
|
|
2019-10-31 15:59:14 +01:00
|
|
|
#if defined(MODULE_SOCK_DTLS) || defined(DOXYGEN)
|
2018-12-14 13:52:31 +01:00
|
|
|
/**
|
|
|
|
* @brief Gets the asynchronous event context from sock object
|
|
|
|
*
|
|
|
|
* @pre `(sock != NULL)`
|
|
|
|
*
|
|
|
|
* @note Only available with @ref SOCK_HAS_ASYNC and @ref SOCK_HAS_ASYNC_CTX
|
|
|
|
* defined.
|
|
|
|
*
|
|
|
|
* @see @ref SOCK_HAS_ASYNC_CTX
|
|
|
|
*
|
|
|
|
* @param[in] sock A DTLS sock object.
|
|
|
|
*
|
|
|
|
* @return The asynchronous event context
|
|
|
|
*/
|
|
|
|
sock_async_ctx_t *sock_dtls_get_async_ctx(sock_dtls_t *sock);
|
2019-10-31 15:59:14 +01:00
|
|
|
#endif /* defined(MODULE_SOCK_DTLS) || defined(DOXYGEN) */
|
2018-12-14 13:52:31 +01:00
|
|
|
|
2019-10-31 15:59:14 +01:00
|
|
|
#if defined(MODULE_SOCK_IP) || defined(DOXYGEN)
|
2018-12-14 13:52:31 +01:00
|
|
|
/**
|
|
|
|
* @brief Gets the asynchronous event context from sock object
|
|
|
|
*
|
|
|
|
* @pre `(sock != NULL)`
|
|
|
|
*
|
|
|
|
* @note Only available with @ref SOCK_HAS_ASYNC and @ref SOCK_HAS_ASYNC_CTX
|
|
|
|
* defined.
|
|
|
|
*
|
|
|
|
* @see @ref SOCK_HAS_ASYNC_CTX
|
|
|
|
*
|
|
|
|
* @param[in] sock A raw IPv4/IPv6 sock object.
|
|
|
|
*
|
|
|
|
* @return The asynchronous event context
|
|
|
|
*/
|
|
|
|
sock_async_ctx_t *sock_ip_get_async_ctx(sock_ip_t *sock);
|
2019-10-31 15:59:14 +01:00
|
|
|
#endif /* defined(MODULE_SOCK_IP) || defined(DOXYGEN) */
|
2018-12-14 13:52:31 +01:00
|
|
|
|
2019-10-31 15:59:14 +01:00
|
|
|
#if defined(MODULE_SOCK_TCP) || defined(DOXYGEN)
|
2018-12-14 13:52:31 +01:00
|
|
|
/**
|
|
|
|
* @brief Gets the asynchronous event context from sock object
|
|
|
|
*
|
|
|
|
* @pre `(sock != NULL)`
|
|
|
|
*
|
|
|
|
* @note Only available with @ref SOCK_HAS_ASYNC and @ref SOCK_HAS_ASYNC_CTX
|
|
|
|
* defined.
|
|
|
|
*
|
|
|
|
* @see @ref SOCK_HAS_ASYNC_CTX
|
|
|
|
*
|
|
|
|
* @param[in] sock A TCP sock object.
|
|
|
|
*
|
|
|
|
* @return The asynchronous event context
|
|
|
|
*/
|
|
|
|
sock_async_ctx_t *sock_tcp_get_async_ctx(sock_tcp_t *sock);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Gets the asynchronous event context from TCP listening queue
|
|
|
|
*
|
|
|
|
* @pre `(queue != NULL)`
|
|
|
|
*
|
|
|
|
* @note Only available with @ref SOCK_HAS_ASYNC and @ref SOCK_HAS_ASYNC_CTX
|
|
|
|
* defined.
|
|
|
|
*
|
|
|
|
* @see @ref SOCK_HAS_ASYNC_CTX
|
|
|
|
*
|
|
|
|
* @param[in] queue A TCP listening queue.
|
|
|
|
*
|
|
|
|
* @return The asynchronous event context
|
|
|
|
*/
|
|
|
|
sock_async_ctx_t *sock_tcp_queue_get_async_ctx(sock_tcp_queue_t *queue);
|
2019-10-31 15:59:14 +01:00
|
|
|
#endif /* defined(MODULE_SOCK_TCP) || defined(DOXYGEN) */
|
2018-12-14 13:52:31 +01:00
|
|
|
|
2019-10-31 15:59:14 +01:00
|
|
|
#if defined(MODULE_SOCK_UDP) || defined(DOXYGEN)
|
2018-12-14 13:52:31 +01:00
|
|
|
/**
|
|
|
|
* @brief Gets the asynchronous event context from sock object
|
|
|
|
*
|
|
|
|
* @pre `(sock != NULL)`
|
|
|
|
*
|
|
|
|
* @note Only available with @ref SOCK_HAS_ASYNC and @ref SOCK_HAS_ASYNC_CTX
|
|
|
|
* defined.
|
|
|
|
*
|
|
|
|
* @see @ref SOCK_HAS_ASYNC_CTX
|
|
|
|
*
|
|
|
|
* @param[in] sock A UDP sock object.
|
|
|
|
*
|
|
|
|
* @return The asynchronous event context
|
|
|
|
*/
|
|
|
|
sock_async_ctx_t *sock_udp_get_async_ctx(sock_udp_t *sock);
|
2019-10-31 15:59:14 +01:00
|
|
|
#endif /* defined(MODULE_SOCK_UDP) || defined(DOXYGEN) */
|
|
|
|
#endif /* defined(SOCK_HAS_ASYNC_CTX) || defined(DOXYGEN) */
|
|
|
|
#endif /* defined(SOCK_HAS_ASYNC) || defined(DOXYGEN) */
|
2018-12-14 13:52:31 +01:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* NET_SOCK_ASYNC_H */
|
|
|
|
/** @} */
|