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,14 +291,12 @@ altcp_mbedtls_lower_recv_process(struct altcp_pcb *conn, altcp_mbedtls_state_t *
if (conn->connected) {
conn->connected(conn->arg, conn, ERR_OK);
}
if (state->rx)
goto pbuf_left;
return ERR_OK;
} else {
/* handle application data */
pbuf_left:
return altcp_mbedtls_handle_rx_appldata(conn, state);
if (state->rx == NULL) {
return ERR_OK;
}
}
/* handle application data */
return altcp_mbedtls_handle_rx_appldata(conn, state);
}
/* Pass queued decoded rx data to application */
@ -610,11 +608,11 @@ altcp_tls_new(struct altcp_tls_config* config, struct altcp_pcb *inner_pcb)
}
void *
altcp_tls_context (struct altcp_pcb *conn)
altcp_tls_context(struct altcp_pcb *conn)
{
if (conn && conn->state) {
altcp_mbedtls_state_t *state = conn->state;
return &state->ssl_context;
altcp_mbedtls_state_t *state = (altcp_mbedtls_state_t *)conn->state;
return &state->ssl_context;
}
return NULL;
}
@ -771,10 +769,9 @@ altcp_tls_create_config_client(const u8_t *cert, size_t cert_len)
void
altcp_tls_free_config(struct altcp_tls_config *conf)
{
altcp_mbedtls_free_config (conf);
altcp_mbedtls_free_config(conf);
}
/* "virtual" functions */
static void
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 */
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 */
static err_t
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 */
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
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 :-) */
}
void
static void
altcp_tcp_setup(struct altcp_pcb *conn, struct tcp_pcb *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 *
altcp_tcp_new_ip_type(u8_t ip_type)
{
/* FIXME: pool alloc */
struct altcp_pcb *ret = altcp_alloc();
if (ret != NULL) {
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;
}
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 */
static void
@ -269,7 +274,7 @@ altcp_tcp_abort(struct altcp_pcb *conn)
struct tcp_pcb *pcb = (struct tcp_pcb *)conn->state;
ALTCP_TCP_ASSERT_CONN(conn);
if (pcb) {
tcp_abort(pcb);
tcp_abort(pcb);
}
}
}
@ -283,14 +288,7 @@ altcp_tcp_close(struct altcp_pcb *conn)
}
ALTCP_TCP_ASSERT_CONN(conn);
pcb = (struct tcp_pcb *)conn->state;
if (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;
return tcp_close(pcb);
}
static err_t

View File

@ -53,15 +53,14 @@
extern "C" {
#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);
#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)
struct tcp_pcb;
struct altcp_pcb *altcp_tcp_wrap(struct tcp_pcb *tpcb);
#ifdef __cplusplus
}
#endif