Skip to content

Commit

Permalink
Merge pull request #12921 from miri64/sock_async/fix/header-foobar
Browse files Browse the repository at this point in the history
sock_async: fix cyclic include problem
  • Loading branch information
fjmolinas authored Jan 7, 2020
2 parents 56ed36f + 3896145 commit d94cd6d
Show file tree
Hide file tree
Showing 8 changed files with 206 additions and 115 deletions.
117 changes: 3 additions & 114 deletions sys/include/net/sock/async.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
*
Expand All @@ -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
*
Expand Down Expand Up @@ -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
*
Expand All @@ -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
Expand Down
157 changes: 157 additions & 0 deletions sys/include/net/sock/async/types.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
/**
* @addtogroup net_sock_async Sock extension for asynchronous access
*
* @{
*
* @file
* @brief Definitions for sock extension for asynchronous access
*
* @author Martine Lenders <m.lenders@fu-berlin.de>
*/
#ifndef NET_SOCK_ASYNC_TYPES_H
#define NET_SOCK_ASYNC_TYPES_H

#ifdef __cplusplus
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
* @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) */

#if defined (__clang__)
# pragma clang diagnostic pop
#endif

#ifdef __cplusplus
}
#endif

#endif /* NET_SOCK_ASYNC_TYPES_H */
/** @} */
11 changes: 11 additions & 0 deletions sys/include/net/sock/dtls.h
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,13 @@
#include <stdlib.h>
#include <sys/types.h>

/* 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"
Expand Down Expand Up @@ -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.
*/
Expand Down
11 changes: 11 additions & 0 deletions sys/include/net/sock/ip.h
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,13 @@
#include <stdlib.h>
#include <sys/types.h>

/* 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
Expand All @@ -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
*
Expand Down
11 changes: 11 additions & 0 deletions sys/include/net/sock/tcp.h
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,13 @@
#include <stdlib.h>
#include <sys/types.h>

/* 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
Expand All @@ -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
*
Expand Down
Loading

0 comments on commit d94cd6d

Please sign in to comment.