altcp_tcp: use 'void* state' to store tcp_pcb, not 'altcp_pcb* inner_conn'

This commit is contained in:
goldsimon 2017-03-28 09:08:33 +02:00
parent 881ab3011e
commit 1dfe916808

View File

@ -53,6 +53,11 @@
#include <string.h>
#define ALTCP_TCP_ASSERT_CONN(conn, tpcb) do { \
LWIP_ASSERT("pcb mismatch", (conn)->state == tpcb); \
LWIP_ASSERT("conn->inner_conn == NULL", (conn)->inner_conn == NULL); } while(0)
/* Variable prototype, the actual declaration is at the end of this file
since it contains pointers to static functions declared here */
extern const struct altcp_functions altcp_tcp_functions;
@ -81,7 +86,7 @@ altcp_tcp_connected(void *arg, struct tcp_pcb *tpcb, err_t err)
{
struct altcp_pcb *conn = (struct altcp_pcb *)arg;
if (conn) {
LWIP_ASSERT("pcb mismatch", conn->inner_conn == (struct altcp_pcb *)tpcb);
ALTCP_TCP_ASSERT_CONN(conn, tpcb);
if (conn->connected) {
return conn->connected(conn->arg, conn, err);
}
@ -94,7 +99,7 @@ altcp_tcp_recv(void *arg, struct tcp_pcb *tpcb, struct pbuf *p, err_t err)
{
struct altcp_pcb *conn = (struct altcp_pcb *)arg;
if (conn) {
LWIP_ASSERT("pcb mismatch", conn->inner_conn == (struct altcp_pcb *)tpcb);
ALTCP_TCP_ASSERT_CONN(conn, tpcb);
if (conn->recv) {
return conn->recv(conn->arg, conn, p, err);
}
@ -111,7 +116,7 @@ altcp_tcp_sent(void *arg, struct tcp_pcb *tpcb, u16_t len)
{
struct altcp_pcb *conn = (struct altcp_pcb *)arg;
if (conn) {
LWIP_ASSERT("pcb mismatch", conn->inner_conn == (struct altcp_pcb *)tpcb);
ALTCP_TCP_ASSERT_CONN(conn, tpcb);
if (conn->sent) {
return conn->sent(conn->arg, conn, len);
}
@ -124,7 +129,7 @@ altcp_tcp_poll(void *arg, struct tcp_pcb *tpcb)
{
struct altcp_pcb *conn = (struct altcp_pcb *)arg;
if (conn) {
LWIP_ASSERT("pcb mismatch", conn->inner_conn == (struct altcp_pcb *)tpcb);
ALTCP_TCP_ASSERT_CONN(conn, tpcb);
if (conn->poll) {
return conn->poll(conn->arg, conn);
}
@ -159,7 +164,7 @@ static void
altcp_tcp_setup(struct altcp_pcb *conn, struct tcp_pcb *tpcb)
{
altcp_tcp_setup_callbacks(conn, tpcb);
conn->inner_conn = (struct altcp_pcb *)tpcb;
conn->state = tpcb;
conn->fns = &altcp_tcp_functions;
}
@ -187,7 +192,7 @@ static void
altcp_tcp_set_poll(struct altcp_pcb *conn, u8_t interval)
{
if (conn != NULL) {
struct tcp_pcb *pcb = (struct tcp_pcb *)conn->inner_conn;
struct tcp_pcb *pcb = (struct tcp_pcb *)conn->state;
tcp_poll(pcb, altcp_tcp_poll, interval);
}
}
@ -196,7 +201,7 @@ static void
altcp_tcp_recved(struct altcp_pcb *conn, u16_t len)
{
if (conn != NULL) {
struct tcp_pcb *pcb = (struct tcp_pcb *)conn->inner_conn;
struct tcp_pcb *pcb = (struct tcp_pcb *)conn->state;
tcp_recved(pcb, len);
}
}
@ -208,7 +213,7 @@ altcp_tcp_bind(struct altcp_pcb *conn, const ip_addr_t *ipaddr, u16_t port)
if (conn == NULL) {
return ERR_VAL;
}
pcb = (struct tcp_pcb *)conn->inner_conn;
pcb = (struct tcp_pcb *)conn->state;
return tcp_bind(pcb, ipaddr, port);
}
@ -220,7 +225,7 @@ altcp_tcp_connect(struct altcp_pcb *conn, const ip_addr_t *ipaddr, u16_t port, a
return ERR_VAL;
}
conn->connected = connected;
pcb = (struct tcp_pcb *)conn->inner_conn;
pcb = (struct tcp_pcb *)conn->state;
return tcp_connect(pcb, ipaddr, port, altcp_tcp_connected);
}
@ -232,10 +237,10 @@ altcp_tcp_listen(struct altcp_pcb *conn, u8_t backlog, err_t *err)
if (conn == NULL) {
return NULL;
}
pcb = (struct tcp_pcb *)conn->inner_conn;
pcb = (struct tcp_pcb *)conn->state;
lpcb = tcp_listen_with_backlog_and_err(pcb, backlog, err);
if (lpcb != NULL) {
conn->inner_conn = (struct altcp_pcb *)lpcb;
conn->state = lpcb;
tcp_accept(lpcb, altcp_tcp_accept);
return conn;
}
@ -246,7 +251,7 @@ static void
altcp_tcp_abort(struct altcp_pcb *conn)
{
if (conn != NULL) {
struct tcp_pcb *pcb = (struct tcp_pcb *)conn->inner_conn;
struct tcp_pcb *pcb = (struct tcp_pcb *)conn->state;
tcp_abort(pcb);
}
}
@ -258,7 +263,7 @@ altcp_tcp_close(struct altcp_pcb *conn)
if (conn == NULL) {
return ERR_VAL;
}
pcb = (struct tcp_pcb *)conn->inner_conn;
pcb = (struct tcp_pcb *)conn->state;
return tcp_close(pcb);
}
@ -269,7 +274,7 @@ altcp_tcp_shutdown(struct altcp_pcb *conn, int shut_rx, int shut_tx)
if (conn == NULL) {
return ERR_VAL;
}
pcb = (struct tcp_pcb *)conn->inner_conn;
pcb = (struct tcp_pcb *)conn->state;
return tcp_shutdown(pcb, shut_rx, shut_tx);
}
@ -280,7 +285,7 @@ altcp_tcp_write(struct altcp_pcb *conn, const void *dataptr, u16_t len, u8_t api
if (conn == NULL) {
return ERR_VAL;
}
pcb = (struct tcp_pcb *)conn->inner_conn;
pcb = (struct tcp_pcb *)conn->state;
return tcp_write(pcb, dataptr, len, apiflags);
}
@ -291,7 +296,7 @@ altcp_tcp_output(struct altcp_pcb *conn)
if (conn == NULL) {
return ERR_VAL;
}
pcb = (struct tcp_pcb *)conn->inner_conn;
pcb = (struct tcp_pcb *)conn->state;
return tcp_output(pcb);
}
@ -302,7 +307,7 @@ altcp_tcp_mss(struct altcp_pcb *conn)
if (conn == NULL) {
return 0;
}
pcb = (struct tcp_pcb *)conn->inner_conn;
pcb = (struct tcp_pcb *)conn->state;
return tcp_mss(pcb);
}
@ -313,7 +318,7 @@ altcp_tcp_sndbuf(struct altcp_pcb *conn)
if (conn == NULL) {
return 0;
}
pcb = (struct tcp_pcb *)conn->inner_conn;
pcb = (struct tcp_pcb *)conn->state;
return tcp_sndbuf(pcb);
}
@ -324,7 +329,7 @@ altcp_tcp_sndqueuelen(struct altcp_pcb *conn)
if (conn == NULL) {
return 0;
}
pcb = (struct tcp_pcb *)conn->inner_conn;
pcb = (struct tcp_pcb *)conn->state;
return tcp_sndqueuelen(pcb);
}
@ -332,7 +337,7 @@ static void
altcp_tcp_setprio(struct altcp_pcb *conn, u8_t prio)
{
if (conn != NULL) {
struct tcp_pcb *pcb = (struct tcp_pcb *)conn->inner_conn;
struct tcp_pcb *pcb = (struct tcp_pcb *)conn->state;
tcp_setprio(pcb, prio);
}
}
@ -348,7 +353,7 @@ static err_t
altcp_tcp_get_tcp_addrinfo(struct altcp_pcb *conn, int local, ip_addr_t *addr, u16_t *port)
{
if (conn) {
struct tcp_pcb *pcb = (struct tcp_pcb *)conn->inner_conn;
struct tcp_pcb *pcb = (struct tcp_pcb *)conn->state;
return tcp_tcp_get_tcp_addrinfo(pcb, local, addr, port);
}
return ERR_VAL;
@ -358,7 +363,7 @@ static ip_addr_t *
altcp_tcp_get_ip(struct altcp_pcb *conn, int local)
{
if (conn) {
struct tcp_pcb *pcb = (struct tcp_pcb *)conn->inner_conn;
struct tcp_pcb *pcb = (struct tcp_pcb *)conn->state;
if (pcb) {
if (local) {
return &pcb->local_ip;
@ -375,7 +380,7 @@ static enum tcp_state
altcp_tcp_dbg_get_tcp_state(struct altcp_pcb *conn)
{
if (conn) {
struct tcp_pcb *pcb = (struct tcp_pcb *)conn->inner_conn;
struct tcp_pcb *pcb = (struct tcp_pcb *)conn->state;
if (pcb) {
return pcb->state;
}