|
|
|
|
@ -63,34 +63,32 @@
|
|
|
|
|
|
|
|
|
|
static err_t netconn_close_shutdown(struct netconn *conn, u8_t how); |
|
|
|
|
|
|
|
|
|
#if !LWIP_TCPIP_CORE_LOCKING |
|
|
|
|
/**
|
|
|
|
|
* Call the lower part of a netconn_* function |
|
|
|
|
* This function is then running in the thread context |
|
|
|
|
* of tcpip_thread and has exclusive access to lwIP core code. |
|
|
|
|
* |
|
|
|
|
* @param fn function to call |
|
|
|
|
* @param apimsg a struct containing the function to call and its parameters |
|
|
|
|
* @return ERR_OK if the function was called, another err_t if not |
|
|
|
|
*/ |
|
|
|
|
static err_t |
|
|
|
|
tcpip_apimsg(struct api_msg *apimsg) |
|
|
|
|
tcpip_apimsg(tcpip_callback_fn fn, struct api_msg *apimsg) |
|
|
|
|
{ |
|
|
|
|
#ifdef LWIP_DEBUG |
|
|
|
|
/* catch functions that don't set err */ |
|
|
|
|
apimsg->msg.err = ERR_VAL; |
|
|
|
|
#endif |
|
|
|
|
#endif /* LWIP_DEBUG */ |
|
|
|
|
|
|
|
|
|
#if LWIP_NETCONN_SEM_PER_THREAD |
|
|
|
|
apimsg->msg.op_completed_sem = LWIP_NETCONN_THREAD_SEM_GET(); |
|
|
|
|
LWIP_ASSERT("netconn semaphore not initialized", |
|
|
|
|
sys_sem_valid(apimsg->msg.op_completed_sem)); |
|
|
|
|
#endif |
|
|
|
|
#endif /* LWIP_NETCONN_SEM_PER_THREAD */ |
|
|
|
|
|
|
|
|
|
if (tcpip_send_api_msg(apimsg->function, &apimsg->msg, LWIP_API_MSG_SEM(&apimsg->msg)) == ERR_OK) { |
|
|
|
|
if (tcpip_send_api_msg(fn, &apimsg->msg, LWIP_API_MSG_SEM(&apimsg->msg)) == ERR_OK) { |
|
|
|
|
return apimsg->msg.err; |
|
|
|
|
} |
|
|
|
|
return ERR_VAL; |
|
|
|
|
} |
|
|
|
|
#endif /* !LWIP_TCPIP_CORE_LOCKING */ |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Create a new netconn (of a specific type) that has a callback function. |
|
|
|
|
@ -114,7 +112,7 @@ netconn_new_with_proto_and_callback(enum netconn_type t, u8_t proto, netconn_cal
|
|
|
|
|
API_MSG_VAR_ALLOC_DONTFAIL(msg); |
|
|
|
|
API_MSG_VAR_REF(msg).msg.msg.n.proto = proto; |
|
|
|
|
API_MSG_VAR_REF(msg).msg.conn = conn; |
|
|
|
|
TCPIP_APIMSG(&API_MSG_VAR_REF(msg), lwip_netconn_do_newconn, err); |
|
|
|
|
err = tcpip_apimsg(lwip_netconn_do_newconn, &API_MSG_VAR_REF(msg)); |
|
|
|
|
API_MSG_VAR_FREE(msg); |
|
|
|
|
if (err != ERR_OK) { |
|
|
|
|
LWIP_ASSERT("freeing conn without freeing pcb", conn->pcb.tcp == NULL); |
|
|
|
|
@ -165,7 +163,7 @@ netconn_delete(struct netconn *conn)
|
|
|
|
|
((LWIP_TCP_CLOSE_TIMEOUT_MS_DEFAULT + TCP_SLOW_INTERVAL - 1) / TCP_SLOW_INTERVAL) + 1; |
|
|
|
|
#endif /* LWIP_TCP */ |
|
|
|
|
#endif /* LWIP_SO_SNDTIMEO || LWIP_SO_LINGER */ |
|
|
|
|
TCPIP_APIMSG(&API_MSG_VAR_REF(msg), lwip_netconn_do_delconn, err); |
|
|
|
|
err = tcpip_apimsg(lwip_netconn_do_delconn, &API_MSG_VAR_REF(msg)); |
|
|
|
|
API_MSG_VAR_FREE(msg); |
|
|
|
|
|
|
|
|
|
if (err != ERR_OK) { |
|
|
|
|
@ -208,7 +206,7 @@ netconn_getaddr(struct netconn *conn, ip_addr_t *addr, u16_t *port, u8_t local)
|
|
|
|
|
#else /* LWIP_MPU_COMPATIBLE */ |
|
|
|
|
msg.msg.msg.ad.ipaddr = addr; |
|
|
|
|
msg.msg.msg.ad.port = port; |
|
|
|
|
TCPIP_APIMSG(&msg, lwip_netconn_do_getaddr, err); |
|
|
|
|
err = tcpip_apimsg(lwip_netconn_do_getaddr, &msg); |
|
|
|
|
#endif /* LWIP_MPU_COMPATIBLE */ |
|
|
|
|
API_MSG_VAR_FREE(msg); |
|
|
|
|
|
|
|
|
|
@ -242,7 +240,7 @@ netconn_bind(struct netconn *conn, const ip_addr_t *addr, u16_t port)
|
|
|
|
|
API_MSG_VAR_REF(msg).msg.conn = conn; |
|
|
|
|
API_MSG_VAR_REF(msg).msg.msg.bc.ipaddr = API_MSG_VAR_REF(addr); |
|
|
|
|
API_MSG_VAR_REF(msg).msg.msg.bc.port = port; |
|
|
|
|
TCPIP_APIMSG(&API_MSG_VAR_REF(msg), lwip_netconn_do_bind, err); |
|
|
|
|
err = tcpip_apimsg(lwip_netconn_do_bind, &API_MSG_VAR_REF(msg)); |
|
|
|
|
API_MSG_VAR_FREE(msg); |
|
|
|
|
|
|
|
|
|
return err; |
|
|
|
|
@ -273,7 +271,7 @@ netconn_connect(struct netconn *conn, const ip_addr_t *addr, u16_t port)
|
|
|
|
|
API_MSG_VAR_REF(msg).msg.conn = conn; |
|
|
|
|
API_MSG_VAR_REF(msg).msg.msg.bc.ipaddr = API_MSG_VAR_REF(addr); |
|
|
|
|
API_MSG_VAR_REF(msg).msg.msg.bc.port = port; |
|
|
|
|
TCPIP_APIMSG(&API_MSG_VAR_REF(msg), lwip_netconn_do_connect, err); |
|
|
|
|
err = tcpip_apimsg(lwip_netconn_do_connect, &API_MSG_VAR_REF(msg)); |
|
|
|
|
API_MSG_VAR_FREE(msg); |
|
|
|
|
|
|
|
|
|
return err; |
|
|
|
|
@ -295,7 +293,7 @@ netconn_disconnect(struct netconn *conn)
|
|
|
|
|
|
|
|
|
|
API_MSG_VAR_ALLOC(msg); |
|
|
|
|
API_MSG_VAR_REF(msg).msg.conn = conn; |
|
|
|
|
TCPIP_APIMSG(&API_MSG_VAR_REF(msg), lwip_netconn_do_disconnect, err); |
|
|
|
|
err = tcpip_apimsg(lwip_netconn_do_disconnect, &API_MSG_VAR_REF(msg)); |
|
|
|
|
API_MSG_VAR_FREE(msg); |
|
|
|
|
|
|
|
|
|
return err; |
|
|
|
|
@ -326,7 +324,7 @@ netconn_listen_with_backlog(struct netconn *conn, u8_t backlog)
|
|
|
|
|
#if TCP_LISTEN_BACKLOG |
|
|
|
|
API_MSG_VAR_REF(msg).msg.msg.lb.backlog = backlog; |
|
|
|
|
#endif /* TCP_LISTEN_BACKLOG */ |
|
|
|
|
TCPIP_APIMSG(&API_MSG_VAR_REF(msg), lwip_netconn_do_listen, err); |
|
|
|
|
err = tcpip_apimsg(lwip_netconn_do_listen, &API_MSG_VAR_REF(msg)); |
|
|
|
|
API_MSG_VAR_FREE(msg); |
|
|
|
|
|
|
|
|
|
return err; |
|
|
|
|
@ -390,7 +388,7 @@ netconn_accept(struct netconn *conn, struct netconn **new_conn)
|
|
|
|
|
API_MSG_VAR_ALLOC_DONTFAIL(msg); |
|
|
|
|
API_MSG_VAR_REF(msg).msg.conn = conn; |
|
|
|
|
/* don't care for the return value of lwip_netconn_do_recv */ |
|
|
|
|
TCPIP_APIMSG_NOERR(&API_MSG_VAR_REF(msg), lwip_netconn_do_recv); |
|
|
|
|
tcpip_apimsg(lwip_netconn_do_recv, &API_MSG_VAR_REF(msg)); |
|
|
|
|
API_MSG_VAR_FREE(msg); |
|
|
|
|
#endif /* TCP_LISTEN_BACKLOG */ |
|
|
|
|
|
|
|
|
|
@ -473,7 +471,7 @@ netconn_recv_data(struct netconn *conn, void **new_buf)
|
|
|
|
|
API_MSG_VAR_REF(msg).msg.msg.r.len = 1; |
|
|
|
|
} |
|
|
|
|
/* don't care for the return value of lwip_netconn_do_recv */ |
|
|
|
|
TCPIP_APIMSG_NOERR(&API_MSG_VAR_REF(msg), lwip_netconn_do_recv); |
|
|
|
|
tcpip_apimsg(lwip_netconn_do_recv, &API_MSG_VAR_REF(msg)); |
|
|
|
|
API_MSG_VAR_FREE(msg); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -612,7 +610,7 @@ netconn_recved(struct netconn *conn, u32_t length)
|
|
|
|
|
API_MSG_VAR_REF(msg).msg.conn = conn; |
|
|
|
|
API_MSG_VAR_REF(msg).msg.msg.r.len = length; |
|
|
|
|
/* don't care for the return value of lwip_netconn_do_recv */ |
|
|
|
|
TCPIP_APIMSG_NOERR(&API_MSG_VAR_REF(msg), lwip_netconn_do_recv); |
|
|
|
|
tcpip_apimsg(lwip_netconn_do_recv, &API_MSG_VAR_REF(msg)); |
|
|
|
|
API_MSG_VAR_FREE(msg); |
|
|
|
|
} |
|
|
|
|
#else /* LWIP_TCP */ |
|
|
|
|
@ -661,7 +659,7 @@ netconn_send(struct netconn *conn, struct netbuf *buf)
|
|
|
|
|
API_MSG_VAR_ALLOC(msg); |
|
|
|
|
API_MSG_VAR_REF(msg).msg.conn = conn; |
|
|
|
|
API_MSG_VAR_REF(msg).msg.msg.b = buf; |
|
|
|
|
TCPIP_APIMSG(&API_MSG_VAR_REF(msg), lwip_netconn_do_send, err); |
|
|
|
|
err = tcpip_apimsg(lwip_netconn_do_send, &API_MSG_VAR_REF(msg)); |
|
|
|
|
API_MSG_VAR_FREE(msg); |
|
|
|
|
|
|
|
|
|
return err; |
|
|
|
|
@ -719,7 +717,7 @@ netconn_write_partly(struct netconn *conn, const void *dataptr, size_t size,
|
|
|
|
|
/* For locking the core: this _can_ be delayed on low memory/low send buffer,
|
|
|
|
|
but if it is, this is done inside api_msg.c:do_write(), so we can use the |
|
|
|
|
non-blocking version here. */ |
|
|
|
|
TCPIP_APIMSG(&API_MSG_VAR_REF(msg), lwip_netconn_do_write, err); |
|
|
|
|
err = tcpip_apimsg(lwip_netconn_do_write, &API_MSG_VAR_REF(msg)); |
|
|
|
|
if ((err == ERR_OK) && (bytes_written != NULL)) { |
|
|
|
|
if (dontblock |
|
|
|
|
#if LWIP_SO_SNDTIMEO |
|
|
|
|
@ -768,7 +766,7 @@ netconn_close_shutdown(struct netconn *conn, u8_t how)
|
|
|
|
|
((LWIP_TCP_CLOSE_TIMEOUT_MS_DEFAULT + TCP_SLOW_INTERVAL - 1) / TCP_SLOW_INTERVAL) + 1; |
|
|
|
|
#endif /* LWIP_SO_SNDTIMEO || LWIP_SO_LINGER */ |
|
|
|
|
#endif /* LWIP_TCP */ |
|
|
|
|
TCPIP_APIMSG(&API_MSG_VAR_REF(msg), lwip_netconn_do_close, err); |
|
|
|
|
err = tcpip_apimsg(lwip_netconn_do_close, &API_MSG_VAR_REF(msg)); |
|
|
|
|
API_MSG_VAR_FREE(msg); |
|
|
|
|
|
|
|
|
|
return err; |
|
|
|
|
@ -835,7 +833,7 @@ netconn_join_leave_group(struct netconn *conn,
|
|
|
|
|
API_MSG_VAR_REF(msg).msg.msg.jl.multiaddr = API_MSG_VAR_REF(multiaddr); |
|
|
|
|
API_MSG_VAR_REF(msg).msg.msg.jl.netif_addr = API_MSG_VAR_REF(netif_addr); |
|
|
|
|
API_MSG_VAR_REF(msg).msg.msg.jl.join_or_leave = join_or_leave; |
|
|
|
|
TCPIP_APIMSG(&API_MSG_VAR_REF(msg), lwip_netconn_do_join_leave_group, err); |
|
|
|
|
err = tcpip_apimsg(lwip_netconn_do_join_leave_group, &API_MSG_VAR_REF(msg)); |
|
|
|
|
API_MSG_VAR_FREE(msg); |
|
|
|
|
|
|
|
|
|
return err; |
|
|
|
|
|