mirror of
https://git.savannah.nongnu.org/git/lwip.git
synced 2026-08-09 17:13:49 +08:00
Test / RFC: Reformat a few files using clang-format
Does it compile? Does it look good (enough)?
This commit is contained in:
@@ -63,11 +63,11 @@
|
||||
#include "lwip/memp.h"
|
||||
|
||||
#include "lwip/ip.h"
|
||||
#include "lwip/raw.h"
|
||||
#include "lwip/udp.h"
|
||||
#include "lwip/priv/api_msg.h"
|
||||
#include "lwip/priv/tcp_priv.h"
|
||||
#include "lwip/priv/tcpip_priv.h"
|
||||
#include "lwip/raw.h"
|
||||
#include "lwip/udp.h"
|
||||
|
||||
#ifdef LWIP_HOOK_FILENAME
|
||||
#include LWIP_HOOK_FILENAME
|
||||
@@ -75,11 +75,11 @@
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#define API_MSG_VAR_REF(name) API_VAR_REF(name)
|
||||
#define API_MSG_VAR_DECLARE(name) API_VAR_DECLARE(struct api_msg, name)
|
||||
#define API_MSG_VAR_ALLOC(name) API_VAR_ALLOC(struct api_msg, MEMP_API_MSG, name, ERR_MEM)
|
||||
#define API_MSG_VAR_REF(name) API_VAR_REF(name)
|
||||
#define API_MSG_VAR_DECLARE(name) API_VAR_DECLARE(struct api_msg, name)
|
||||
#define API_MSG_VAR_ALLOC(name) API_VAR_ALLOC(struct api_msg, MEMP_API_MSG, name, ERR_MEM)
|
||||
#define API_MSG_VAR_ALLOC_RETURN_NULL(name) API_VAR_ALLOC(struct api_msg, MEMP_API_MSG, name, NULL)
|
||||
#define API_MSG_VAR_FREE(name) API_VAR_FREE(MEMP_API_MSG, name)
|
||||
#define API_MSG_VAR_FREE(name) API_VAR_FREE(MEMP_API_MSG, name)
|
||||
|
||||
#if TCP_LISTEN_BACKLOG
|
||||
/* need to allocate API message for accept so empty message pool does not result in event loss
|
||||
@@ -92,18 +92,22 @@
|
||||
#endif /* TCP_LISTEN_BACKLOG */
|
||||
|
||||
#if LWIP_NETCONN_FULLDUPLEX
|
||||
#define NETCONN_RECVMBOX_WAITABLE(conn) (sys_mbox_valid(&(conn)->recvmbox) && (((conn)->flags & NETCONN_FLAG_MBOXINVALID) == 0))
|
||||
#define NETCONN_ACCEPTMBOX_WAITABLE(conn) (sys_mbox_valid(&(conn)->acceptmbox) && (((conn)->flags & (NETCONN_FLAG_MBOXCLOSED|NETCONN_FLAG_MBOXINVALID)) == 0))
|
||||
#define NETCONN_RECVMBOX_WAITABLE(conn) \
|
||||
(sys_mbox_valid(&(conn)->recvmbox) && (((conn)->flags & NETCONN_FLAG_MBOXINVALID) == 0))
|
||||
#define NETCONN_ACCEPTMBOX_WAITABLE(conn) \
|
||||
(sys_mbox_valid(&(conn)->acceptmbox) && (((conn)->flags & (NETCONN_FLAG_MBOXCLOSED | NETCONN_FLAG_MBOXINVALID)) == 0))
|
||||
#define NETCONN_MBOX_WAITING_INC(conn) SYS_ARCH_INC(conn->mbox_threads_waiting, 1)
|
||||
#define NETCONN_MBOX_WAITING_DEC(conn) SYS_ARCH_INC(conn->mbox_threads_waiting, 1)
|
||||
#else /* LWIP_NETCONN_FULLDUPLEX */
|
||||
#define NETCONN_RECVMBOX_WAITABLE(conn) sys_mbox_valid(&(conn)->recvmbox)
|
||||
#define NETCONN_ACCEPTMBOX_WAITABLE(conn) (sys_mbox_valid(&(conn)->acceptmbox) && (((conn)->flags & NETCONN_FLAG_MBOXCLOSED) == 0))
|
||||
#define NETCONN_RECVMBOX_WAITABLE(conn) sys_mbox_valid(&(conn)->recvmbox)
|
||||
#define NETCONN_ACCEPTMBOX_WAITABLE(conn) \
|
||||
(sys_mbox_valid(&(conn)->acceptmbox) && (((conn)->flags & NETCONN_FLAG_MBOXCLOSED) == 0))
|
||||
#define NETCONN_MBOX_WAITING_INC(conn)
|
||||
#define NETCONN_MBOX_WAITING_DEC(conn)
|
||||
#endif /* LWIP_NETCONN_FULLDUPLEX */
|
||||
|
||||
static err_t netconn_close_shutdown(struct netconn *conn, u8_t how);
|
||||
static err_t
|
||||
netconn_close_shutdown(struct netconn *conn, u8_t how);
|
||||
|
||||
/**
|
||||
* Call the lower part of a netconn_* function
|
||||
@@ -282,7 +286,7 @@ netconn_getaddr(struct netconn *conn, ip_addr_t *addr, u16_t *port, u8_t local)
|
||||
err = netconn_apimsg(lwip_netconn_do_getaddr, &API_MSG_VAR_REF(msg));
|
||||
*addr = msg->msg.ad.ipaddr;
|
||||
*port = msg->msg.ad.port;
|
||||
#else /* LWIP_MPU_COMPATIBLE */
|
||||
#else /* LWIP_MPU_COMPATIBLE */
|
||||
msg.msg.ad.ipaddr = addr;
|
||||
msg.msg.ad.port = port;
|
||||
err = netconn_apimsg(lwip_netconn_do_getaddr, &msg);
|
||||
@@ -322,8 +326,7 @@ netconn_bind(struct netconn *conn, const ip_addr_t *addr, u16_t port)
|
||||
/* "Socket API like" dual-stack support: If IP to bind to is IP6_ADDR_ANY,
|
||||
* and NETCONN_FLAG_IPV6_V6ONLY is 0, use IP_ANY_TYPE to bind
|
||||
*/
|
||||
if ((netconn_get_ipv6only(conn) == 0) &&
|
||||
ip_addr_cmp(addr, IP6_ADDR_ANY)) {
|
||||
if ((netconn_get_ipv6only(conn) == 0) && ip_addr_cmp(addr, IP6_ADDR_ANY)) {
|
||||
addr = IP_ANY_TYPE;
|
||||
}
|
||||
#endif /* LWIP_IPV4 && LWIP_IPV6 */
|
||||
@@ -451,7 +454,7 @@ netconn_listen_with_backlog(struct netconn *conn, u8_t backlog)
|
||||
API_MSG_VAR_FREE(msg);
|
||||
|
||||
return err;
|
||||
#else /* LWIP_TCP */
|
||||
#else /* LWIP_TCP */
|
||||
LWIP_UNUSED_ARG(conn);
|
||||
LWIP_UNUSED_ARG(backlog);
|
||||
return ERR_ARG;
|
||||
@@ -478,9 +481,9 @@ netconn_accept(struct netconn *conn, struct netconn **new_conn)
|
||||
API_MSG_VAR_DECLARE(msg);
|
||||
#endif /* TCP_LISTEN_BACKLOG */
|
||||
|
||||
LWIP_ERROR("netconn_accept: invalid pointer", (new_conn != NULL), return ERR_ARG;);
|
||||
LWIP_ERROR("netconn_accept: invalid pointer", (new_conn != NULL), return ERR_ARG;);
|
||||
*new_conn = NULL;
|
||||
LWIP_ERROR("netconn_accept: invalid conn", (conn != NULL), return ERR_ARG;);
|
||||
LWIP_ERROR("netconn_accept: invalid conn", (conn != NULL), return ERR_ARG;);
|
||||
|
||||
/* NOTE: Although the opengroup spec says a pending error shall be returned to
|
||||
send/recv/getsockopt(SO_ERROR) only, we return it for listening
|
||||
@@ -552,7 +555,7 @@ netconn_accept(struct netconn *conn, struct netconn **new_conn)
|
||||
*new_conn = newconn;
|
||||
/* don't set conn->last_err: it's only ERR_OK, anyway */
|
||||
return ERR_OK;
|
||||
#else /* LWIP_TCP */
|
||||
#else /* LWIP_TCP */
|
||||
LWIP_UNUSED_ARG(conn);
|
||||
LWIP_UNUSED_ARG(new_conn);
|
||||
return ERR_ARG;
|
||||
@@ -583,7 +586,7 @@ netconn_recv_data(struct netconn *conn, void **new_buf, u8_t apiflags)
|
||||
|
||||
LWIP_ERROR("netconn_recv: invalid pointer", (new_buf != NULL), return ERR_ARG;);
|
||||
*new_buf = NULL;
|
||||
LWIP_ERROR("netconn_recv: invalid conn", (conn != NULL), return ERR_ARG;);
|
||||
LWIP_ERROR("netconn_recv: invalid conn", (conn != NULL), return ERR_ARG;);
|
||||
|
||||
if (!NETCONN_RECVMBOX_WAITABLE(conn)) {
|
||||
err_t err = netconn_err(conn);
|
||||
@@ -595,8 +598,8 @@ netconn_recv_data(struct netconn *conn, void **new_buf, u8_t apiflags)
|
||||
}
|
||||
|
||||
NETCONN_MBOX_WAITING_INC(conn);
|
||||
if (netconn_is_nonblocking(conn) || (apiflags & NETCONN_DONTBLOCK) ||
|
||||
(conn->flags & NETCONN_FLAG_MBOXCLOSED) || (conn->pending_err != ERR_OK)) {
|
||||
if (netconn_is_nonblocking(conn) || (apiflags & NETCONN_DONTBLOCK) || (conn->flags & NETCONN_FLAG_MBOXCLOSED) ||
|
||||
(conn->pending_err != ERR_OK)) {
|
||||
if (sys_arch_mbox_tryfetch(&conn->recvmbox, &buf) == SYS_ARCH_TIMEOUT) {
|
||||
err_t err;
|
||||
NETCONN_MBOX_WAITING_DEC(conn);
|
||||
@@ -665,7 +668,7 @@ netconn_recv_data(struct netconn *conn, void **new_buf, u8_t apiflags)
|
||||
/* Register event with callback */
|
||||
API_EVENT(conn, NETCONN_EVT_RCVMINUS, len);
|
||||
|
||||
LWIP_DEBUGF(API_LIB_DEBUG, ("netconn_recv_data: received %p, len=%"U16_F"\n", buf, len));
|
||||
LWIP_DEBUGF(API_LIB_DEBUG, ("netconn_recv_data: received %p, len=%" U16_F "\n", buf, len));
|
||||
|
||||
*new_buf = buf;
|
||||
/* don't set conn->last_err: it's only ERR_OK, anyway */
|
||||
@@ -676,8 +679,9 @@ netconn_recv_data(struct netconn *conn, void **new_buf, u8_t apiflags)
|
||||
static err_t
|
||||
netconn_tcp_recvd_msg(struct netconn *conn, size_t len, struct api_msg *msg)
|
||||
{
|
||||
LWIP_ERROR("netconn_recv_tcp_pbuf: invalid conn", (conn != NULL) &&
|
||||
NETCONNTYPE_GROUP(netconn_type(conn)) == NETCONN_TCP, return ERR_ARG;);
|
||||
LWIP_ERROR("netconn_recv_tcp_pbuf: invalid conn",
|
||||
(conn != NULL) && NETCONNTYPE_GROUP(netconn_type(conn)) == NETCONN_TCP,
|
||||
return ERR_ARG;);
|
||||
|
||||
msg->conn = conn;
|
||||
msg->msg.r.len = len;
|
||||
@@ -690,8 +694,9 @@ netconn_tcp_recvd(struct netconn *conn, size_t len)
|
||||
{
|
||||
err_t err;
|
||||
API_MSG_VAR_DECLARE(msg);
|
||||
LWIP_ERROR("netconn_recv_tcp_pbuf: invalid conn", (conn != NULL) &&
|
||||
NETCONNTYPE_GROUP(netconn_type(conn)) == NETCONN_TCP, return ERR_ARG;);
|
||||
LWIP_ERROR("netconn_recv_tcp_pbuf: invalid conn",
|
||||
(conn != NULL) && NETCONNTYPE_GROUP(netconn_type(conn)) == NETCONN_TCP,
|
||||
return ERR_ARG;);
|
||||
|
||||
API_MSG_VAR_ALLOC(msg);
|
||||
err = netconn_tcp_recvd_msg(conn, len, &API_VAR_REF(msg));
|
||||
@@ -720,7 +725,7 @@ netconn_recv_data_tcp(struct netconn *conn, struct pbuf **new_buf, u8_t apiflags
|
||||
|
||||
if (!(apiflags & NETCONN_NOAUTORCVD)) {
|
||||
/* need to allocate API message here so empty message pool does not result in event loss
|
||||
* see bug #47512: MPU_COMPATIBLE may fail on empty pool */
|
||||
* see bug #47512: MPU_COMPATIBLE may fail on empty pool */
|
||||
API_MSG_VAR_ALLOC(msg);
|
||||
}
|
||||
|
||||
@@ -737,7 +742,7 @@ netconn_recv_data_tcp(struct netconn *conn, struct pbuf **new_buf, u8_t apiflags
|
||||
u16_t len = buf ? buf->tot_len : 1;
|
||||
/* don't care for the return value of lwip_netconn_do_recv */
|
||||
/* @todo: this should really be fixed, e.g. by retrying in poll on error */
|
||||
netconn_tcp_recvd_msg(conn, len, &API_VAR_REF(msg));
|
||||
netconn_tcp_recvd_msg(conn, len, &API_VAR_REF(msg));
|
||||
API_MSG_VAR_FREE(msg);
|
||||
}
|
||||
|
||||
@@ -749,7 +754,7 @@ netconn_recv_data_tcp(struct netconn *conn, struct pbuf **new_buf, u8_t apiflags
|
||||
netconn_set_flags(conn, NETCONN_FIN_RX_PENDING);
|
||||
return ERR_WOULDBLOCK;
|
||||
} else {
|
||||
handle_fin:
|
||||
handle_fin:
|
||||
API_EVENT(conn, NETCONN_EVT_RCVMINUS, 0);
|
||||
if (conn->pcb.ip == NULL) {
|
||||
/* race condition: RST during recv */
|
||||
@@ -781,8 +786,9 @@ handle_fin:
|
||||
err_t
|
||||
netconn_recv_tcp_pbuf(struct netconn *conn, struct pbuf **new_buf)
|
||||
{
|
||||
LWIP_ERROR("netconn_recv_tcp_pbuf: invalid conn", (conn != NULL) &&
|
||||
NETCONNTYPE_GROUP(netconn_type(conn)) == NETCONN_TCP, return ERR_ARG;);
|
||||
LWIP_ERROR("netconn_recv_tcp_pbuf: invalid conn",
|
||||
(conn != NULL) && NETCONNTYPE_GROUP(netconn_type(conn)) == NETCONN_TCP,
|
||||
return ERR_ARG;);
|
||||
|
||||
return netconn_recv_data_tcp(conn, new_buf, 0);
|
||||
}
|
||||
@@ -802,8 +808,9 @@ netconn_recv_tcp_pbuf(struct netconn *conn, struct pbuf **new_buf)
|
||||
err_t
|
||||
netconn_recv_tcp_pbuf_flags(struct netconn *conn, struct pbuf **new_buf, u8_t apiflags)
|
||||
{
|
||||
LWIP_ERROR("netconn_recv_tcp_pbuf: invalid conn", (conn != NULL) &&
|
||||
NETCONNTYPE_GROUP(netconn_type(conn)) == NETCONN_TCP, return ERR_ARG;);
|
||||
LWIP_ERROR("netconn_recv_tcp_pbuf: invalid conn",
|
||||
(conn != NULL) && NETCONNTYPE_GROUP(netconn_type(conn)) == NETCONN_TCP,
|
||||
return ERR_ARG;);
|
||||
|
||||
return netconn_recv_data_tcp(conn, new_buf, apiflags);
|
||||
}
|
||||
@@ -821,8 +828,9 @@ netconn_recv_tcp_pbuf_flags(struct netconn *conn, struct pbuf **new_buf, u8_t ap
|
||||
err_t
|
||||
netconn_recv_udp_raw_netbuf(struct netconn *conn, struct netbuf **new_buf)
|
||||
{
|
||||
LWIP_ERROR("netconn_recv_udp_raw_netbuf: invalid conn", (conn != NULL) &&
|
||||
NETCONNTYPE_GROUP(netconn_type(conn)) != NETCONN_TCP, return ERR_ARG;);
|
||||
LWIP_ERROR("netconn_recv_udp_raw_netbuf: invalid conn",
|
||||
(conn != NULL) && NETCONNTYPE_GROUP(netconn_type(conn)) != NETCONN_TCP,
|
||||
return ERR_ARG;);
|
||||
|
||||
return netconn_recv_data(conn, (void **)new_buf, 0);
|
||||
}
|
||||
@@ -841,8 +849,9 @@ netconn_recv_udp_raw_netbuf(struct netconn *conn, struct netbuf **new_buf)
|
||||
err_t
|
||||
netconn_recv_udp_raw_netbuf_flags(struct netconn *conn, struct netbuf **new_buf, u8_t apiflags)
|
||||
{
|
||||
LWIP_ERROR("netconn_recv_udp_raw_netbuf: invalid conn", (conn != NULL) &&
|
||||
NETCONNTYPE_GROUP(netconn_type(conn)) != NETCONN_TCP, return ERR_ARG;);
|
||||
LWIP_ERROR("netconn_recv_udp_raw_netbuf: invalid conn",
|
||||
(conn != NULL) && NETCONNTYPE_GROUP(netconn_type(conn)) != NETCONN_TCP,
|
||||
return ERR_ARG;);
|
||||
|
||||
return netconn_recv_data(conn, (void **)new_buf, apiflags);
|
||||
}
|
||||
@@ -866,7 +875,7 @@ netconn_recv(struct netconn *conn, struct netbuf **new_buf)
|
||||
|
||||
LWIP_ERROR("netconn_recv: invalid pointer", (new_buf != NULL), return ERR_ARG;);
|
||||
*new_buf = NULL;
|
||||
LWIP_ERROR("netconn_recv: invalid conn", (conn != NULL), return ERR_ARG;);
|
||||
LWIP_ERROR("netconn_recv: invalid conn", (conn != NULL), return ERR_ARG;);
|
||||
|
||||
#if LWIP_TCP
|
||||
#if (LWIP_UDP || LWIP_RAW)
|
||||
@@ -943,9 +952,9 @@ netconn_send(struct netconn *conn, struct netbuf *buf)
|
||||
API_MSG_VAR_DECLARE(msg);
|
||||
err_t err;
|
||||
|
||||
LWIP_ERROR("netconn_send: invalid conn", (conn != NULL), return ERR_ARG;);
|
||||
LWIP_ERROR("netconn_send: invalid conn", (conn != NULL), return ERR_ARG;);
|
||||
|
||||
LWIP_DEBUGF(API_LIB_DEBUG, ("netconn_send: sending %"U16_F" bytes\n", buf->p->tot_len));
|
||||
LWIP_DEBUGF(API_LIB_DEBUG, ("netconn_send: sending %" U16_F " bytes\n", buf->p->tot_len));
|
||||
|
||||
API_MSG_VAR_ALLOC(msg);
|
||||
API_MSG_VAR_REF(msg).conn = conn;
|
||||
@@ -971,8 +980,7 @@ netconn_send(struct netconn *conn, struct netbuf *buf)
|
||||
* @return ERR_OK if data was sent, any other err_t on error
|
||||
*/
|
||||
err_t
|
||||
netconn_write_partly(struct netconn *conn, const void *dataptr, size_t size,
|
||||
u8_t apiflags, size_t *bytes_written)
|
||||
netconn_write_partly(struct netconn *conn, const void *dataptr, size_t size, u8_t apiflags, size_t *bytes_written)
|
||||
{
|
||||
struct netvector vector;
|
||||
vector.ptr = dataptr;
|
||||
@@ -994,8 +1002,11 @@ netconn_write_partly(struct netconn *conn, const void *dataptr, size_t size,
|
||||
* @return ERR_OK if data was sent, any other err_t on error
|
||||
*/
|
||||
err_t
|
||||
netconn_write_vectors_partly(struct netconn *conn, struct netvector *vectors, u16_t vectorcnt,
|
||||
u8_t apiflags, size_t *bytes_written)
|
||||
netconn_write_vectors_partly(struct netconn *conn,
|
||||
struct netvector *vectors,
|
||||
u16_t vectorcnt,
|
||||
u8_t apiflags,
|
||||
size_t *bytes_written)
|
||||
{
|
||||
API_MSG_VAR_DECLARE(msg);
|
||||
err_t err;
|
||||
@@ -1003,8 +1014,8 @@ netconn_write_vectors_partly(struct netconn *conn, struct netvector *vectors, u1
|
||||
size_t size;
|
||||
int i;
|
||||
|
||||
LWIP_ERROR("netconn_write: invalid conn", (conn != NULL), return ERR_ARG;);
|
||||
LWIP_ERROR("netconn_write: invalid conn->type", (NETCONNTYPE_GROUP(conn->type) == NETCONN_TCP), return ERR_VAL;);
|
||||
LWIP_ERROR("netconn_write: invalid conn", (conn != NULL), return ERR_ARG;);
|
||||
LWIP_ERROR("netconn_write: invalid conn->type", (NETCONNTYPE_GROUP(conn->type) == NETCONN_TCP), return ERR_VAL;);
|
||||
dontblock = netconn_is_nonblocking(conn) || (apiflags & NETCONN_DONTBLOCK);
|
||||
#if LWIP_SO_SNDTIMEO
|
||||
if (conn->send_timeout != 0) {
|
||||
@@ -1092,7 +1103,7 @@ netconn_close_shutdown(struct netconn *conn, u8_t how)
|
||||
err_t err;
|
||||
LWIP_UNUSED_ARG(how);
|
||||
|
||||
LWIP_ERROR("netconn_close: invalid conn", (conn != NULL), return ERR_ARG;);
|
||||
LWIP_ERROR("netconn_close: invalid conn", (conn != NULL), return ERR_ARG;);
|
||||
|
||||
API_MSG_VAR_ALLOC(msg);
|
||||
API_MSG_VAR_REF(msg).conn = conn;
|
||||
@@ -1103,7 +1114,7 @@ netconn_close_shutdown(struct netconn *conn, u8_t how)
|
||||
/* get the time we started, which is later compared to
|
||||
sys_now() + conn->send_timeout */
|
||||
API_MSG_VAR_REF(msg).msg.sd.time_started = sys_now();
|
||||
#else /* LWIP_SO_SNDTIMEO || LWIP_SO_LINGER */
|
||||
#else /* LWIP_SO_SNDTIMEO || LWIP_SO_LINGER */
|
||||
API_MSG_VAR_REF(msg).msg.sd.polls_left =
|
||||
((LWIP_TCP_CLOSE_TIMEOUT_MS_DEFAULT + TCP_SLOW_INTERVAL - 1) / TCP_SLOW_INTERVAL) + 1;
|
||||
#endif /* LWIP_SO_SNDTIMEO || LWIP_SO_LINGER */
|
||||
@@ -1186,7 +1197,7 @@ netconn_join_leave_group(struct netconn *conn,
|
||||
API_MSG_VAR_DECLARE(msg);
|
||||
err_t err;
|
||||
|
||||
LWIP_ERROR("netconn_join_leave_group: invalid conn", (conn != NULL), return ERR_ARG;);
|
||||
LWIP_ERROR("netconn_join_leave_group: invalid conn", (conn != NULL), return ERR_ARG;);
|
||||
|
||||
API_MSG_VAR_ALLOC(msg);
|
||||
|
||||
@@ -1228,7 +1239,7 @@ netconn_join_leave_group_netif(struct netconn *conn,
|
||||
API_MSG_VAR_DECLARE(msg);
|
||||
err_t err;
|
||||
|
||||
LWIP_ERROR("netconn_join_leave_group: invalid conn", (conn != NULL), return ERR_ARG;);
|
||||
LWIP_ERROR("netconn_join_leave_group: invalid conn", (conn != NULL), return ERR_ARG;);
|
||||
|
||||
API_MSG_VAR_ALLOC(msg);
|
||||
|
||||
@@ -1303,7 +1314,7 @@ netconn_gethostbyname(const char *name, ip_addr_t *addr)
|
||||
#if LWIP_MPU_COMPATIBLE
|
||||
strncpy(API_VAR_REF(msg).name, name, DNS_MAX_NAME_LENGTH - 1);
|
||||
API_VAR_REF(msg).name[DNS_MAX_NAME_LENGTH - 1] = 0;
|
||||
#else /* LWIP_MPU_COMPATIBLE */
|
||||
#else /* LWIP_MPU_COMPATIBLE */
|
||||
msg.err = &err;
|
||||
msg.sem = &sem;
|
||||
API_VAR_REF(msg).addr = API_VAR_REF(addr);
|
||||
@@ -1314,7 +1325,7 @@ netconn_gethostbyname(const char *name, ip_addr_t *addr)
|
||||
#endif /* LWIP_IPV4 && LWIP_IPV6 */
|
||||
#if LWIP_NETCONN_SEM_PER_THREAD
|
||||
API_VAR_REF(msg).sem = LWIP_NETCONN_THREAD_SEM_GET();
|
||||
#else /* LWIP_NETCONN_SEM_PER_THREAD*/
|
||||
#else /* LWIP_NETCONN_SEM_PER_THREAD*/
|
||||
err = sys_sem_new(API_EXPR_REF(API_VAR_REF(msg).sem), 0);
|
||||
if (err != ERR_OK) {
|
||||
API_VAR_FREE(MEMP_DNS_API_MSG, msg);
|
||||
|
||||
@@ -44,13 +44,13 @@
|
||||
|
||||
#include "lwip/ip.h"
|
||||
#include "lwip/ip_addr.h"
|
||||
#include "lwip/udp.h"
|
||||
#include "lwip/tcp.h"
|
||||
#include "lwip/raw.h"
|
||||
#include "lwip/tcp.h"
|
||||
#include "lwip/udp.h"
|
||||
|
||||
#include "lwip/memp.h"
|
||||
#include "lwip/igmp.h"
|
||||
#include "lwip/dns.h"
|
||||
#include "lwip/igmp.h"
|
||||
#include "lwip/memp.h"
|
||||
#include "lwip/mld6.h"
|
||||
#include "lwip/priv/tcpip_priv.h"
|
||||
|
||||
@@ -59,10 +59,14 @@
|
||||
/* netconns are polled once per second (e.g. continue write on memory error) */
|
||||
#define NETCONN_TCP_POLL_INTERVAL 2
|
||||
|
||||
#define SET_NONBLOCKING_CONNECT(conn, val) do { if (val) { \
|
||||
netconn_set_flags(conn, NETCONN_FLAG_IN_NONBLOCKING_CONNECT); \
|
||||
} else { \
|
||||
netconn_clear_flags(conn, NETCONN_FLAG_IN_NONBLOCKING_CONNECT); }} while(0)
|
||||
#define SET_NONBLOCKING_CONNECT(conn, val) \
|
||||
do { \
|
||||
if (val) { \
|
||||
netconn_set_flags(conn, NETCONN_FLAG_IN_NONBLOCKING_CONNECT); \
|
||||
} else { \
|
||||
netconn_clear_flags(conn, NETCONN_FLAG_IN_NONBLOCKING_CONNECT); \
|
||||
} \
|
||||
} while (0)
|
||||
#define IN_NONBLOCKING_CONNECT(conn) netconn_is_flag_set(conn, NETCONN_FLAG_IN_NONBLOCKING_CONNECT)
|
||||
|
||||
#if LWIP_NETCONN_FULLDUPLEX
|
||||
@@ -74,22 +78,28 @@
|
||||
/* forward declarations */
|
||||
#if LWIP_TCP
|
||||
#if LWIP_TCPIP_CORE_LOCKING
|
||||
#define WRITE_DELAYED , 1
|
||||
#define WRITE_DELAYED_PARAM , u8_t delayed
|
||||
#define WRITE_DELAYED , 1
|
||||
#define WRITE_DELAYED_PARAM , u8_t delayed
|
||||
#else /* LWIP_TCPIP_CORE_LOCKING */
|
||||
#define WRITE_DELAYED
|
||||
#define WRITE_DELAYED_PARAM
|
||||
#endif /* LWIP_TCPIP_CORE_LOCKING */
|
||||
static err_t lwip_netconn_do_writemore(struct netconn *conn WRITE_DELAYED_PARAM);
|
||||
static err_t lwip_netconn_do_close_internal(struct netconn *conn WRITE_DELAYED_PARAM);
|
||||
static err_t
|
||||
lwip_netconn_do_writemore(struct netconn *conn WRITE_DELAYED_PARAM);
|
||||
static err_t
|
||||
lwip_netconn_do_close_internal(struct netconn *conn WRITE_DELAYED_PARAM);
|
||||
#endif
|
||||
|
||||
static void netconn_drain(struct netconn *conn);
|
||||
static void
|
||||
netconn_drain(struct netconn *conn);
|
||||
|
||||
#if LWIP_TCPIP_CORE_LOCKING
|
||||
#define TCPIP_APIMSG_ACK(m)
|
||||
#else /* LWIP_TCPIP_CORE_LOCKING */
|
||||
#define TCPIP_APIMSG_ACK(m) do { sys_sem_signal(LWIP_API_MSG_SEM(m)); } while(0)
|
||||
#define TCPIP_APIMSG_ACK(m) \
|
||||
do { \
|
||||
sys_sem_signal(LWIP_API_MSG_SEM(m)); \
|
||||
} while (0)
|
||||
#endif /* LWIP_TCPIP_CORE_LOCKING */
|
||||
|
||||
#if LWIP_NETCONN_FULLDUPLEX
|
||||
@@ -146,7 +156,6 @@ lwip_netconn_is_err_msg(void *msg, err_t *err)
|
||||
}
|
||||
#endif /* LWIP_TCP */
|
||||
|
||||
|
||||
#if LWIP_RAW
|
||||
/**
|
||||
* Receive callback function for RAW netconns.
|
||||
@@ -156,8 +165,7 @@ lwip_netconn_is_err_msg(void *msg, err_t *err)
|
||||
* @see raw.h (struct raw_pcb.recv) for parameters and return value
|
||||
*/
|
||||
static u8_t
|
||||
recv_raw(void *arg, struct raw_pcb *pcb, struct pbuf *p,
|
||||
const ip_addr_t *addr)
|
||||
recv_raw(void *arg, struct raw_pcb *pcb, struct pbuf *p, const ip_addr_t *addr)
|
||||
{
|
||||
struct pbuf *q;
|
||||
struct netbuf *buf;
|
||||
@@ -215,8 +223,7 @@ recv_raw(void *arg, struct raw_pcb *pcb, struct pbuf *p,
|
||||
* @see udp.h (struct udp_pcb.recv) for parameters
|
||||
*/
|
||||
static void
|
||||
recv_udp(void *arg, struct udp_pcb *pcb, struct pbuf *p,
|
||||
const ip_addr_t *addr, u16_t port)
|
||||
recv_udp(void *arg, struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *addr, u16_t port)
|
||||
{
|
||||
struct netbuf *buf;
|
||||
struct netconn *conn;
|
||||
@@ -239,8 +246,7 @@ recv_udp(void *arg, struct udp_pcb *pcb, struct pbuf *p,
|
||||
|
||||
#if LWIP_SO_RCVBUF
|
||||
SYS_ARCH_GET(conn->recv_avail, recv_avail);
|
||||
if (!NETCONN_MBOX_VALID(conn, &conn->recvmbox) ||
|
||||
((recv_avail + (int)(p->tot_len)) > conn->recv_bufsize)) {
|
||||
if (!NETCONN_MBOX_VALID(conn, &conn->recvmbox) || ((recv_avail + (int)(p->tot_len)) > conn->recv_bufsize)) {
|
||||
#else /* LWIP_SO_RCVBUF */
|
||||
if (!NETCONN_MBOX_VALID(conn, &conn->recvmbox)) {
|
||||
#endif /* LWIP_SO_RCVBUF */
|
||||
@@ -362,14 +368,14 @@ poll_tcp(void *arg, struct tcp_pcb *pcb)
|
||||
LWIP_ASSERT("conn != NULL", (conn != NULL));
|
||||
|
||||
if (conn->state == NETCONN_WRITE) {
|
||||
lwip_netconn_do_writemore(conn WRITE_DELAYED);
|
||||
lwip_netconn_do_writemore(conn WRITE_DELAYED);
|
||||
} else if (conn->state == NETCONN_CLOSE) {
|
||||
#if !LWIP_SO_SNDTIMEO && !LWIP_SO_LINGER
|
||||
if (conn->current_msg && conn->current_msg->msg.sd.polls_left) {
|
||||
conn->current_msg->msg.sd.polls_left--;
|
||||
}
|
||||
#endif /* !LWIP_SO_SNDTIMEO && !LWIP_SO_LINGER */
|
||||
lwip_netconn_do_close_internal(conn WRITE_DELAYED);
|
||||
lwip_netconn_do_close_internal(conn WRITE_DELAYED);
|
||||
}
|
||||
/* @todo: implement connect timeout here? */
|
||||
|
||||
@@ -404,9 +410,9 @@ sent_tcp(void *arg, struct tcp_pcb *pcb, u16_t len)
|
||||
|
||||
if (conn) {
|
||||
if (conn->state == NETCONN_WRITE) {
|
||||
lwip_netconn_do_writemore(conn WRITE_DELAYED);
|
||||
lwip_netconn_do_writemore(conn WRITE_DELAYED);
|
||||
} else if (conn->state == NETCONN_CLOSE) {
|
||||
lwip_netconn_do_close_internal(conn WRITE_DELAYED);
|
||||
lwip_netconn_do_close_internal(conn WRITE_DELAYED);
|
||||
}
|
||||
|
||||
/* If the queued byte- or pbuf-count drops below the configured low-water limit,
|
||||
@@ -473,8 +479,7 @@ err_tcp(void *arg, err_t err)
|
||||
sys_mbox_trypost(&conn->acceptmbox, mbox_msg);
|
||||
}
|
||||
|
||||
if ((old_state == NETCONN_WRITE) || (old_state == NETCONN_CLOSE) ||
|
||||
(old_state == NETCONN_CONNECT)) {
|
||||
if ((old_state == NETCONN_WRITE) || (old_state == NETCONN_CLOSE) || (old_state == NETCONN_CONNECT)) {
|
||||
/* calling lwip_netconn_do_writemore/lwip_netconn_do_close_internal is not necessary
|
||||
since the pcb has already been deleted! */
|
||||
int was_nonblocking_connect = IN_NONBLOCKING_CONNECT(conn);
|
||||
@@ -755,14 +760,14 @@ netconn_alloc(enum netconn_type t, netconn_callback callback)
|
||||
#if LWIP_TCP
|
||||
sys_mbox_set_invalid(&conn->acceptmbox);
|
||||
#endif
|
||||
conn->state = NETCONN_NONE;
|
||||
conn->state = NETCONN_NONE;
|
||||
#if LWIP_SOCKET
|
||||
/* initialize socket to -1 since 0 is a valid socket */
|
||||
conn->socket = -1;
|
||||
conn->socket = -1;
|
||||
#endif /* LWIP_SOCKET */
|
||||
conn->callback = callback;
|
||||
conn->callback = callback;
|
||||
#if LWIP_TCP
|
||||
conn->current_msg = NULL;
|
||||
conn->current_msg = NULL;
|
||||
#endif /* LWIP_TCP */
|
||||
#if LWIP_SO_SNDTIMEO
|
||||
conn->send_timeout = 0;
|
||||
@@ -772,7 +777,7 @@ netconn_alloc(enum netconn_type t, netconn_callback callback)
|
||||
#endif /* LWIP_SO_RCVTIMEO */
|
||||
#if LWIP_SO_RCVBUF
|
||||
conn->recv_bufsize = RECV_BUFSIZE_DEFAULT;
|
||||
conn->recv_avail = 0;
|
||||
conn->recv_avail = 0;
|
||||
#endif /* LWIP_SO_RCVBUF */
|
||||
#if LWIP_SO_LINGER
|
||||
conn->linger = -1;
|
||||
@@ -800,11 +805,9 @@ netconn_free(struct netconn *conn)
|
||||
netconn_drain(conn);
|
||||
#endif /* LWIP_NETCONN_FULLDUPLEX */
|
||||
|
||||
LWIP_ASSERT("recvmbox must be deallocated before calling this function",
|
||||
!sys_mbox_valid(&conn->recvmbox));
|
||||
LWIP_ASSERT("recvmbox must be deallocated before calling this function", !sys_mbox_valid(&conn->recvmbox));
|
||||
#if LWIP_TCP
|
||||
LWIP_ASSERT("acceptmbox must be deallocated before calling this function",
|
||||
!sys_mbox_valid(&conn->acceptmbox));
|
||||
LWIP_ASSERT("acceptmbox must be deallocated before calling this function", !sys_mbox_valid(&conn->acceptmbox));
|
||||
#endif /* LWIP_TCP */
|
||||
|
||||
#if !LWIP_NETCONN_SEM_PER_THREAD
|
||||
@@ -917,7 +920,7 @@ netconn_mark_mbox_invalid(struct netconn *conn)
|
||||
* @param conn the TCP netconn to close
|
||||
*/
|
||||
static err_t
|
||||
lwip_netconn_do_close_internal(struct netconn *conn WRITE_DELAYED_PARAM)
|
||||
lwip_netconn_do_close_internal(struct netconn *conn WRITE_DELAYED_PARAM)
|
||||
{
|
||||
err_t err;
|
||||
u8_t shut, shut_rx, shut_tx, shut_close;
|
||||
@@ -941,10 +944,7 @@ lwip_netconn_do_close_internal(struct netconn *conn WRITE_DELAYED_PARAM)
|
||||
(also if RD or WR side was shut down before already) */
|
||||
if (shut == NETCONN_SHUT_RDWR) {
|
||||
shut_close = 1;
|
||||
} else if (shut_rx &&
|
||||
((tpcb->state == FIN_WAIT_1) ||
|
||||
(tpcb->state == FIN_WAIT_2) ||
|
||||
(tpcb->state == CLOSING))) {
|
||||
} else if (shut_rx && ((tpcb->state == FIN_WAIT_1) || (tpcb->state == FIN_WAIT_2) || (tpcb->state == CLOSING))) {
|
||||
shut_close = 1;
|
||||
} else if (shut_tx && ((tpcb->flags & TF_RXCLOSED) != 0)) {
|
||||
shut_close = 1;
|
||||
@@ -988,8 +988,7 @@ lwip_netconn_do_close_internal(struct netconn *conn WRITE_DELAYED_PARAM)
|
||||
if (netconn_is_nonblocking(conn)) {
|
||||
/* data left on a nonblocking netconn -> cannot linger */
|
||||
err = ERR_WOULDBLOCK;
|
||||
} else if ((s32_t)(sys_now() - conn->current_msg->msg.sd.time_started) >=
|
||||
(conn->linger * 1000)) {
|
||||
} else if ((s32_t)(sys_now() - conn->current_msg->msg.sd.time_started) >= (conn->linger * 1000)) {
|
||||
/* data left but linger timeout has expired (this happens on further
|
||||
calls to this function through poll_tcp */
|
||||
tcp_abort(tpcb);
|
||||
@@ -1038,7 +1037,7 @@ lwip_netconn_do_close_internal(struct netconn *conn WRITE_DELAYED_PARAM)
|
||||
}
|
||||
#endif
|
||||
if ((s32_t)(sys_now() - conn->current_msg->msg.sd.time_started) >= close_timeout) {
|
||||
#else /* LWIP_SO_SNDTIMEO || LWIP_SO_LINGER */
|
||||
#else /* LWIP_SO_SNDTIMEO || LWIP_SO_LINGER */
|
||||
if (conn->current_msg->msg.sd.polls_left == 0) {
|
||||
#endif /* LWIP_SO_SNDTIMEO || LWIP_SO_LINGER */
|
||||
close_finished = 1;
|
||||
@@ -1120,8 +1119,7 @@ lwip_netconn_do_delconn(void *m)
|
||||
#if LWIP_NETCONN_FULLDUPLEX
|
||||
/* In full duplex mode, blocking write/connect is aborted with ERR_CLSD */
|
||||
if (state != NETCONN_NONE) {
|
||||
if ((state == NETCONN_WRITE) ||
|
||||
((state == NETCONN_CONNECT) && !IN_NONBLOCKING_CONNECT(msg->conn))) {
|
||||
if ((state == NETCONN_WRITE) || ((state == NETCONN_CONNECT) && !IN_NONBLOCKING_CONNECT(msg->conn))) {
|
||||
/* close requested, abort running write/connect */
|
||||
sys_sem_t *op_completed_sem;
|
||||
LWIP_ASSERT("msg->conn->current_msg != NULL", msg->conn->current_msg != NULL);
|
||||
@@ -1132,10 +1130,8 @@ lwip_netconn_do_delconn(void *m)
|
||||
sys_sem_signal(op_completed_sem);
|
||||
}
|
||||
}
|
||||
#else /* LWIP_NETCONN_FULLDUPLEX */
|
||||
if (((state != NETCONN_NONE) &&
|
||||
(state != NETCONN_LISTEN) &&
|
||||
(state != NETCONN_CONNECT)) ||
|
||||
#else /* LWIP_NETCONN_FULLDUPLEX */
|
||||
if (((state != NETCONN_NONE) && (state != NETCONN_LISTEN) && (state != NETCONN_CONNECT)) ||
|
||||
((state == NETCONN_CONNECT) && !IN_NONBLOCKING_CONNECT(msg->conn))) {
|
||||
/* This means either a blocking write or blocking connect is running
|
||||
(nonblocking write returns and sets state to NONE) */
|
||||
@@ -1143,13 +1139,12 @@ lwip_netconn_do_delconn(void *m)
|
||||
} else
|
||||
#endif /* LWIP_NETCONN_FULLDUPLEX */
|
||||
{
|
||||
LWIP_ASSERT("blocking connect in progress",
|
||||
(state != NETCONN_CONNECT) || IN_NONBLOCKING_CONNECT(msg->conn));
|
||||
LWIP_ASSERT("blocking connect in progress", (state != NETCONN_CONNECT) || IN_NONBLOCKING_CONNECT(msg->conn));
|
||||
msg->err = ERR_OK;
|
||||
#if LWIP_NETCONN_FULLDUPLEX
|
||||
/* Mark mboxes invalid */
|
||||
netconn_mark_mbox_invalid(msg->conn);
|
||||
#else /* LWIP_NETCONN_FULLDUPLEX */
|
||||
#else /* LWIP_NETCONN_FULLDUPLEX */
|
||||
netconn_drain(msg->conn);
|
||||
#endif /* LWIP_NETCONN_FULLDUPLEX */
|
||||
|
||||
@@ -1181,7 +1176,7 @@ lwip_netconn_do_delconn(void *m)
|
||||
LOCK_TCPIP_CORE();
|
||||
LWIP_ASSERT("state!", msg->conn->state == NETCONN_NONE);
|
||||
}
|
||||
#else /* LWIP_TCPIP_CORE_LOCKING */
|
||||
#else /* LWIP_TCPIP_CORE_LOCKING */
|
||||
lwip_netconn_do_close_internal(msg->conn);
|
||||
#endif /* LWIP_TCPIP_CORE_LOCKING */
|
||||
/* API_EVENT is called inside lwip_netconn_do_close_internal, before releasing
|
||||
@@ -1326,8 +1321,7 @@ lwip_netconn_do_connected(void *arg, struct tcp_pcb *pcb, err_t err)
|
||||
was_blocking = !IN_NONBLOCKING_CONNECT(conn);
|
||||
SET_NONBLOCKING_CONNECT(conn, 0);
|
||||
LWIP_ASSERT("blocking connect state error",
|
||||
(was_blocking && op_completed_sem != NULL) ||
|
||||
(!was_blocking && op_completed_sem == NULL));
|
||||
(was_blocking && op_completed_sem != NULL) || (!was_blocking && op_completed_sem == NULL));
|
||||
conn->current_msg = NULL;
|
||||
conn->state = NETCONN_NONE;
|
||||
API_EVENT(conn, NETCONN_EVT_SENDPLUS, 0);
|
||||
@@ -1376,8 +1370,8 @@ lwip_netconn_do_connect(void *m)
|
||||
err = ERR_ISCONN;
|
||||
} else {
|
||||
setup_tcp(msg->conn);
|
||||
err = tcp_connect(msg->conn->pcb.tcp, API_EXPR_REF(msg->msg.bc.ipaddr),
|
||||
msg->msg.bc.port, lwip_netconn_do_connected);
|
||||
err = tcp_connect(
|
||||
msg->conn->pcb.tcp, API_EXPR_REF(msg->msg.bc.ipaddr), msg->msg.bc.port, lwip_netconn_do_connected);
|
||||
if (err == ERR_OK) {
|
||||
u8_t non_blocking = netconn_is_nonblocking(msg->conn);
|
||||
msg->conn->state = NETCONN_CONNECT;
|
||||
@@ -1402,9 +1396,7 @@ lwip_netconn_do_connect(void *m)
|
||||
break;
|
||||
#endif /* LWIP_TCP */
|
||||
default:
|
||||
LWIP_ERROR("Invalid netconn type", 0, do {
|
||||
err = ERR_VAL;
|
||||
} while (0));
|
||||
LWIP_ERROR("Invalid netconn type", 0, do { err = ERR_VAL; } while (0));
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -1467,12 +1459,11 @@ lwip_netconn_do_listen(void *m)
|
||||
#endif /* TCP_LISTEN_BACKLOG */
|
||||
#if LWIP_IPV4 && LWIP_IPV6
|
||||
/* "Socket API like" dual-stack support: If IP to listen to is IP6_ADDR_ANY,
|
||||
* and NETCONN_FLAG_IPV6_V6ONLY is NOT set, use IP_ANY_TYPE to listen
|
||||
*/
|
||||
if (ip_addr_cmp(&msg->conn->pcb.ip->local_ip, IP6_ADDR_ANY) &&
|
||||
(netconn_get_ipv6only(msg->conn) == 0)) {
|
||||
* and NETCONN_FLAG_IPV6_V6ONLY is NOT set, use IP_ANY_TYPE to listen
|
||||
*/
|
||||
if (ip_addr_cmp(&msg->conn->pcb.ip->local_ip, IP6_ADDR_ANY) && (netconn_get_ipv6only(msg->conn) == 0)) {
|
||||
/* change PCB type to IPADDR_TYPE_ANY */
|
||||
IP_SET_TYPE_VAL(msg->conn->pcb.tcp->local_ip, IPADDR_TYPE_ANY);
|
||||
IP_SET_TYPE_VAL(msg->conn->pcb.tcp->local_ip, IPADDR_TYPE_ANY);
|
||||
IP_SET_TYPE_VAL(msg->conn->pcb.tcp->remote_ip, IPADDR_TYPE_ANY);
|
||||
}
|
||||
#endif /* LWIP_IPV4 && LWIP_IPV6 */
|
||||
@@ -1550,14 +1541,17 @@ lwip_netconn_do_send(void *m)
|
||||
case NETCONN_UDP:
|
||||
#if LWIP_CHECKSUM_ON_COPY
|
||||
if (ip_addr_isany(&msg->msg.b->addr) || IP_IS_ANY_TYPE_VAL(msg->msg.b->addr)) {
|
||||
err = udp_send_chksum(msg->conn->pcb.udp, msg->msg.b->p,
|
||||
msg->msg.b->flags & NETBUF_FLAG_CHKSUM, msg->msg.b->toport_chksum);
|
||||
err = udp_send_chksum(
|
||||
msg->conn->pcb.udp, msg->msg.b->p, msg->msg.b->flags & NETBUF_FLAG_CHKSUM, msg->msg.b->toport_chksum);
|
||||
} else {
|
||||
err = udp_sendto_chksum(msg->conn->pcb.udp, msg->msg.b->p,
|
||||
&msg->msg.b->addr, msg->msg.b->port,
|
||||
msg->msg.b->flags & NETBUF_FLAG_CHKSUM, msg->msg.b->toport_chksum);
|
||||
err = udp_sendto_chksum(msg->conn->pcb.udp,
|
||||
msg->msg.b->p,
|
||||
&msg->msg.b->addr,
|
||||
msg->msg.b->port,
|
||||
msg->msg.b->flags & NETBUF_FLAG_CHKSUM,
|
||||
msg->msg.b->toport_chksum);
|
||||
}
|
||||
#else /* LWIP_CHECKSUM_ON_COPY */
|
||||
#else /* LWIP_CHECKSUM_ON_COPY */
|
||||
if (ip_addr_isany_val(msg->msg.b->addr) || IP_IS_ANY_TYPE_VAL(msg->msg.b->addr)) {
|
||||
err = udp_send(msg->conn->pcb.udp, msg->msg.b->p);
|
||||
} else {
|
||||
@@ -1637,7 +1631,7 @@ lwip_netconn_do_accepted(void *m)
|
||||
* ERR_MEM if LWIP_TCPIP_CORE_LOCKING=1 and sending hasn't yet finished
|
||||
*/
|
||||
static err_t
|
||||
lwip_netconn_do_writemore(struct netconn *conn WRITE_DELAYED_PARAM)
|
||||
lwip_netconn_do_writemore(struct netconn *conn WRITE_DELAYED_PARAM)
|
||||
{
|
||||
err_t err;
|
||||
const void *dataptr;
|
||||
@@ -1660,8 +1654,7 @@ lwip_netconn_do_writemore(struct netconn *conn WRITE_DELAYED_PARAM)
|
||||
dontblock = netconn_is_nonblocking(conn) || (apiflags & NETCONN_DONTBLOCK);
|
||||
|
||||
#if LWIP_SO_SNDTIMEO
|
||||
if ((conn->send_timeout != 0) &&
|
||||
((s32_t)(sys_now() - conn->current_msg->msg.w.time_started) >= conn->send_timeout)) {
|
||||
if ((conn->send_timeout != 0) && ((s32_t)(sys_now() - conn->current_msg->msg.w.time_started) >= conn->send_timeout)) {
|
||||
write_finished = 1;
|
||||
if (conn->current_msg->msg.w.offset == 0) {
|
||||
/* nothing has been written */
|
||||
@@ -1702,8 +1695,7 @@ lwip_netconn_do_writemore(struct netconn *conn WRITE_DELAYED_PARAM)
|
||||
1) We couldn't finish the current vector because of 16-bit size limitations.
|
||||
tcp_write() and tcp_sndbuf() both are limited to 16-bit sizes
|
||||
2) We are sending the remainder of the current vector and have more */
|
||||
if ((len == 0xffff && diff > 0xffffUL) ||
|
||||
(len == (u16_t)diff && conn->current_msg->msg.w.vector_cnt > 1)) {
|
||||
if ((len == 0xffff && diff > 0xffffUL) || (len == (u16_t)diff && conn->current_msg->msg.w.vector_cnt > 1)) {
|
||||
write_more = 1;
|
||||
apiflags |= TCP_WRITE_FLAG_MORE;
|
||||
} else {
|
||||
@@ -1726,14 +1718,13 @@ lwip_netconn_do_writemore(struct netconn *conn WRITE_DELAYED_PARAM)
|
||||
} while (write_more && err == ERR_OK);
|
||||
/* if OK or memory error, check available space */
|
||||
if ((err == ERR_OK) || (err == ERR_MEM)) {
|
||||
err_mem:
|
||||
err_mem:
|
||||
if (dontblock && (conn->current_msg->msg.w.offset < conn->current_msg->msg.w.len)) {
|
||||
/* non-blocking write did not write everything: mark the pcb non-writable
|
||||
and let poll_tcp check writable space to mark the pcb writable again */
|
||||
API_EVENT(conn, NETCONN_EVT_SENDMINUS, 0);
|
||||
conn->flags |= NETCONN_FLAG_CHECK_WRITESPACE;
|
||||
} else if ((tcp_sndbuf(conn->pcb.tcp) <= TCP_SNDLOWAT) ||
|
||||
(tcp_sndqueuelen(conn->pcb.tcp) >= TCP_SNDQUEUELOWAT)) {
|
||||
} else if ((tcp_sndbuf(conn->pcb.tcp) <= TCP_SNDLOWAT) || (tcp_sndqueuelen(conn->pcb.tcp) >= TCP_SNDQUEUELOWAT)) {
|
||||
/* The queued byte- or pbuf-count exceeds the configured low-water limit,
|
||||
let select mark this pcb as non-writable. */
|
||||
API_EVENT(conn, NETCONN_EVT_SENDMINUS, 0);
|
||||
@@ -1835,7 +1826,7 @@ lwip_netconn_do_write(void *m)
|
||||
LOCK_TCPIP_CORE();
|
||||
LWIP_ASSERT("state!", msg->conn->state != NETCONN_WRITE);
|
||||
}
|
||||
#else /* LWIP_TCPIP_CORE_LOCKING */
|
||||
#else /* LWIP_TCPIP_CORE_LOCKING */
|
||||
lwip_netconn_do_writemore(msg->conn);
|
||||
#endif /* LWIP_TCPIP_CORE_LOCKING */
|
||||
/* for both cases: if lwip_netconn_do_writemore was called, don't ACK the APIMSG
|
||||
@@ -1844,7 +1835,7 @@ lwip_netconn_do_write(void *m)
|
||||
} else {
|
||||
err = ERR_CONN;
|
||||
}
|
||||
#else /* LWIP_TCP */
|
||||
#else /* LWIP_TCP */
|
||||
err = ERR_VAL;
|
||||
#endif /* LWIP_TCP */
|
||||
#if (LWIP_UDP || LWIP_RAW)
|
||||
@@ -1870,11 +1861,9 @@ lwip_netconn_do_getaddr(void *m)
|
||||
|
||||
if (msg->conn->pcb.ip != NULL) {
|
||||
if (msg->msg.ad.local) {
|
||||
ip_addr_copy(API_EXPR_DEREF(msg->msg.ad.ipaddr),
|
||||
msg->conn->pcb.ip->local_ip);
|
||||
ip_addr_copy(API_EXPR_DEREF(msg->msg.ad.ipaddr), msg->conn->pcb.ip->local_ip);
|
||||
} else {
|
||||
ip_addr_copy(API_EXPR_DEREF(msg->msg.ad.ipaddr),
|
||||
msg->conn->pcb.ip->remote_ip);
|
||||
ip_addr_copy(API_EXPR_DEREF(msg->msg.ad.ipaddr), msg->conn->pcb.ip->remote_ip);
|
||||
}
|
||||
|
||||
msg->err = ERR_OK;
|
||||
@@ -1909,7 +1898,8 @@ lwip_netconn_do_getaddr(void *m)
|
||||
/* pcb is not connected and remote name is requested */
|
||||
msg->err = ERR_CONN;
|
||||
} else {
|
||||
API_EXPR_DEREF(msg->msg.ad.port) = (msg->msg.ad.local ? msg->conn->pcb.tcp->local_port : msg->conn->pcb.tcp->remote_port);
|
||||
API_EXPR_DEREF(msg->msg.ad.port) =
|
||||
(msg->msg.ad.local ? msg->conn->pcb.tcp->local_port : msg->conn->pcb.tcp->remote_port);
|
||||
}
|
||||
break;
|
||||
#endif /* LWIP_TCP */
|
||||
@@ -1939,8 +1929,7 @@ lwip_netconn_do_close(void *m)
|
||||
enum netconn_state state = msg->conn->state;
|
||||
/* First check if this is a TCP netconn and if it is in a correct state
|
||||
(LISTEN doesn't support half shutdown) */
|
||||
if ((msg->conn->pcb.tcp != NULL) &&
|
||||
(NETCONNTYPE_GROUP(msg->conn->type) == NETCONN_TCP) &&
|
||||
if ((msg->conn->pcb.tcp != NULL) && (NETCONNTYPE_GROUP(msg->conn->type) == NETCONN_TCP) &&
|
||||
((msg->msg.sd.shut == NETCONN_SHUT_RDWR) || (state != NETCONN_LISTEN))) {
|
||||
/* Check if we are in a connected state */
|
||||
if (state == NETCONN_CONNECT) {
|
||||
@@ -1966,7 +1955,7 @@ lwip_netconn_do_close(void *m)
|
||||
}
|
||||
}
|
||||
if (state == NETCONN_NONE) {
|
||||
#else /* LWIP_NETCONN_FULLDUPLEX */
|
||||
#else /* LWIP_NETCONN_FULLDUPLEX */
|
||||
msg->err = ERR_INPROGRESS;
|
||||
} else {
|
||||
#endif /* LWIP_NETCONN_FULLDUPLEX */
|
||||
@@ -1974,7 +1963,7 @@ lwip_netconn_do_close(void *m)
|
||||
#if LWIP_NETCONN_FULLDUPLEX
|
||||
/* Mark mboxes invalid */
|
||||
netconn_mark_mbox_invalid(msg->conn);
|
||||
#else /* LWIP_NETCONN_FULLDUPLEX */
|
||||
#else /* LWIP_NETCONN_FULLDUPLEX */
|
||||
netconn_drain(msg->conn);
|
||||
#endif /* LWIP_NETCONN_FULLDUPLEX */
|
||||
}
|
||||
@@ -1989,7 +1978,7 @@ lwip_netconn_do_close(void *m)
|
||||
LOCK_TCPIP_CORE();
|
||||
LWIP_ASSERT("state!", msg->conn->state == NETCONN_NONE);
|
||||
}
|
||||
#else /* LWIP_TCPIP_CORE_LOCKING */
|
||||
#else /* LWIP_TCPIP_CORE_LOCKING */
|
||||
lwip_netconn_do_close_internal(msg->conn);
|
||||
#endif /* LWIP_TCPIP_CORE_LOCKING */
|
||||
/* for tcp netconns, lwip_netconn_do_close_internal ACKs the message */
|
||||
@@ -2075,22 +2064,18 @@ lwip_netconn_do_join_leave_group_netif(void *m)
|
||||
#if LWIP_IPV6 && LWIP_IPV6_MLD
|
||||
if (NETCONNTYPE_ISIPV6(msg->conn->type)) {
|
||||
if (msg->msg.jl.join_or_leave == NETCONN_JOIN) {
|
||||
msg->err = mld6_joingroup_netif(netif,
|
||||
ip_2_ip6(API_EXPR_REF(msg->msg.jl.multiaddr)));
|
||||
msg->err = mld6_joingroup_netif(netif, ip_2_ip6(API_EXPR_REF(msg->msg.jl.multiaddr)));
|
||||
} else {
|
||||
msg->err = mld6_leavegroup_netif(netif,
|
||||
ip_2_ip6(API_EXPR_REF(msg->msg.jl.multiaddr)));
|
||||
msg->err = mld6_leavegroup_netif(netif, ip_2_ip6(API_EXPR_REF(msg->msg.jl.multiaddr)));
|
||||
}
|
||||
} else
|
||||
#endif /* LWIP_IPV6 && LWIP_IPV6_MLD */
|
||||
{
|
||||
#if LWIP_IGMP
|
||||
if (msg->msg.jl.join_or_leave == NETCONN_JOIN) {
|
||||
msg->err = igmp_joingroup_netif(netif,
|
||||
ip_2_ip4(API_EXPR_REF(msg->msg.jl.multiaddr)));
|
||||
msg->err = igmp_joingroup_netif(netif, ip_2_ip4(API_EXPR_REF(msg->msg.jl.multiaddr)));
|
||||
} else {
|
||||
msg->err = igmp_leavegroup_netif(netif,
|
||||
ip_2_ip4(API_EXPR_REF(msg->msg.jl.multiaddr)));
|
||||
msg->err = igmp_leavegroup_netif(netif, ip_2_ip4(API_EXPR_REF(msg->msg.jl.multiaddr)));
|
||||
}
|
||||
#endif /* LWIP_IGMP */
|
||||
}
|
||||
@@ -2150,8 +2135,8 @@ lwip_netconn_do_gethostbyname(void *arg)
|
||||
LWIP_DNS_ADDRTYPE_DEFAULT;
|
||||
#endif
|
||||
|
||||
API_EXPR_DEREF(msg->err) = dns_gethostbyname_addrtype(msg->name,
|
||||
API_EXPR_REF(msg->addr), lwip_netconn_do_dns_found, msg, addrtype);
|
||||
API_EXPR_DEREF(msg->err) =
|
||||
dns_gethostbyname_addrtype(msg->name, API_EXPR_REF(msg->addr), lwip_netconn_do_dns_found, msg, addrtype);
|
||||
#if LWIP_TCPIP_CORE_LOCKING
|
||||
/* For core locking, only block if we need to wait for answer/timeout */
|
||||
if (API_EXPR_DEREF(msg->err) == ERR_INPROGRESS) {
|
||||
@@ -2160,7 +2145,7 @@ lwip_netconn_do_gethostbyname(void *arg)
|
||||
LOCK_TCPIP_CORE();
|
||||
LWIP_ASSERT("do_gethostbyname still in progress!!", API_EXPR_DEREF(msg->err) != ERR_INPROGRESS);
|
||||
}
|
||||
#else /* LWIP_TCPIP_CORE_LOCKING */
|
||||
#else /* LWIP_TCPIP_CORE_LOCKING */
|
||||
if (API_EXPR_DEREF(msg->err) != ERR_INPROGRESS) {
|
||||
/* on error or immediate success, wake up the application
|
||||
* task waiting in netconn_gethostbyname */
|
||||
|
||||
@@ -44,25 +44,25 @@
|
||||
|
||||
#if !NO_SYS
|
||||
/** Table to quickly map an lwIP error (err_t) to a socket error
|
||||
* by using -err as an index */
|
||||
* by using -err as an index */
|
||||
static const int err_to_errno_table[] = {
|
||||
0, /* ERR_OK 0 No error, everything OK. */
|
||||
ENOMEM, /* ERR_MEM -1 Out of memory error. */
|
||||
ENOBUFS, /* ERR_BUF -2 Buffer error. */
|
||||
EWOULDBLOCK, /* ERR_TIMEOUT -3 Timeout */
|
||||
EHOSTUNREACH, /* ERR_RTE -4 Routing problem. */
|
||||
EINPROGRESS, /* ERR_INPROGRESS -5 Operation in progress */
|
||||
EINVAL, /* ERR_VAL -6 Illegal value. */
|
||||
EWOULDBLOCK, /* ERR_WOULDBLOCK -7 Operation would block. */
|
||||
EADDRINUSE, /* ERR_USE -8 Address in use. */
|
||||
EALREADY, /* ERR_ALREADY -9 Already connecting. */
|
||||
EISCONN, /* ERR_ISCONN -10 Conn already established.*/
|
||||
ENOTCONN, /* ERR_CONN -11 Not connected. */
|
||||
-1, /* ERR_IF -12 Low-level netif error */
|
||||
ECONNABORTED, /* ERR_ABRT -13 Connection aborted. */
|
||||
ECONNRESET, /* ERR_RST -14 Connection reset. */
|
||||
ENOTCONN, /* ERR_CLSD -15 Connection closed. */
|
||||
EIO /* ERR_ARG -16 Illegal argument. */
|
||||
0, /* ERR_OK 0 No error, everything OK. */
|
||||
ENOMEM, /* ERR_MEM -1 Out of memory error. */
|
||||
ENOBUFS, /* ERR_BUF -2 Buffer error. */
|
||||
EWOULDBLOCK, /* ERR_TIMEOUT -3 Timeout */
|
||||
EHOSTUNREACH, /* ERR_RTE -4 Routing problem. */
|
||||
EINPROGRESS, /* ERR_INPROGRESS -5 Operation in progress */
|
||||
EINVAL, /* ERR_VAL -6 Illegal value. */
|
||||
EWOULDBLOCK, /* ERR_WOULDBLOCK -7 Operation would block. */
|
||||
EADDRINUSE, /* ERR_USE -8 Address in use. */
|
||||
EALREADY, /* ERR_ALREADY -9 Already connecting. */
|
||||
EISCONN, /* ERR_ISCONN -10 Conn already established.*/
|
||||
ENOTCONN, /* ERR_CONN -11 Not connected. */
|
||||
-1, /* ERR_IF -12 Low-level netif error */
|
||||
ECONNABORTED, /* ERR_ABRT -13 Connection aborted. */
|
||||
ECONNRESET, /* ERR_RST -14 Connection reset. */
|
||||
ENOTCONN, /* ERR_CLSD -15 Connection closed. */
|
||||
EIO /* ERR_ARG -16 Illegal argument. */
|
||||
};
|
||||
|
||||
int
|
||||
|
||||
@@ -67,7 +67,7 @@ lwip_if_indextoname(unsigned int ifindex, char *ifname)
|
||||
return ifname;
|
||||
}
|
||||
}
|
||||
#else /* LWIP_NETIF_API */
|
||||
#else /* LWIP_NETIF_API */
|
||||
LWIP_UNUSED_ARG(ifindex);
|
||||
LWIP_UNUSED_ARG(ifname);
|
||||
#endif /* LWIP_NETIF_API */
|
||||
@@ -93,9 +93,9 @@ lwip_if_nametoindex(const char *ifname)
|
||||
if (!err) {
|
||||
return idx;
|
||||
}
|
||||
#else /* LWIP_NETIF_API */
|
||||
#else /* LWIP_NETIF_API */
|
||||
LWIP_UNUSED_ARG(ifname);
|
||||
#endif /* LWIP_NETIF_API */
|
||||
#endif /* LWIP_NETIF_API */
|
||||
return 0; /* invalid index */
|
||||
}
|
||||
|
||||
|
||||
@@ -46,8 +46,8 @@
|
||||
|
||||
#if LWIP_NETCONN /* don't build if not configured for use in lwipopts.h */
|
||||
|
||||
#include "lwip/netbuf.h"
|
||||
#include "lwip/memp.h"
|
||||
#include "lwip/netbuf.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
@@ -59,8 +59,8 @@
|
||||
* @return a pointer to a new netbuf
|
||||
* NULL on lack of memory
|
||||
*/
|
||||
struct
|
||||
netbuf *netbuf_new(void)
|
||||
struct netbuf *
|
||||
netbuf_new(void)
|
||||
{
|
||||
struct netbuf *buf;
|
||||
|
||||
@@ -111,8 +111,7 @@ netbuf_alloc(struct netbuf *buf, u16_t size)
|
||||
if (buf->p == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
LWIP_ASSERT("check that first pbuf can hold size",
|
||||
(buf->p->len >= size));
|
||||
LWIP_ASSERT("check that first pbuf can hold size", (buf->p->len >= size));
|
||||
buf->ptr = buf->p;
|
||||
return buf->p->payload;
|
||||
}
|
||||
|
||||
@@ -39,18 +39,19 @@
|
||||
|
||||
#if LWIP_DNS && LWIP_SOCKET
|
||||
|
||||
#include "lwip/err.h"
|
||||
#include "lwip/mem.h"
|
||||
#include "lwip/memp.h"
|
||||
#include "lwip/ip_addr.h"
|
||||
#include "lwip/api.h"
|
||||
#include "lwip/dns.h"
|
||||
#include "lwip/err.h"
|
||||
#include "lwip/ip_addr.h"
|
||||
#include "lwip/mem.h"
|
||||
#include "lwip/memp.h"
|
||||
|
||||
#include <string.h> /* memset */
|
||||
#include <stdlib.h> /* atoi */
|
||||
#include <string.h> /* memset */
|
||||
|
||||
/** helper struct for gethostbyname_r to access the char* buffer */
|
||||
struct gethostbyname_r_helper {
|
||||
struct gethostbyname_r_helper
|
||||
{
|
||||
ip_addr_t *addr_list[2];
|
||||
ip_addr_t addr;
|
||||
char *aliases;
|
||||
@@ -129,7 +130,8 @@ lwip_gethostbyname(const char *name)
|
||||
u8_t idx;
|
||||
for (idx = 0; s_hostent.h_addr_list[idx]; idx++) {
|
||||
LWIP_DEBUGF(DNS_DEBUG, ("hostent.h_addr_list[%i] == %p\n", idx, s_hostent.h_addr_list[idx]));
|
||||
LWIP_DEBUGF(DNS_DEBUG, ("hostent.h_addr_list[%i]-> == %s\n", idx, ipaddr_ntoa((ip_addr_t *)s_hostent.h_addr_list[idx])));
|
||||
LWIP_DEBUGF(DNS_DEBUG,
|
||||
("hostent.h_addr_list[%i]-> == %s\n", idx, ipaddr_ntoa((ip_addr_t *)s_hostent.h_addr_list[idx])));
|
||||
}
|
||||
}
|
||||
#endif /* DNS_DEBUG */
|
||||
@@ -159,8 +161,12 @@ lwip_gethostbyname(const char *name)
|
||||
* is stored in *h_errnop instead of h_errno to be thread-safe
|
||||
*/
|
||||
int
|
||||
lwip_gethostbyname_r(const char *name, struct hostent *ret, char *buf,
|
||||
size_t buflen, struct hostent **result, int *h_errnop)
|
||||
lwip_gethostbyname_r(const char *name,
|
||||
struct hostent *ret,
|
||||
char *buf,
|
||||
size_t buflen,
|
||||
struct hostent **result,
|
||||
int *h_errnop)
|
||||
{
|
||||
err_t err;
|
||||
struct gethostbyname_r_helper *h;
|
||||
@@ -266,8 +272,7 @@ lwip_freeaddrinfo(struct addrinfo *ai)
|
||||
* @todo: implement AI_V4MAPPED, AI_ADDRCONFIG
|
||||
*/
|
||||
int
|
||||
lwip_getaddrinfo(const char *nodename, const char *servname,
|
||||
const struct addrinfo *hints, struct addrinfo **res)
|
||||
lwip_getaddrinfo(const char *nodename, const char *servname, const struct addrinfo *hints, struct addrinfo **res)
|
||||
{
|
||||
err_t err;
|
||||
ip_addr_t addr;
|
||||
@@ -295,7 +300,7 @@ lwip_getaddrinfo(const char *nodename, const char *servname,
|
||||
#if LWIP_IPV6
|
||||
&& (ai_family != AF_INET6)
|
||||
#endif /* LWIP_IPV6 */
|
||||
) {
|
||||
) {
|
||||
return EAI_FAMILY;
|
||||
}
|
||||
} else {
|
||||
@@ -319,8 +324,7 @@ lwip_getaddrinfo(const char *nodename, const char *servname,
|
||||
return EAI_NONAME;
|
||||
}
|
||||
#if LWIP_IPV4 && LWIP_IPV6
|
||||
if ((IP_IS_V6_VAL(addr) && ai_family == AF_INET) ||
|
||||
(IP_IS_V4_VAL(addr) && ai_family == AF_INET6)) {
|
||||
if ((IP_IS_V6_VAL(addr) && ai_family == AF_INET) || (IP_IS_V4_VAL(addr) && ai_family == AF_INET6)) {
|
||||
return EAI_NONAME;
|
||||
}
|
||||
#endif /* LWIP_IPV4 && LWIP_IPV6 */
|
||||
@@ -359,8 +363,7 @@ lwip_getaddrinfo(const char *nodename, const char *servname,
|
||||
total_size += namelen + 1;
|
||||
}
|
||||
/* If this fails, please report to lwip-devel! :-) */
|
||||
LWIP_ASSERT("total_size <= NETDB_ELEM_SIZE: please report this!",
|
||||
total_size <= NETDB_ELEM_SIZE);
|
||||
LWIP_ASSERT("total_size <= NETDB_ELEM_SIZE: please report this!", total_size <= NETDB_ELEM_SIZE);
|
||||
ai = (struct addrinfo *)memp_malloc(MEMP_NETDB);
|
||||
if (ai == NULL) {
|
||||
return EAI_MEMORY;
|
||||
|
||||
@@ -43,16 +43,16 @@
|
||||
#if LWIP_NETIF_API /* don't build if not configured for use in lwipopts.h */
|
||||
|
||||
#include "lwip/etharp.h"
|
||||
#include "lwip/netifapi.h"
|
||||
#include "lwip/memp.h"
|
||||
#include "lwip/netifapi.h"
|
||||
#include "lwip/priv/tcpip_priv.h"
|
||||
|
||||
#include <string.h> /* strncpy */
|
||||
|
||||
#define NETIFAPI_VAR_REF(name) API_VAR_REF(name)
|
||||
#define NETIFAPI_VAR_DECLARE(name) API_VAR_DECLARE(struct netifapi_msg, name)
|
||||
#define NETIFAPI_VAR_ALLOC(name) API_VAR_ALLOC(struct netifapi_msg, MEMP_NETIFAPI_MSG, name, ERR_MEM)
|
||||
#define NETIFAPI_VAR_FREE(name) API_VAR_FREE(MEMP_NETIFAPI_MSG, name)
|
||||
#define NETIFAPI_VAR_REF(name) API_VAR_REF(name)
|
||||
#define NETIFAPI_VAR_DECLARE(name) API_VAR_DECLARE(struct netifapi_msg, name)
|
||||
#define NETIFAPI_VAR_ALLOC(name) API_VAR_ALLOC(struct netifapi_msg, MEMP_NETIFAPI_MSG, name, ERR_MEM)
|
||||
#define NETIFAPI_VAR_FREE(name) API_VAR_FREE(MEMP_NETIFAPI_MSG, name)
|
||||
|
||||
/**
|
||||
* Call netif_add() inside the tcpip_thread context.
|
||||
@@ -64,15 +64,15 @@ netifapi_do_netif_add(struct tcpip_api_call_data *m)
|
||||
* We know it works because the structs have been instantiated as struct netifapi_msg */
|
||||
struct netifapi_msg *msg = (struct netifapi_msg *)(void *)m;
|
||||
|
||||
if (!netif_add( msg->netif,
|
||||
if (!netif_add(msg->netif,
|
||||
#if LWIP_IPV4
|
||||
API_EXPR_REF(msg->msg.add.ipaddr),
|
||||
API_EXPR_REF(msg->msg.add.netmask),
|
||||
API_EXPR_REF(msg->msg.add.gw),
|
||||
API_EXPR_REF(msg->msg.add.ipaddr),
|
||||
API_EXPR_REF(msg->msg.add.netmask),
|
||||
API_EXPR_REF(msg->msg.add.gw),
|
||||
#endif /* LWIP_IPV4 */
|
||||
msg->msg.add.state,
|
||||
msg->msg.add.init,
|
||||
msg->msg.add.input)) {
|
||||
msg->msg.add.state,
|
||||
msg->msg.add.init,
|
||||
msg->msg.add.input)) {
|
||||
return ERR_IF;
|
||||
} else {
|
||||
return ERR_OK;
|
||||
@@ -90,17 +90,15 @@ netifapi_do_netif_set_addr(struct tcpip_api_call_data *m)
|
||||
* We know it works because the structs have been instantiated as struct netifapi_msg */
|
||||
struct netifapi_msg *msg = (struct netifapi_msg *)(void *)m;
|
||||
|
||||
netif_set_addr( msg->netif,
|
||||
API_EXPR_REF(msg->msg.add.ipaddr),
|
||||
API_EXPR_REF(msg->msg.add.netmask),
|
||||
API_EXPR_REF(msg->msg.add.gw));
|
||||
netif_set_addr(
|
||||
msg->netif, API_EXPR_REF(msg->msg.add.ipaddr), API_EXPR_REF(msg->msg.add.netmask), API_EXPR_REF(msg->msg.add.gw));
|
||||
return ERR_OK;
|
||||
}
|
||||
#endif /* LWIP_IPV4 */
|
||||
|
||||
/**
|
||||
* Call netif_name_to_index() inside the tcpip_thread context.
|
||||
*/
|
||||
* Call netif_name_to_index() inside the tcpip_thread context.
|
||||
*/
|
||||
static err_t
|
||||
netifapi_do_name_to_index(struct tcpip_api_call_data *m)
|
||||
{
|
||||
@@ -113,8 +111,8 @@ netifapi_do_name_to_index(struct tcpip_api_call_data *m)
|
||||
}
|
||||
|
||||
/**
|
||||
* Call netif_index_to_name() inside the tcpip_thread context.
|
||||
*/
|
||||
* Call netif_index_to_name() inside the tcpip_thread context.
|
||||
*/
|
||||
static err_t
|
||||
netifapi_do_index_to_name(struct tcpip_api_call_data *m)
|
||||
{
|
||||
@@ -221,9 +219,13 @@ netifapi_arp_remove(const ip4_addr_t *ipaddr, enum netifapi_arp_entry type)
|
||||
err_t
|
||||
netifapi_netif_add(struct netif *netif,
|
||||
#if LWIP_IPV4
|
||||
const ip4_addr_t *ipaddr, const ip4_addr_t *netmask, const ip4_addr_t *gw,
|
||||
const ip4_addr_t *ipaddr,
|
||||
const ip4_addr_t *netmask,
|
||||
const ip4_addr_t *gw,
|
||||
#endif /* LWIP_IPV4 */
|
||||
void *state, netif_init_fn init, netif_input_fn input)
|
||||
void *state,
|
||||
netif_init_fn init,
|
||||
netif_input_fn input)
|
||||
{
|
||||
err_t err;
|
||||
NETIFAPI_VAR_DECLARE(msg);
|
||||
@@ -243,13 +245,13 @@ netifapi_netif_add(struct netif *netif,
|
||||
|
||||
NETIFAPI_VAR_REF(msg).netif = netif;
|
||||
#if LWIP_IPV4
|
||||
NETIFAPI_VAR_REF(msg).msg.add.ipaddr = NETIFAPI_VAR_REF(ipaddr);
|
||||
NETIFAPI_VAR_REF(msg).msg.add.ipaddr = NETIFAPI_VAR_REF(ipaddr);
|
||||
NETIFAPI_VAR_REF(msg).msg.add.netmask = NETIFAPI_VAR_REF(netmask);
|
||||
NETIFAPI_VAR_REF(msg).msg.add.gw = NETIFAPI_VAR_REF(gw);
|
||||
NETIFAPI_VAR_REF(msg).msg.add.gw = NETIFAPI_VAR_REF(gw);
|
||||
#endif /* LWIP_IPV4 */
|
||||
NETIFAPI_VAR_REF(msg).msg.add.state = state;
|
||||
NETIFAPI_VAR_REF(msg).msg.add.init = init;
|
||||
NETIFAPI_VAR_REF(msg).msg.add.input = input;
|
||||
NETIFAPI_VAR_REF(msg).msg.add.state = state;
|
||||
NETIFAPI_VAR_REF(msg).msg.add.init = init;
|
||||
NETIFAPI_VAR_REF(msg).msg.add.input = input;
|
||||
err = tcpip_api_call(netifapi_do_netif_add, &API_VAR_REF(msg).call);
|
||||
NETIFAPI_VAR_FREE(msg);
|
||||
return err;
|
||||
@@ -264,10 +266,7 @@ netifapi_netif_add(struct netif *netif,
|
||||
* @note for params @see netif_set_addr()
|
||||
*/
|
||||
err_t
|
||||
netifapi_netif_set_addr(struct netif *netif,
|
||||
const ip4_addr_t *ipaddr,
|
||||
const ip4_addr_t *netmask,
|
||||
const ip4_addr_t *gw)
|
||||
netifapi_netif_set_addr(struct netif *netif, const ip4_addr_t *ipaddr, const ip4_addr_t *netmask, const ip4_addr_t *gw)
|
||||
{
|
||||
err_t err;
|
||||
NETIFAPI_VAR_DECLARE(msg);
|
||||
@@ -284,9 +283,9 @@ netifapi_netif_set_addr(struct netif *netif,
|
||||
}
|
||||
|
||||
NETIFAPI_VAR_REF(msg).netif = netif;
|
||||
NETIFAPI_VAR_REF(msg).msg.add.ipaddr = NETIFAPI_VAR_REF(ipaddr);
|
||||
NETIFAPI_VAR_REF(msg).msg.add.ipaddr = NETIFAPI_VAR_REF(ipaddr);
|
||||
NETIFAPI_VAR_REF(msg).msg.add.netmask = NETIFAPI_VAR_REF(netmask);
|
||||
NETIFAPI_VAR_REF(msg).msg.add.gw = NETIFAPI_VAR_REF(gw);
|
||||
NETIFAPI_VAR_REF(msg).msg.add.gw = NETIFAPI_VAR_REF(gw);
|
||||
err = tcpip_api_call(netifapi_do_netif_set_addr, &API_VAR_REF(msg).call);
|
||||
NETIFAPI_VAR_FREE(msg);
|
||||
return err;
|
||||
@@ -300,8 +299,7 @@ netifapi_netif_set_addr(struct netif *netif,
|
||||
* @note use only for functions where there is only "netif" parameter.
|
||||
*/
|
||||
err_t
|
||||
netifapi_netif_common(struct netif *netif, netifapi_void_fn voidfunc,
|
||||
netifapi_errt_fn errtfunc)
|
||||
netifapi_netif_common(struct netif *netif, netifapi_void_fn voidfunc, netifapi_errt_fn errtfunc)
|
||||
{
|
||||
err_t err;
|
||||
NETIFAPI_VAR_DECLARE(msg);
|
||||
@@ -316,13 +314,13 @@ netifapi_netif_common(struct netif *netif, netifapi_void_fn voidfunc,
|
||||
}
|
||||
|
||||
/**
|
||||
* @ingroup netifapi_netif
|
||||
* Call netif_name_to_index() in a thread-safe way by running that function inside the
|
||||
* tcpip_thread context.
|
||||
*
|
||||
* @param name the interface name of the netif
|
||||
* @param idx output index of the found netif
|
||||
*/
|
||||
* @ingroup netifapi_netif
|
||||
* Call netif_name_to_index() in a thread-safe way by running that function inside the
|
||||
* tcpip_thread context.
|
||||
*
|
||||
* @param name the interface name of the netif
|
||||
* @param idx output index of the found netif
|
||||
*/
|
||||
err_t
|
||||
netifapi_netif_name_to_index(const char *name, u8_t *idx)
|
||||
{
|
||||
@@ -347,14 +345,14 @@ netifapi_netif_name_to_index(const char *name, u8_t *idx)
|
||||
}
|
||||
|
||||
/**
|
||||
* @ingroup netifapi_netif
|
||||
* Call netif_index_to_name() in a thread-safe way by running that function inside the
|
||||
* tcpip_thread context.
|
||||
*
|
||||
* @param idx the interface index of the netif
|
||||
* @param name output name of the found netif, empty '\0' string if netif not found.
|
||||
* name should be of at least NETIF_NAMESIZE bytes
|
||||
*/
|
||||
* @ingroup netifapi_netif
|
||||
* Call netif_index_to_name() in a thread-safe way by running that function inside the
|
||||
* tcpip_thread context.
|
||||
*
|
||||
* @param idx the interface index of the netif
|
||||
* @param name output name of the found netif, empty '\0' string if netif not found.
|
||||
* name should be of at least NETIF_NAMESIZE bytes
|
||||
*/
|
||||
err_t
|
||||
netifapi_netif_index_to_name(u8_t idx, char *name)
|
||||
{
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -40,20 +40,20 @@
|
||||
|
||||
#if !NO_SYS /* don't build if not configured for use in lwipopts.h */
|
||||
|
||||
#include "lwip/priv/tcpip_priv.h"
|
||||
#include "lwip/sys.h"
|
||||
#include "lwip/memp.h"
|
||||
#include "lwip/mem.h"
|
||||
#include "lwip/etharp.h"
|
||||
#include "lwip/init.h"
|
||||
#include "lwip/ip.h"
|
||||
#include "lwip/mem.h"
|
||||
#include "lwip/memp.h"
|
||||
#include "lwip/pbuf.h"
|
||||
#include "lwip/etharp.h"
|
||||
#include "lwip/priv/tcpip_priv.h"
|
||||
#include "lwip/sys.h"
|
||||
#include "netif/ethernet.h"
|
||||
|
||||
#define TCPIP_MSG_VAR_REF(name) API_VAR_REF(name)
|
||||
#define TCPIP_MSG_VAR_REF(name) API_VAR_REF(name)
|
||||
#define TCPIP_MSG_VAR_DECLARE(name) API_VAR_DECLARE(struct tcpip_msg, name)
|
||||
#define TCPIP_MSG_VAR_ALLOC(name) API_VAR_ALLOC(struct tcpip_msg, MEMP_TCPIP_MSG_API, name, ERR_MEM)
|
||||
#define TCPIP_MSG_VAR_FREE(name) API_VAR_FREE(MEMP_TCPIP_MSG_API, name)
|
||||
#define TCPIP_MSG_VAR_ALLOC(name) API_VAR_ALLOC(struct tcpip_msg, MEMP_TCPIP_MSG_API, name, ERR_MEM)
|
||||
#define TCPIP_MSG_VAR_FREE(name) API_VAR_FREE(MEMP_TCPIP_MSG_API, name)
|
||||
|
||||
/* global variables */
|
||||
static tcpip_init_done_fn tcpip_init_done;
|
||||
@@ -65,7 +65,8 @@ static sys_mbox_t tcpip_mbox;
|
||||
sys_mutex_t lock_tcpip_core;
|
||||
#endif /* LWIP_TCPIP_CORE_LOCKING */
|
||||
|
||||
static void tcpip_thread_handle_msg(struct tcpip_msg *msg);
|
||||
static void
|
||||
tcpip_thread_handle_msg(struct tcpip_msg *msg);
|
||||
|
||||
#if !LWIP_TIMERS
|
||||
/* wait for a message with timers disabled (e.g. pass a timer-check trigger into tcpip_thread) */
|
||||
@@ -136,7 +137,7 @@ tcpip_thread(void *arg)
|
||||
tcpip_init_done(tcpip_init_done_arg);
|
||||
}
|
||||
|
||||
while (1) { /* MAIN Loop */
|
||||
while (1) { /* MAIN Loop */
|
||||
LWIP_TCPIP_THREAD_ALIVE();
|
||||
/* wait for a message, timeouts are processed while waiting */
|
||||
TCPIP_MBOX_FETCH(&tcpip_mbox, (void **)&msg);
|
||||
@@ -246,7 +247,7 @@ tcpip_inpkt(struct pbuf *p, struct netif *inp, netif_input_fn input_fn)
|
||||
ret = input_fn(p, inp);
|
||||
UNLOCK_TCPIP_CORE();
|
||||
return ret;
|
||||
#else /* LWIP_TCPIP_CORE_LOCKING_INPUT */
|
||||
#else /* LWIP_TCPIP_CORE_LOCKING_INPUT */
|
||||
struct tcpip_msg *msg;
|
||||
|
||||
LWIP_ASSERT("Invalid mbox", sys_mbox_valid_val(tcpip_mbox));
|
||||
@@ -420,7 +421,6 @@ tcpip_untimeout(sys_timeout_handler h, void *arg)
|
||||
}
|
||||
#endif /* LWIP_TCPIP_TIMEOUT && LWIP_TIMERS */
|
||||
|
||||
|
||||
/**
|
||||
* Sends a message to TCPIP thread to call a function. Caller thread blocks on
|
||||
* on a provided semaphore, which ist NOT automatically signalled by TCPIP thread,
|
||||
@@ -442,7 +442,7 @@ tcpip_send_msg_wait_sem(tcpip_callback_fn fn, void *apimsg, sys_sem_t *sem)
|
||||
fn(apimsg);
|
||||
UNLOCK_TCPIP_CORE();
|
||||
return ERR_OK;
|
||||
#else /* LWIP_TCPIP_CORE_LOCKING */
|
||||
#else /* LWIP_TCPIP_CORE_LOCKING */
|
||||
TCPIP_MSG_VAR_DECLARE(msg);
|
||||
|
||||
LWIP_ASSERT("semaphore not initialized", sys_sem_valid(sem));
|
||||
@@ -496,7 +496,7 @@ tcpip_api_call(tcpip_api_call_fn fn, struct tcpip_api_call_data *call)
|
||||
TCPIP_MSG_VAR_REF(msg).msg.api_call.function = fn;
|
||||
#if LWIP_NETCONN_SEM_PER_THREAD
|
||||
TCPIP_MSG_VAR_REF(msg).msg.api_call.sem = LWIP_NETCONN_THREAD_SEM_GET();
|
||||
#else /* LWIP_NETCONN_SEM_PER_THREAD */
|
||||
#else /* LWIP_NETCONN_SEM_PER_THREAD */
|
||||
TCPIP_MSG_VAR_REF(msg).msg.api_call.sem = &call->sem;
|
||||
#endif /* LWIP_NETCONN_SEM_PER_THREAD */
|
||||
sys_mbox_post(&tcpip_mbox, &TCPIP_MSG_VAR_REF(msg));
|
||||
@@ -519,7 +519,7 @@ tcpip_api_call(tcpip_api_call_fn fn, struct tcpip_api_call_data *call)
|
||||
* e.g. the message is allocated once and posted several times from an IRQ
|
||||
* using tcpip_callbackmsg_trycallback().
|
||||
* Example usage: Trigger execution of an ethernet IRQ DPC routine in lwIP thread context.
|
||||
*
|
||||
*
|
||||
* @param function the function to call
|
||||
* @param ctx parameter passed to function
|
||||
* @return a struct pointer to pass to tcpip_callbackmsg_trycallback().
|
||||
|
||||
Reference in New Issue
Block a user