Loading...
Searching...
No Matches
sock_internal.h
1/*
2 * SPDX-FileCopyrightText: 2016 Freie Universität Berlin
3 * SPDX-License-Identifier: LGPL-2.1-only
4 */
5
6#pragma once
7
21
22#include <assert.h>
23#include <stdbool.h>
24#include <stdint.h>
25
26#include "net/af.h"
27#include "net/sock.h"
28#include "time_units.h"
29
30#include "lwip/ip_addr.h"
31#include "lwip/api.h"
32
33#ifdef __cplusplus
34extern "C" {
35#endif
36
41#ifndef LWIP_SOCK_TCP_ACCEPT_TIMEOUT
42#define LWIP_SOCK_TCP_ACCEPT_TIMEOUT (0)
43#endif
44
50int lwip_sock_create(struct netconn **conn, const struct _sock_tl_ep *local,
51 const struct _sock_tl_ep *remote, int proto,
52 uint16_t flags, int type);
53uint16_t lwip_sock_bind_addr_to_netif(const ip_addr_t *bind_addr);
54int lwip_sock_get_addr(struct netconn *conn, struct _sock_tl_ep *ep, u8_t local);
55#if defined(MODULE_LWIP_SOCK_UDP) || defined(MODULE_LWIP_SOCK_IP)
56int lwip_sock_recv(struct netconn *conn, uint32_t timeout, struct netbuf **buf);
57#endif
58ssize_t lwip_sock_sendv(struct netconn *conn, const iolist_t *snips,
59 int proto, const struct _sock_tl_ep *remote, int type);
60static inline ssize_t lwip_sock_send(struct netconn *conn,
61 const void *data, size_t len,
62 int proto, const struct _sock_tl_ep *remote, int type)
63{
64 iolist_t snip = {
65 .iol_base = (void *)data,
66 .iol_len = len,
67 };
68
69 return lwip_sock_sendv(conn, &snip, proto, remote, type);
70}
71
85static inline uint32_t lwip_sock_timeout_ms(uint32_t timeout)
86{
87 assert((timeout != 0) && (timeout != SOCK_NO_TIMEOUT));
88
89 /* DIV_ROUND_UP() is not used here, because its (a + b - 1) form overflows
90 * for large timeouts on platforms where unsigned long is 32 bit */
91 return (timeout - 1) / US_PER_MS + 1;
92}
93
97
98#ifdef __cplusplus
99}
100#endif
101
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.