1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

fixup! sock: Introduction of new application layer API

This commit is contained in:
Martine Lenders 2016-08-19 17:36:58 +02:00
parent 01b0975072
commit b24d9de9ae
5 changed files with 88 additions and 136 deletions

View File

@ -18,6 +18,7 @@
* About
* =====
*
* ~~~~~~~~~~~~~~~~~~~~
* +---------------+
* | Application |
* +---------------+
@ -31,6 +32,7 @@
* +---------------+
* | Network Stack |
* +---------------+
* ~~~~~~~~~~~~~~~~~~~~
*
* This module provides a minimal set of functions to establish connections or
* send and receives datagrams using different types of communication. Together,
@ -65,28 +67,25 @@
* the network stack underneath to be switched simply by changing the
* `USEMODULE` definitions in the application's Makefile.
*
* @{
*
* @file
* @brief Sock API definitions
*
* @author Alexander Aring <aar@pengutronix.de>
* @author Simon Brummer <simon.brummer@haw-hamburg.de>
* @author Cenk Gündoğan <mail@cgundogan.de>
* @author Peter Kietzmann <peter.kietzmann@haw-hamburg.de>
* @author Martine Lenders <m.lenders@fu-berlin.de>
* @author Kaspar Schleiser <kaspar@schleiser.de>
*
* @{
*
* @file
* @brief Common sock API definitions
*
* @author Martine Lenders <m.lenders@fu-berlin.de>
* @author Kaspar Schleiser <kaspar@schleiser.de>
*/
#ifndef NET_SOCK_H_
#define NET_SOCK_H_
#include <stdbool.h>
#include "net/sock/ip.h"
#include "net/sock/tcp.h"
#include "net/sock/udp.h"
#ifdef __cplusplus
extern "C" {
#endif
@ -99,13 +98,80 @@ extern "C" {
#endif
/**
* @brief Common flags for @ref net_conn
* @brief Common flags for @ref net_conn
* @name net_sock_flags
* @{
*/
#define SOCK_FLAGS_REUSE_EP (0x00000001) /**< allow to reuse end point on bind */
#define SOCK_FLAGS_REUSE_EP (0x0001) /**< allow to reuse end point on bind */
/** @} */
/**
* @brief Special netif ID for "any interface"
* @todo Use an equivalent defintion from PR #5511
*/
#define SOCK_ADDR_ANY_NETIF (0)
/**
* @brief Address to bind to any IPv4 address
*/
#define SOCK_IPV4_EP_ANY(netif) { .family = AF_INET, \
.addr = { .ipv4 = 0U }, \
.netif = (netif) }
#if defined(SOCK_HAS_IPV6) || defined(DOXYGEN)
/**
* @brief Address to bind to any IPv6 address
*/
#define SOCK_IPV6_EP_ANY(netif) { .family = AF_INET6, \
.addr = { .ipv6 = { 0 } }, \
.netif = (netif) }
#endif
/**
* @brief Abstract IP end point and end point for a raw IP sock object.
*/
typedef struct {
/**
* @brief family of sock_ip_ep_t::addr
*
* @see @ref net_af
*/
int family;
union {
#if defined(SOCK_HAS_IPV6) || defined(DOXYGEN)
/**
* @brief IPv6 address mode
*
* @note only available if @ref SOCK_HAS_IPV6 is defined.
*/
uint8_t ipv6[16];
#endif
uint32_t ipv4; /**< IPv4 address mode */
} addr; /**< address */
/**
* @brief stack-specific network interface ID
*
* @todo port to common network interface identifiers in PR #5511.
*
* Use @ref SOCK_ADDR_ANY_NETIF for any interface.
* For reception this is the local interface the message came over,
* for transmission, this is the local interface the message should be send
* over
*/
uint16_t netif;
} sock_ip_ep_t;
/**
* @brief Common IP-based transport layer end point
*/
typedef struct _sock_tl_ep {
sock_ip_ep_t ip; /**< IP end point */
uint16_t port; /**< transport layer port */
};
#ifdef __cplusplus
}
#endif

View File

@ -1,76 +0,0 @@
/*
* Copyright (C) 2016 Freie Universität Berlin
* Kaspar Schleiser <kaspar@schleiser.de>
*
* 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_addr Address abstractions
* @ingroup net_sock
* @brief Address abstractions for usage with @ref net_sock
* @{
*
* @file
* @brief Address abstraction definitions for @ref net_sock
*
* @author Martine Lenders <m.lenders@fu-berlin.de>
* @author Kaspar Schleiser <kaspar@schleiser.de>
*/
#ifndef SOCK_ADDR_H_
#define SOCK_ADDR_H_
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Special netif ID for "any interface"
* @todo Use an equivalent defintion from #5511
*/
#define SOCK_ADDR_ANY_NETIF (0)
/**
* @brief Address to bind to any IPv4 address
*/
#define SOCK_ADDR_IPV4_ANY (0U)
/**
* @brief Address to bind to any IPv6 address
*/
#define SOCK_ADDR_IPV6_ANY { { 0 } }
typedef uint32_t sock_addr_ipv4_t;
/**
* @brief Type to represent an IPv6 address
*/
typedef struct {
uint8_t u8[16]; /**< bytes of the address */
} sock_addr_ipv6_t;
/**
* @brief Type to abstract both IPv4 and IPv6 addresses
*/
typedef union {
#if defined(SOCK_HAS_IPV6) || defined(DOXYGEN)
/**
* @brief IPv6 address mode
*
* @note only available if @ref SOCK_HAS_IPV6 is defined.
*/
sock_addr_ipv6_t ipv6;
#endif
sock_addr_ipv4_t ipv4; /**< IPv4 address mode */
} sock_addr_ip_t;
#ifdef __cplusplus
}
#endif
#endif /* SOCK_ADDR_H_ */
/** @} */

