From 3a443a37ef5e6bf6cd85d076ee9d7565cb455655 Mon Sep 17 00:00:00 2001 From: Martine Lenders Date: Tue, 12 Jan 2016 23:28:43 +0100 Subject: [PATCH] conn: provide API support for asynchronous IO --- sys/include/net/conn/ip.h | 17 ++++++++++++++++ sys/include/net/conn/tcp.h | 19 ++++++++++++++++++ sys/include/net/conn/types.h | 38 ++++++++++++++++++++++++++++++++++++ sys/include/net/conn/udp.h | 19 ++++++++++++++++++ 4 files changed, 93 insertions(+) create mode 100644 sys/include/net/conn/types.h diff --git a/sys/include/net/conn/ip.h b/sys/include/net/conn/ip.h index ee7cf92081ac..d0b4d0f4220d 100644 --- a/sys/include/net/conn/ip.h +++ b/sys/include/net/conn/ip.h @@ -41,6 +41,15 @@ struct conn_ip; */ typedef struct conn_ip conn_ip_t; +/** + * @brief Event callback for asynchronous communication + * + * @param[in] conn A raw IPv4/IPv6 connection object. + * @param[in] event Event type. + * @param[in] len Length of event related data. + */ +typedef void (*conn_ip_cb_t)(conn_ip_t *conn, conn_event_t event, unsigned int len); + /** * @brief Creates a new raw IPv4/IPv6 connection object * @@ -57,6 +66,14 @@ typedef struct conn_ip conn_ip_t; */ int conn_ip_create(conn_ip_t *conn, const void *addr, size_t addr_len, int family, int proto); +/** + * @brief Sets an event callback for a raw IPv4/IPv6 connection + * + * @param[in] conn A raw IPv4/IPv6 connection object. + * @param[in] cb Externally defined event callback. May be NULL to unset. + */ +void conn_ip_set_cb(conn_ip_t *conn, conn_ip_cb_t *cb); + /** * @brief Closes a raw IPv4/IPv6 connection * diff --git a/sys/include/net/conn/tcp.h b/sys/include/net/conn/tcp.h index aa02fa7e048f..e3123fef484b 100644 --- a/sys/include/net/conn/tcp.h +++ b/sys/include/net/conn/tcp.h @@ -23,6 +23,8 @@ #include #include +#include "net/conn/types.h" + #ifdef MODULE_GNRC_CONN_TCP #include "net/gnrc/conn.h" #endif @@ -41,6 +43,15 @@ struct conn_tcp; */ typedef struct conn_tcp conn_tcp_t; +/** + * @brief Event callback for asynchronous communication + * + * @param[in] conn TCP connection object. + * @param[in] event Event type. + * @param[in] len Length of event related data. + */ +typedef void (*conn_tcp_cb_t)(conn_tcp_t *conn, conn_event_t event, unsigned int len); + /** * @brief Creates a new TCP connection object * @@ -58,6 +69,14 @@ typedef struct conn_tcp conn_tcp_t; int conn_tcp_create(conn_tcp_t *conn, const void *addr, size_t addr_len, int family, uint16_t port); +/** + * @brief Sets an event callback for a TCP connection + * + * @param[in] conn A TCP connection object. + * @param[in] cb Externally defined event callback. May be NULL to unset. + */ +void conn_tcp_set_cb(conn_ip_t *conn, conn_ip_cb_t *cb); + /** * @brief Closes a TCP connection * diff --git a/sys/include/net/conn/types.h b/sys/include/net/conn/types.h new file mode 100644 index 000000000000..d626eb9c661e --- /dev/null +++ b/sys/include/net/conn/types.h @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2016 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. + */ + +/** + * @ingroup conn + * @{ + * + * @file + * @brief Generic types for @ref conn. + * + * @author Martine Lenders + */ +#ifndef CONN_TYPES_H_ +#define CONN_TYPES_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Events to signal to asynchronous callbacks. + */ +typedef conn_event { + CONN_EVENT_RECV = 0, /**< data received */ +} conn_event_t; + + +#ifdef __cplusplus +} +#endif + +#endif /* CONN_TYPES_H_ */ +/** @} */ diff --git a/sys/include/net/conn/udp.h b/sys/include/net/conn/udp.h index 68b40323fa12..8dc4d5fc1161 100644 --- a/sys/include/net/conn/udp.h +++ b/sys/include/net/conn/udp.h @@ -23,6 +23,8 @@ #include #include +#include "net/conn/types.h" + #ifdef MODULE_GNRC_CONN_UDP #include "net/gnrc/conn.h" #endif @@ -41,6 +43,15 @@ struct conn_udp; */ typedef struct conn_udp conn_udp_t; +/** + * @brief Event callback for asynchronous communication + * + * @param[in] conn A UDP connection object. + * @param[in] event Event type. + * @param[in] len Length of event related data. + */ +typedef void (*conn_udp_cb_t)(conn_udp_t *conn, conn_event_t event, unsigned int len); + /** * @brief Creates a new UDP connection object * @@ -58,6 +69,14 @@ typedef struct conn_udp conn_udp_t; int conn_udp_create(conn_udp_t *conn, const void *addr, size_t addr_len, int family, uint16_t port); +/** + * @brief Sets an event callback for a UDP connection + * + * @param[in] conn A UDP connection object. + * @param[in] cb Externally defined event callback. May be NULL to unset. + */ +void conn_udp_set_cb(conn_ip_t *conn, conn_ip_cb_t *cb); + /** * @brief Closes a UDP connection *