diff --git a/src/api/api_lib.c b/src/api/api_lib.c index 02d284b1..fd2c9f2a 100644 --- a/src/api/api_lib.c +++ b/src/api/api_lib.c @@ -467,6 +467,7 @@ netconn_recv(struct netconn *conn) struct api_msg *msg; struct netbuf *buf; struct pbuf *p; + u16_t len; if(conn == NULL) { return NULL; @@ -497,12 +498,17 @@ netconn_recv(struct netconn *conn) sys_mbox_fetch(conn->recvmbox, (void **)&p); - if (p != NULL) { - conn->recv_avail -= p->tot_len; - /* Register event with callback */ - if (conn->callback) - (*conn->callback)(conn, NETCONN_EVT_RCVMINUS, p->tot_len); + if (p != NULL) + { + len = p->tot_len; + conn->recv_avail -= len; } + else + len = 0; + + /* Register event with callback */ + if (conn->callback) + (*conn->callback)(conn, NETCONN_EVT_RCVMINUS, len); /* If we are closed, we indicate that we no longer wish to recieve data by setting conn->recvmbox to SYS_MBOX_NULL. */ diff --git a/src/api/api_msg.c b/src/api/api_msg.c index c3b84375..c9924212 100644 --- a/src/api/api_msg.c +++ b/src/api/api_msg.c @@ -42,7 +42,8 @@ static err_t recv_tcp(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err) { struct netconn *conn; - + u16_t len; + conn = arg; if(conn == NULL) { @@ -54,11 +55,14 @@ recv_tcp(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err) conn->err = err; if (p != NULL) { - conn->recv_avail += p->tot_len; - /* Register event with callback */ - if (conn->callback) - (*conn->callback)(conn, NETCONN_EVT_RCVPLUS, p->tot_len); - } + len = p->tot_len; + conn->recv_avail += len; + } + else + len = 0; + /* Register event with callback */ + if (conn->callback) + (*conn->callback)(conn, NETCONN_EVT_RCVPLUS, len); sys_mbox_post(conn->recvmbox, p); } return ERR_OK; diff --git a/src/include/lwip/sys.h b/src/include/lwip/sys.h index 46669868..0aeac0fc 100644 --- a/src/include/lwip/sys.h +++ b/src/include/lwip/sys.h @@ -114,7 +114,7 @@ u32_t sys_arch_protect(void); void sys_arch_unprotect(u32_t pval); /* Thread functions. */ -void sys_thread_new(void (* thread)(void *arg), void *arg); +sys_thread_t sys_thread_new(void (* thread)(void *arg), void *arg); /* The following functions are used only in Unix code, and can be omitted when porting the stack. */