View File

@ -33,7 +33,7 @@
#include <stdlib.h>
#include <sys/types.h>
#include "net/sock/addr.h"
#include "net/sock.h"
#ifdef __cplusplus
extern "C" {
@ -108,7 +108,7 @@ typedef struct sock_ip sock_ip_t;
* remote.
*/
int sock_ip_create(sock_ip_t *sock, const sock_ip_ep_t *local,
const sock_ip_ep_t *remote, uint8_t proto, uint32_t flags);
const sock_ip_ep_t *remote, uint8_t proto, uint16_t flags);
/**
* @brief Closes a raw IPv4/IPv6 sock object

View File

@ -32,32 +32,13 @@
#include <stdlib.h>
#include <sys/types.h>
#include "net/sock/addr.h"
#include "net/sock.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief An end point for a TCP sock object
*/
typedef struct {
uint16_t family; /**< family of sock_ip_ep_t::addr as defined in @ref net_af */
/**
* @brief stack-specific network interface ID
*
* @todo port to common network interface identifiers in PR #5511.
*
* Use @ref SOCK_ADDR_ANY_NETIF for any interface.
* For reception this is the local interface the message came over,
* for transmission, this is the local interface the message should be send
* over
*/
uint16_t netif;
sock_addr_ip_t addr; /**< IP address */
uint16_t port; /**< port for the TCP end point */
} sock_tcp_ep_t;
typedef struct _sock_tl_ep sock_tcp_ep_t; /**< An end point for a TCP sock object */
/**
* @brief Implementation-specific type of a TCP sock object
@ -103,7 +84,7 @@ typedef struct sock_tcp_queue sock_tcp_queue_t;
* @return -ETIMEDOUT, if the connection attempt to @p remote timed out.
*/
int sock_tcp_connect(sock_tcp_t *sock, const sock_tcp_ep_t *remote,
uint16_t local_port, uint32_t flags);
uint16_t local_port, uint16_t flags);
/**
* @brief Listen for an incoming connection request on @p local end point
@ -128,7 +109,7 @@ int sock_tcp_connect(sock_tcp_t *sock, const sock_tcp_ep_t *remote,
*/
int sock_tcp_listen(sock_tcp_queue_t *queue, const sock_tcp_ep_t *local,
sock_tcp_t[] queue_array, unsigned queue_len,
uint32_t flags);
uint16_t flags);
/**
* @brief Disconnects a TCP connection

View File

@ -33,32 +33,13 @@
#include <stdlib.h>
#include <sys/types.h>
#include "net/sock/addr.h"
#include "net/sock.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief An end point for a UDP sock object
*/
typedef struct {
uint16_t family; /**< family of sock_ip_ep_t::addr as defined in @ref net_af */
/**
* @brief stack-specific network interface ID
*
* @todo port to common network interface identifiers in PR #5511.
*
* Use @ref SOCK_ADDR_ANY_NETIF for any interface.
* For reception this is the local interface the message came over,
* for transmission, this is the local interface the message should be send
* over
*/
uint16_t netif;
sock_addr_ip_t addr; /**< IP address */
uint16_t port; /**< port for the UDP end point */
} sock_udp_ep_t;
typedef struct _sock_tl_ep sock_tcp_ep_t; /**< An end point for a TCP sock object */
/**
* @brief Implementation-specific type of a UDP sock object
@ -107,7 +88,7 @@ typedef struct sock_udp sock_udp_t;
* `
*/
int sock_udp_create(sock_udp_t *sock, const sock_udp_ep_t *local,
const sock_udp_ep_t *remote, uint32_t flags);
const sock_udp_ep_t *remote, uint16_t flags);
/**
* @brief Closes a UDP sock object