mirror of
https://git.savannah.nongnu.org/git/lwip.git
synced 2026-05-17 13:46:56 +08:00
sys_arch.txt, api.h, api_lib.c, api_msg.h, api_msg.c, tcpip.c, sys.h, opt.h: Introduce changes for task #7490 "Add return value to sys_mbox_post" with some modifications in the sys_mbox api: sys_mbox_new take a "size" parameters which indicate the number of pointers query by the mailbox. There is three defines in opt.h to indicate sizes for tcpip::mbox, netconn::recvmbox, and for the netconn::acceptmbox. Port maintainers, you can decide to just add this new parameter in your implementation, but to ignore it to keep the previous behavior. The new sys_mbox_trypost function return a value to know if the mailbox is full or if the message is posted. Take a look to sys_arch.txt for more details. This new function is used in tcpip_input (so, can be called in an interrupt context since the function is not blocking), and in recv_udp and recv_raw.
This commit is contained in:
@@ -65,8 +65,7 @@
|
||||
* NULL on memory error
|
||||
*/
|
||||
struct netconn*
|
||||
netconn_new_with_proto_and_callback(enum netconn_type t, u8_t proto,
|
||||
void (*callback)(struct netconn *, enum netconn_evt, u16_t len))
|
||||
netconn_new_with_proto_and_callback(enum netconn_type t, u8_t proto, netconn_callback callback)
|
||||
{
|
||||
struct netconn *conn;
|
||||
struct api_msg msg;
|
||||
|
||||
@@ -98,7 +98,9 @@ recv_raw(void *arg, struct raw_pcb *pcb, struct pbuf *p,
|
||||
SYS_ARCH_INC(conn->recv_avail, p->tot_len);
|
||||
/* Register event with callback */
|
||||
API_EVENT(conn, NETCONN_EVT_RCVPLUS, p->tot_len);
|
||||
sys_mbox_post(conn->recvmbox, buf);
|
||||
if (sys_mbox_trypost(conn->recvmbox, buf) != ERR_OK) {
|
||||
netbuf_delete(buf);
|
||||
}
|
||||
}
|
||||
|
||||
return 0; /* do not eat the packet */
|
||||
@@ -153,7 +155,10 @@ recv_udp(void *arg, struct udp_pcb *pcb, struct pbuf *p,
|
||||
SYS_ARCH_INC(conn->recv_avail, p->tot_len);
|
||||
/* Register event with callback */
|
||||
API_EVENT(conn, NETCONN_EVT_RCVPLUS, p->tot_len);
|
||||
sys_mbox_post(conn->recvmbox, buf);
|
||||
if (sys_mbox_trypost(conn->recvmbox, buf) != ERR_OK) {
|
||||
netbuf_delete(buf);
|
||||
return;
|
||||
}
|
||||
}
|
||||
#endif /* LWIP_UDP */
|
||||
|
||||
@@ -348,7 +353,11 @@ accept_function(void *arg, struct tcp_pcb *newpcb, err_t err)
|
||||
/* Register event with callback */
|
||||
API_EVENT(conn, NETCONN_EVT_RCVPLUS, 0);
|
||||
|
||||
sys_mbox_post(conn->acceptmbox, newconn);
|
||||
if (sys_mbox_trypost(conn->acceptmbox, newconn) != ERR_OK) {
|
||||
/** @todo call here a "netconn_free" */
|
||||
LWIP_ASSERT("accept_function: not yet implemented!", 0);
|
||||
return ERR_MEM;
|
||||
}
|
||||
return ERR_OK;
|
||||
}
|
||||
#endif /* LWIP_TCP */
|
||||
@@ -446,8 +455,7 @@ do_newconn(struct api_msg_msg *msg)
|
||||
* NULL on memory error
|
||||
*/
|
||||
struct netconn*
|
||||
netconn_alloc(enum netconn_type t,
|
||||
void (*callback)(struct netconn *, enum netconn_evt, u16_t len))
|
||||
netconn_alloc(enum netconn_type t, netconn_callback callback)
|
||||
{
|
||||
struct netconn *conn;
|
||||
|
||||
@@ -460,11 +468,11 @@ netconn_alloc(enum netconn_type t,
|
||||
conn->type = t;
|
||||
conn->pcb.tcp = NULL;
|
||||
|
||||
if ((conn->mbox = sys_mbox_new()) == SYS_MBOX_NULL) {
|
||||
if ((conn->mbox = sys_mbox_new(1)) == SYS_MBOX_NULL) {
|
||||
memp_free(MEMP_NETCONN, conn);
|
||||
return NULL;
|
||||
}
|
||||
if ((conn->recvmbox = sys_mbox_new()) == SYS_MBOX_NULL) {
|
||||
if ((conn->recvmbox = sys_mbox_new(DEFAULT_RECVMBOX_SIZE)) == SYS_MBOX_NULL) {
|
||||
sys_mbox_free(conn->mbox);
|
||||
memp_free(MEMP_NETCONN, conn);
|
||||
return NULL;
|
||||
@@ -732,7 +740,7 @@ do_listen(struct api_msg_msg *msg)
|
||||
msg->conn->recvmbox = NULL;
|
||||
}
|
||||
if (msg->conn->acceptmbox == SYS_MBOX_NULL) {
|
||||
if ((msg->conn->acceptmbox = sys_mbox_new()) == SYS_MBOX_NULL) {
|
||||
if ((msg->conn->acceptmbox = sys_mbox_new(DEFAULT_ACCEPTMBOX_SIZE)) == SYS_MBOX_NULL) {
|
||||
msg->conn->err = ERR_MEM;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -332,7 +332,10 @@ tcpip_input(struct pbuf *p, struct netif *inp)
|
||||
msg->type = TCPIP_MSG_INPKT;
|
||||
msg->msg.inp.p = p;
|
||||
msg->msg.inp.netif = inp;
|
||||
sys_mbox_post(mbox, msg);
|
||||
if (sys_mbox_trypost(mbox, msg) != ERR_OK) {
|
||||
memp_free(MEMP_TCPIP_MSG_INPKT, msg);
|
||||
return ERR_MEM;
|
||||
}
|
||||
return ERR_OK;
|
||||
}
|
||||
return ERR_VAL;
|
||||
@@ -499,7 +502,7 @@ tcpip_init(void (* initfunc)(void *), void *arg)
|
||||
|
||||
tcpip_init_done = initfunc;
|
||||
tcpip_init_done_arg = arg;
|
||||
mbox = sys_mbox_new();
|
||||
mbox = sys_mbox_new(TCPIP_MBOX_SIZE);
|
||||
#if LWIP_TCPIP_CORE_LOCKING
|
||||
lock_tcpip_core = sys_sem_new(1);
|
||||
#endif /* LWIP_TCPIP_CORE_LOCKING */
|
||||
|
||||
Reference in New Issue
Block a user