Loading...
Searching...
No Matches
sock_internal.h
1/*
2 * Copyright (C) 2016 Freie Universität Berlin
3 *
4 * This file is subject to the terms and conditions of the GNU Lesser
5 * General Public License v2.1. See the file LICENSE in the top level
6 * directory for more details.
7 */
8
9#pragma once
10
24
25#include <assert.h>
26#include <stdbool.h>
27#include <stdint.h>
28
29#include "net/af.h"
30#include "net/sock.h"
31#include "time_units.h"
32
33#include "lwip/ip_addr.h"
34#include "lwip/api.h"
35
36#ifdef __cplusplus
37extern "C" {
38#endif
39
44#ifndef LWIP_SOCK_TCP_ACCEPT_TIMEOUT
45#define LWIP_SOCK_TCP_ACCEPT_TIMEOUT (0)
46#endif
47
53int lwip_sock_create(struct netconn **conn, const struct _sock_tl_ep *local,
54 const struct _sock_tl_ep *remote, int proto,
55 uint16_t flags, int type);
56uint16_t lwip_sock_bind_addr_to_netif(const ip_addr_t *bind_addr);
57int lwip_sock_get_addr(struct netconn *conn, struct _sock_tl_ep *ep, u8_t local);
58#if defined(MODULE_LWIP_SOCK_UDP) || defined(MODULE_LWIP_SOCK_IP)
59int lwip_sock_recv(struct netconn *conn, uint32_t timeout, struct netbuf **buf);
60#endif
61ssize_t lwip_sock_sendv(struct netconn *conn, const iolist_t *snips,
62 int proto, const struct _sock_tl_ep *remote, int type);
63static inline ssize_t lwip_sock_send(struct netconn *conn,
64 const void *data, size_t len,
65 int proto, const struct _sock_tl_ep *remote, int type)
66{
67 iolist_t snip = {
68 .iol_base = (void *)data,
69 .iol_len = len,
70 };
71
72 return lwip_sock_sendv(conn, &snip, proto, remote, type);
73}
74
88static inline uint32_t lwip_sock_timeout_ms(uint32_t timeout)
89{
90 assert((timeout != 0) && (timeout != SOCK_NO_TIMEOUT));
91
92 /* DIV_ROUND_UP() is not used here, because its (a + b - 1) form overflows
93 * for large timeouts on platforms where unsigned long is 32 bit */
94 return (timeout - 1) / US_PER_MS + 1;
95}
96
100
101#ifdef __cplusplus
102}
103#endif
104
Global UNIX address family definitions.
POSIX.1-2008 compliant version of the assert macro.
#define assert(cond)
abort the program if assertion is false
Definition assert.h:143
#define SOCK_NO_TIMEOUT
Special value meaning "wait forever" (don't timeout)
Definition sock.h:169
struct iolist iolist_t
iolist forward declaration
Definition iolist.h:30
#define US_PER_MS
The number of microseconds per millisecond.
Definition time_units.h:86
Common sock API definitions.
Common IP-based transport layer end point.
Definition sock.h:211
Utility header providing time unit defines.