Some cleanups after applying David Girault's altcp patches

This commit is contained in:
goldsimon 2017-08-08 12:53:57 +02:00
parent bc3edfb4d7
commit 6d28e9de79
3 changed files with 30 additions and 36 deletions

View File

@ -291,15 +291,13 @@ altcp_mbedtls_lower_recv_process(struct altcp_pcb *conn, altcp_mbedtls_state_t *
if (conn->connected) { if (conn->connected) {
conn->connected(conn->arg, conn, ERR_OK); conn->connected(conn->arg, conn, ERR_OK);
} }
if (state->rx) if (state->rx == NULL) {
goto pbuf_left;
return ERR_OK; return ERR_OK;
} else {
/* handle application data */
pbuf_left:
return altcp_mbedtls_handle_rx_appldata(conn, state);
} }
} }
/* handle application data */
return altcp_mbedtls_handle_rx_appldata(conn, state);
}
/* Pass queued decoded rx data to application */ /* Pass queued decoded rx data to application */
static err_t static err_t
@ -613,7 +611,7 @@ void *
altcp_tls_context(struct altcp_pcb *conn) altcp_tls_context(struct altcp_pcb *conn)
{ {
if (conn && conn->state) { if (conn && conn->state) {
altcp_mbedtls_state_t *state = conn->state; altcp_mbedtls_state_t *state = (altcp_mbedtls_state_t *)conn->state;
return &state->ssl_context; return &state->ssl_context;
} }
return NULL; return NULL;
@ -774,7 +772,6 @@ altcp_tls_free_config(struct altcp_tls_config *conf)
altcp_mbedtls_free_config(conf); altcp_mbedtls_free_config(conf);
} }
/* "virtual" functions */ /* "virtual" functions */
static void static void
altcp_mbedtls_set_poll(struct altcp_pcb *conn, u8_t interval) altcp_mbedtls_set_poll(struct altcp_pcb *conn, u8_t interval)

View File

@ -63,6 +63,8 @@
since it contains pointers to static functions declared here */ since it contains pointers to static functions declared here */
extern const struct altcp_functions altcp_tcp_functions; extern const struct altcp_functions altcp_tcp_functions;
static void altcp_tcp_setup(struct altcp_pcb *conn, struct tcp_pcb *tpcb);
/* callback functions for TCP */ /* callback functions for TCP */
static err_t static err_t
altcp_tcp_accept(void *arg, struct tcp_pcb *new_tpcb, err_t err) altcp_tcp_accept(void *arg, struct tcp_pcb *new_tpcb, err_t err)
@ -150,15 +152,6 @@ altcp_tcp_err(void *arg, err_t err)
} }
/* setup functions */ /* setup functions */
static void
altcp_tcp_remove_callbacks(struct altcp_pcb *conn, struct tcp_pcb *tpcb)
tcp_arg(tpcb, NULL);
tcp_recv(tpcb, NULL);
tcp_sent(tpcb, NULL);
tcp_err(tpcb, NULL);
}
static void static void
altcp_tcp_setup_callbacks(struct altcp_pcb *conn, struct tcp_pcb *tpcb) altcp_tcp_setup_callbacks(struct altcp_pcb *conn, struct tcp_pcb *tpcb)
{ {
@ -170,7 +163,7 @@ altcp_tcp_setup_callbacks(struct altcp_pcb *conn, struct tcp_pcb *tpcb)
/* listen is set totally different :-) */ /* listen is set totally different :-) */
} }
void static void
altcp_tcp_setup(struct altcp_pcb *conn, struct tcp_pcb *tpcb) altcp_tcp_setup(struct altcp_pcb *conn, struct tcp_pcb *tpcb)
{ {
altcp_tcp_setup_callbacks(conn, tpcb); altcp_tcp_setup_callbacks(conn, tpcb);
@ -181,7 +174,6 @@ altcp_tcp_setup(struct altcp_pcb *conn, struct tcp_pcb *tpcb)
struct altcp_pcb * struct altcp_pcb *
altcp_tcp_new_ip_type(u8_t ip_type) altcp_tcp_new_ip_type(u8_t ip_type)
{ {
/* FIXME: pool alloc */
struct altcp_pcb *ret = altcp_alloc(); struct altcp_pcb *ret = altcp_alloc();
if (ret != NULL) { if (ret != NULL) {
struct tcp_pcb *tpcb = tcp_new_ip_type(ip_type); struct tcp_pcb *tpcb = tcp_new_ip_type(ip_type);
@ -196,6 +188,19 @@ altcp_tcp_new_ip_type(u8_t ip_type)
return ret; return ret;
} }
struct altcp_pcb *
altcp_tcp_wrap(struct tcp_pcb *tpcb)
{
if (tpcb != NULL) {
struct altcp_pcb *ret = altcp_alloc();
if (ret != NULL) {
altcp_tcp_setup(ret, tpcb);
return ret;
}
}
return NULL;
}
/* "virtual" functions calling into tcp */ /* "virtual" functions calling into tcp */
static void static void
@ -283,14 +288,7 @@ altcp_tcp_close(struct altcp_pcb *conn)
} }
ALTCP_TCP_ASSERT_CONN(conn); ALTCP_TCP_ASSERT_CONN(conn);
pcb = (struct tcp_pcb *)conn->state; pcb = (struct tcp_pcb *)conn->state;
if (pcb) { return tcp_close(pcb);
altcp_tcp_remove_callbacks(conn, pcb);
err_t res = tcp_close(pcb);
if (res != ERR_OK) return res;
conn->state = NULL; /* unsafe to reference pcb after tcp_close(). */
return ERR_OK;
}
return ERR_CLSD;
} }
static err_t static err_t

View File

@ -53,15 +53,14 @@
extern "C" { extern "C" {
#endif #endif
/* setup a newly allocated altcp_pcb with existing tcp_pcb */
struct tcp_pcb;
void altcp_tcp_setup(struct altcp_pcb *conn, struct tcp_pcb *tpcb);
struct altcp_pcb *altcp_tcp_new_ip_type(u8_t ip_type); struct altcp_pcb *altcp_tcp_new_ip_type(u8_t ip_type);
#define altcp_tcp_new() altcp_tcp_new_ip_type(IPADDR_TYPE_V4) #define altcp_tcp_new() altcp_tcp_new_ip_type(IPADDR_TYPE_V4)
#define altcp_tcp_new_ip6() altcp_tcp_new_ip_type(IPADDR_TYPE_V6) #define altcp_tcp_new_ip6() altcp_tcp_new_ip_type(IPADDR_TYPE_V6)
struct tcp_pcb;
struct altcp_pcb *altcp_tcp_wrap(struct tcp_pcb *tpcb);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif