From 43b1c5c74c9baa3a286e272ff0afb01823a8daa2 Mon Sep 17 00:00:00 2001 From: "Martine S. Lenders" Date: Wed, 11 Dec 2019 09:55:49 +0100 Subject: [PATCH 1/4] sock_async: fix cyclic dependency with sock_types.h Typically a stack needs to add the callback for a sock as a member of its respective `sock` type so `sock_types.h` needs to include `net/sock/async.h` at the moment. As those however include `net/sock/.h`, which in turn include `sock_types.h`, we create a cyclic dependency. This fix resolves this cyclic dependency, by putting the callback definitions in its own header that then in turn can be also included by `sock_types.h`. --- sys/include/net/sock/async.h | 117 +---------------------- sys/include/net/sock/async/types.h | 146 +++++++++++++++++++++++++++++ 2 files changed, 149 insertions(+), 114 deletions(-) create mode 100644 sys/include/net/sock/async/types.h diff --git a/sys/include/net/sock/async.h b/sys/include/net/sock/async.h index 75f4cfe75c..7f61958c55 100644 --- a/sys/include/net/sock/async.h +++ b/sys/include/net/sock/async.h @@ -23,63 +23,14 @@ #ifndef NET_SOCK_ASYNC_H #define NET_SOCK_ASYNC_H -#ifdef MODULE_SOCK_DTLS -#include "net/sock/dtls.h" -#endif - -#ifdef MODULE_SOCK_IP -#include "net/sock/ip.h" -#endif - -#ifdef MODULE_SOCK_TCP -#include "net/sock/tcp.h" -#endif - -#ifdef MODULE_SOCK_UDP -#include "net/sock/udp.h" -#endif +#include "net/sock/async/types.h" #ifdef __cplusplus extern "C" { #endif #if defined(SOCK_HAS_ASYNC) || defined(DOXYGEN) -#ifdef SOCK_HAS_ASYNC_CTX -#include "sock_async_ctx.h" /* defines sock_async_ctx_t */ -#endif - -/** - * @brief Flag types to signify asynchronous sock events - * @note Only applicable with @ref SOCK_HAS_ASYNC defined. - */ -typedef enum { - SOCK_ASYNC_CONN_RDY = 0x0001, /**< Connection ready event */ - SOCK_ASYNC_CONN_FIN = 0x0002, /**< Connection finished event */ - SOCK_ASYNC_CONN_RECV = 0x0004, /**< Listener received connection event */ - SOCK_ASYNC_MSG_RECV = 0x0010, /**< Message received event */ - SOCK_ASYNC_MSG_SENT = 0x0020, /**< Message sent event */ - SOCK_ASYNC_PATH_PROP = 0x0040, /**< Path property changed event */ -} sock_async_flags_t; - #if defined(MODULE_SOCK_DTLS) || defined(DOXYGEN) -/** - * @brief Event callback for @ref sock_dtls_t - * - * @pre `(sock != NULL)` - * - * @note Only applicable with @ref SOCK_HAS_ASYNC defined. - * - * @param[in] sock The sock the event happened on - * @param[in] flags The event flags. Expected values are - * - @ref SOCK_ASYNC_CONN_RDY (if a session you created becomes ready), - * - @ref SOCK_ASYNC_CONN_FIN (if a created session was destroyed), - * - @ref SOCK_ASYNC_CONN_RECV (if a peer tries to create a session), - * - @ref SOCK_ASYNC_MSG_RECV, - * - @ref SOCK_ASYNC_MSG_SENT, - * - @ref SOCK_ASYNC_PATH_PROP, or - * - a combination of them. - */ -typedef void (*sock_dtls_cb_t)(sock_dtls_t *sock, sock_async_flags_t flags); /** * @brief Gets the asynchronous event context from sock object @@ -98,22 +49,6 @@ void sock_dtls_set_cb(sock_dtls_t *sock, sock_dtls_cb_t cb); #endif /* defined(MODULE_SOCK_DTLS) || defined(DOXYGEN) */ #if defined(MODULE_SOCK_IP) || defined(DOXYGEN) -/** - * @brief Event callback for @ref sock_ip_t - * - * @pre `(sock != NULL)` - * - * @note Only applicable with @ref SOCK_HAS_ASYNC defined. - * - * @param[in] sock The sock the event happened on - * @param[in] flags The event flags. Expected values are - * - @ref SOCK_ASYNC_MSG_RECV, - * - @ref SOCK_ASYNC_MSG_SENT, - * - @ref SOCK_ASYNC_PATH_PROP, or - * - a combination of them. - */ -typedef void (*sock_ip_cb_t)(sock_ip_t *sock, sock_async_flags_t flags); - /** * @brief Sets event callback for @ref sock_ip_t * @@ -131,38 +66,6 @@ void sock_ip_set_cb(sock_ip_t *sock, sock_ip_cb_t cb); #endif /* defined(MODULE_SOCK_IP) || defined(DOXYGEN) */ #if defined(MODULE_SOCK_TCP) || defined(DOXYGEN) -/** - * @brief Event callback for @ref sock_tcp_t - * - * @pre `(sock != NULL)` - * - * @note Only applicable with @ref SOCK_HAS_ASYNC defined. - * - * @param[in] sock The sock the event happened on - * @param[in] flags The event flags. Expected values are - * - @ref SOCK_ASYNC_CONN_RDY, - * - @ref SOCK_ASYNC_CONN_FIN, - * - @ref SOCK_ASYNC_MSG_RECV, - * - @ref SOCK_ASYNC_MSG_SENT, - * - @ref SOCK_ASYNC_PATH_PROP, or - * - a combination of them. - */ -typedef void (*sock_tcp_cb_t)(sock_tcp_t *sock, sock_async_flags_t flags); - -/** - * @brief Event callback for @ref sock_tcp_queue_t - * - * @pre `(queue != NULL)` - * - * @note Only applicable with @ref SOCK_HAS_ASYNC defined. - * - * @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. - */ -typedef void (*sock_tcp_queue_cb_t)(sock_tcp_queue_t *queue, - sock_async_flags_t flags); - /** * @brief Sets event callback for @ref sock_tcp_t * @@ -195,22 +98,6 @@ void sock_tcp_queue_set_cb(sock_tcp_queue_t *queue, sock_tcp_queue_cb_t cb); #endif /* defined(MODULE_SOCK_TCP) || defined(DOXYGEN) */ #if defined(MODULE_SOCK_UDP) || defined(DOXYGEN) -/** - * @brief Event callback for @ref sock_udp_t - * - * @pre `(sock != NULL)` - * - * @note Only applicable with @ref SOCK_HAS_ASYNC defined. - * - * @param[in] sock The sock the event happened on - * @param[in] flags The event flags. Expected values are - * - @ref SOCK_ASYNC_MSG_RECV, - * - @ref SOCK_ASYNC_MSG_SENT, - * - @ref SOCK_ASYNC_PATH_PROP, or - * - a combination of them. - */ -typedef void (*sock_udp_cb_t)(sock_udp_t *sock, sock_async_flags_t type); - /** * @brief Gets the asynchronous event context from sock object * @@ -228,6 +115,8 @@ void sock_udp_set_cb(sock_udp_t *sock, sock_udp_cb_t cb); #endif /* defined(MODULE_SOCK_UDP) || defined(DOXYGEN) */ #if defined(SOCK_HAS_ASYNC_CTX) || defined(DOXYGEN) +#include "sock_async_ctx.h" /* defines sock_async_ctx_t */ + #if defined(MODULE_SOCK_DTLS) || defined(DOXYGEN) /** * @brief Gets the asynchronous event context from sock object diff --git a/sys/include/net/sock/async/types.h b/sys/include/net/sock/async/types.h new file mode 100644 index 0000000000..c93cd25068 --- /dev/null +++ b/sys/include/net/sock/async/types.h @@ -0,0 +1,146 @@ +/** + * @addtogroup net_sock_async Sock extension for asynchronous access + * + * @{ + * + * @file + * @brief Definitions for sock extension for asynchronous access + * + * @author Martine Lenders + */ +#ifndef NET_SOCK_ASYNC_TYPES_H +#define NET_SOCK_ASYNC_TYPES_H + +#ifdef __cplusplus +extern "C" { +#endif + +#if defined(SOCK_HAS_ASYNC) || defined(DOXYGEN) +/** + * @brief Flag types to signify asynchronous sock events + * @note Only applicable with @ref SOCK_HAS_ASYNC defined. + */ +typedef enum { + SOCK_ASYNC_CONN_RDY = 0x0001, /**< Connection ready event */ + SOCK_ASYNC_CONN_FIN = 0x0002, /**< Connection finished event */ + SOCK_ASYNC_CONN_RECV = 0x0004, /**< Listener received connection event */ + SOCK_ASYNC_MSG_RECV = 0x0010, /**< Message received event */ + SOCK_ASYNC_MSG_SENT = 0x0020, /**< Message sent event */ + SOCK_ASYNC_PATH_PROP = 0x0040, /**< Path property changed event */ +} sock_async_flags_t; + +#if defined(MODULE_SOCK_DTLS) || defined(DOXYGEN) +typedef struct sock_dtls sock_dtls_t; /**< forward declare for async */ + +/** + * @brief Event callback for @ref sock_dtls_t + * + * @pre `(sock != NULL)` + * + * @note Only applicable with @ref SOCK_HAS_ASYNC defined. + * + * @param[in] sock The sock the event happened on + * @param[in] flags The event flags. Expected values are + * - @ref SOCK_ASYNC_CONN_RDY (if a session you created becomes ready), + * - @ref SOCK_ASYNC_CONN_FIN (if a created session was destroyed), + * - @ref SOCK_ASYNC_CONN_RECV (if a peer tries to create a session), + * - @ref SOCK_ASYNC_MSG_RECV, + * - @ref SOCK_ASYNC_MSG_SENT, + * - @ref SOCK_ASYNC_PATH_PROP, or + * - a combination of them. + */ +typedef void (*sock_dtls_cb_t)(sock_dtls_t *sock, sock_async_flags_t flags); +#endif /* defined(MODULE_SOCK_DTLS) || defined(DOXYGEN) */ + +#if defined(MODULE_SOCK_IP) || defined(DOXYGEN) +typedef struct sock_ip sock_ip_t; /**< forward declare for async */ + +/** + * @brief Event callback for @ref sock_ip_t + * + * @pre `(sock != NULL)` + * + * @note Only applicable with @ref SOCK_HAS_ASYNC defined. + * + * @param[in] sock The sock the event happened on + * @param[in] flags The event flags. Expected values are + * - @ref SOCK_ASYNC_MSG_RECV, + * - @ref SOCK_ASYNC_MSG_SENT, + * - @ref SOCK_ASYNC_PATH_PROP, or + * - a combination of them. + */ +typedef void (*sock_ip_cb_t)(sock_ip_t *sock, sock_async_flags_t flags); +#endif /* defined(MODULE_SOCK_IP) || defined(DOXYGEN) */ + +#if defined(MODULE_SOCK_TCP) || defined(DOXYGEN) +typedef struct sock_tcp sock_tcp_t; /**< forward declare for async */ +typedef struct sock_tcp sock_tcp_quee_t; /**< forward declare for async */ + +/** + * @brief Event callback for @ref sock_tcp_t + * + * @pre `(sock != NULL)` + * + * @note Only applicable with @ref SOCK_HAS_ASYNC defined. + * + * @param[in] sock The sock the event happened on + * @param[in] flags The event flags. Expected values are + * - @ref SOCK_ASYNC_CONN_RDY, + * - @ref SOCK_ASYNC_CONN_FIN, + * - @ref SOCK_ASYNC_MSG_RECV, + * - @ref SOCK_ASYNC_MSG_SENT, + * - @ref SOCK_ASYNC_PATH_PROP, or + * - a combination of them. + */ +typedef void (*sock_tcp_cb_t)(sock_tcp_t *sock, sock_async_flags_t flags); + +/** + * @brief Event callback for @ref sock_tcp_queue_t + * + * @pre `(queue != NULL)` + * + * @note Only applicable with @ref SOCK_HAS_ASYNC defined. + * + * @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. + */ +typedef void (*sock_tcp_queue_cb_t)(sock_tcp_queue_t *queue, + sock_async_flags_t flags); +#endif /* defined(MODULE_SOCK_TCP) || defined(DOXYGEN) */ + +#if defined(MODULE_SOCK_UDP) || defined(DOXYGEN) +typedef struct sock_udp sock_udp_t; /**< forward declare for async */ + +/** + * @brief Event callback for @ref sock_udp_t + * + * @pre `(sock != NULL)` + * + * @note Only applicable with @ref SOCK_HAS_ASYNC defined. + * + * @param[in] sock The sock the event happened on + * @param[in] flags The event flags. Expected values are + * - @ref SOCK_ASYNC_MSG_RECV, + * - @ref SOCK_ASYNC_MSG_SENT, + * - @ref SOCK_ASYNC_PATH_PROP, or + * - a combination of them. + */ +typedef void (*sock_udp_cb_t)(sock_udp_t *sock, sock_async_flags_t type); +#endif /* defined(MODULE_SOCK_UDP) || defined(DOXYGEN) */ + +#include "sock_types.h" +#ifdef MODULE_SOCK_DTLS +#include "sock_dtls_types.h" +#endif /* MODULE_SOCK_DTLS */ +#ifdef SOCK_HAS_ASYNC_CTX +#include "sock_async_ctx.h" +#endif +#endif /* defined(SOCK_HAS_ASYNC) || defined(DOXYGEN) */ + +#ifdef __cplusplus +} +#endif + +#endif /* NET_SOCK_ASYNC_TYPES_H */ +/** @} */ From 37d99c11b0553c6bf0045bbd2386bf7e31b8f376 Mon Sep 17 00:00:00 2001 From: "Martine S. Lenders" Date: Wed, 11 Dec 2019 10:04:01 +0100 Subject: [PATCH 2/4] =?UTF-8?q?gnrc=5Fsock:=20use=20`=E2=80=A6/async/types?= =?UTF-8?q?.h`=20instead=20of=20`=E2=80=A6/async.h`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sys/net/gnrc/sock/include/sock_types.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sys/net/gnrc/sock/include/sock_types.h b/sys/net/gnrc/sock/include/sock_types.h index 59d25aee2d..76e43ee5bb 100644 --- a/sys/net/gnrc/sock/include/sock_types.h +++ b/sys/net/gnrc/sock/include/sock_types.h @@ -30,7 +30,7 @@ #include "net/gnrc.h" #include "net/gnrc/netreg.h" #ifdef SOCK_HAS_ASYNC -#include "net/sock/async.h" +#include "net/sock/async/types.h" #endif #include "net/sock/ip.h" #include "net/sock/udp.h" From 82180a8bb657870500210daefbe2e945ba5739d4 Mon Sep 17 00:00:00 2001 From: "Martine S. Lenders" Date: Wed, 11 Dec 2019 10:04:28 +0100 Subject: [PATCH 3/4] test/gnrc_sock_async: include `net/sock/async.h` --- tests/gnrc_sock_async/main.c | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/gnrc_sock_async/main.c b/tests/gnrc_sock_async/main.c index 470e2144ce..116f82a6d5 100644 --- a/tests/gnrc_sock_async/main.c +++ b/tests/gnrc_sock_async/main.c @@ -20,6 +20,7 @@ #include #include "net/ipv6/addr.h" #include "net/ipv6/hdr.h" +#include "net/sock/async.h" #include "net/sock/ip.h" #include "net/sock/udp.h" #include "net/gnrc.h" From 3896145c31d19a57163842ca941052cc3546825e Mon Sep 17 00:00:00 2001 From: "Martine S. Lenders" Date: Mon, 6 Jan 2020 15:31:41 +0100 Subject: [PATCH 4/4] sock: ignore `-Wtypedef-redefinition` for LLVM where needed net/sock/async/types.h included by net/sock.h needs to re-typedef the the sock types to prevent cyclic includes. --- sys/include/net/sock/async/types.h | 11 +++++++++++ sys/include/net/sock/dtls.h | 11 +++++++++++ sys/include/net/sock/ip.h | 11 +++++++++++ sys/include/net/sock/tcp.h | 11 +++++++++++ sys/include/net/sock/udp.h | 11 +++++++++++ 5 files changed, 55 insertions(+) diff --git a/sys/include/net/sock/async/types.h b/sys/include/net/sock/async/types.h index c93cd25068..314fff89b9 100644 --- a/sys/include/net/sock/async/types.h +++ b/sys/include/net/sock/async/types.h @@ -15,6 +15,12 @@ extern "C" { #endif +/* This header needs to re-typedef the sock types to prevent cyclic includes */ +#if defined (__clang__) +# pragma clang diagnostic push +# pragma clang diagnostic ignored "-Wtypedef-redefinition" +#endif + #if defined(SOCK_HAS_ASYNC) || defined(DOXYGEN) /** * @brief Flag types to signify asynchronous sock events @@ -133,11 +139,16 @@ typedef void (*sock_udp_cb_t)(sock_udp_t *sock, sock_async_flags_t type); #ifdef MODULE_SOCK_DTLS #include "sock_dtls_types.h" #endif /* MODULE_SOCK_DTLS */ + #ifdef SOCK_HAS_ASYNC_CTX #include "sock_async_ctx.h" #endif #endif /* defined(SOCK_HAS_ASYNC) || defined(DOXYGEN) */ +#if defined (__clang__) +# pragma clang diagnostic pop +#endif + #ifdef __cplusplus } #endif diff --git a/sys/include/net/sock/dtls.h b/sys/include/net/sock/dtls.h index 3c237ebc1f..bdbabaee1d 100644 --- a/sys/include/net/sock/dtls.h +++ b/sys/include/net/sock/dtls.h @@ -461,6 +461,13 @@ #include #include +/* net/sock/async/types.h included by net/sock.h needs to re-typedef the + * `sock_dtls_t` to prevent cyclic includes */ +#if defined (__clang__) +# pragma clang diagnostic push +# pragma clang diagnostic ignored "-Wtypedef-redefinition" +#endif + #include "net/sock.h" #include "net/sock/udp.h" #include "net/credman.h" @@ -500,6 +507,10 @@ enum { */ typedef struct sock_dtls sock_dtls_t; +#if defined (__clang__) +# pragma clang diagnostic pop +#endif + /** * @brief Information about a created session. */ diff --git a/sys/include/net/sock/ip.h b/sys/include/net/sock/ip.h index e6000bbfb0..be79478b16 100644 --- a/sys/include/net/sock/ip.h +++ b/sys/include/net/sock/ip.h @@ -273,6 +273,13 @@ #include #include +/* net/sock/async/types.h included by net/sock.h needs to re-typedef the + * `sock_ip_t` to prevent cyclic includes */ +#if defined (__clang__) +# pragma clang diagnostic push +# pragma clang diagnostic ignored "-Wtypedef-redefinition" +#endif + #include "net/sock.h" #ifdef __cplusplus @@ -287,6 +294,10 @@ extern "C" { */ typedef struct sock_ip sock_ip_t; +#if defined (__clang__) +# pragma clang diagnostic pop +#endif + /** * @brief Creates a new raw IPv4/IPv6 sock object * diff --git a/sys/include/net/sock/tcp.h b/sys/include/net/sock/tcp.h index ebdc374fcc..a8d5310cec 100644 --- a/sys/include/net/sock/tcp.h +++ b/sys/include/net/sock/tcp.h @@ -303,6 +303,13 @@ #include #include +/* net/sock/async/types.h included by net/sock.h needs to re-typedef the + * `sock_tcp_t` and `sock_tcp_queue_t` to prevent cyclic includes */ +#if defined (__clang__) +# pragma clang diagnostic push +# pragma clang diagnostic ignored "-Wtypedef-redefinition" +#endif + #include "net/sock.h" #ifdef __cplusplus @@ -327,6 +334,10 @@ typedef struct sock_tcp sock_tcp_t; */ typedef struct sock_tcp_queue sock_tcp_queue_t; +#if defined (__clang__) +# pragma clang diagnostic pop +#endif + /** * @brief Establishes a new TCP sock connection * diff --git a/sys/include/net/sock/udp.h b/sys/include/net/sock/udp.h index f8b978e629..428c61af7e 100644 --- a/sys/include/net/sock/udp.h +++ b/sys/include/net/sock/udp.h @@ -273,6 +273,13 @@ #include #include +/* net/sock/async/types.h included by net/sock.h needs to re-typedef the + * `sock_ip_t` to prevent cyclic includes */ +#if defined (__clang__) +# pragma clang diagnostic push +# pragma clang diagnostic ignored "-Wtypedef-redefinition" +#endif + #include "net/sock.h" #ifdef __cplusplus @@ -289,6 +296,10 @@ typedef struct _sock_tl_ep sock_udp_ep_t; /**< An end point for a UDP sock obj */ typedef struct sock_udp sock_udp_t; +#if defined (__clang__) +# pragma clang diagnostic pop +#endif + /** * @brief Creates a new UDP sock object *