tcpip.h, tcpip.c, api.h, api_lib.c, api_msg.c, sockets.c: replace the field netconn::mbox (sys_mbox_t) per netconn::sem (sys_sem_t) for the task #7490 "Add return value to sys_mbox_post".

This commit is contained in:
fbernon 2008-01-10 21:34:25 +00:00
parent b333b7c9dc
commit bceff76c70
7 changed files with 34 additions and 30 deletions

View File

@ -19,6 +19,11 @@ HISTORY
++ New features:
2008-01-10 Frédéric Bernon
* tcpip.h, tcpip.c, api.h, api_lib.c, api_msg.c, sockets.c: replace the field
netconn::mbox (sys_mbox_t) per netconn::sem (sys_sem_t) for the task #7490
"Add return value to sys_mbox_post".
2008-01-05 Frédéric Bernon
* 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
@ -566,11 +571,11 @@ HISTORY
2008-01-09 Jonathan Larmour
* opt.h, ip.c: Rename IP_OPTIONS define to IP_OPTIONS_ALLOWED to avoid
conflict with Linux system headers.
conflict with Linux system headers.
2008-01-06 Jonathan Larmour
* dhcp.c: fix bug #19927: "DHCP NACK problem" by clearing any existing set IP
address entirely on receiving a DHCPNAK, and restarting discovery.
address entirely on receiving a DHCPNAK, and restarting discovery.
2007-12-21 Simon Goldschmidt
* sys.h, api_lib.c, api_msg.c, sockets.c: fix bug #21698: "netconn->recv_avail

View File

@ -79,10 +79,10 @@ netconn_new_with_proto_and_callback(enum netconn_type t, u8_t proto, netconn_cal
if (conn->err != ERR_OK) {
LWIP_ASSERT("freeing conn without freeing pcb", conn->pcb.tcp == NULL);
LWIP_ASSERT("conn has no mbox", conn->mbox != SYS_MBOX_NULL);
LWIP_ASSERT("conn has no sem", conn->sem != SYS_SEM_NULL);
LWIP_ASSERT("conn has no recvmbox", conn->recvmbox != SYS_MBOX_NULL);
LWIP_ASSERT("conn->acceptmbox shouldn't exist", conn->acceptmbox == SYS_MBOX_NULL);
sys_mbox_free(conn->mbox);
sys_sem_free(conn->sem);
sys_mbox_free(conn->recvmbox);
memp_free(MEMP_NETCONN, conn);
return NULL;

View File

@ -282,9 +282,9 @@ err_tcp(void *arg, err_t err)
API_EVENT(conn, NETCONN_EVT_RCVPLUS, 0);
sys_mbox_post(conn->recvmbox, NULL);
}
if (conn->mbox != SYS_MBOX_NULL && conn->state == NETCONN_CONNECT) {
if (conn->sem != SYS_SEM_NULL && conn->state == NETCONN_CONNECT) {
conn->state = NETCONN_NONE;
sys_mbox_post(conn->mbox, NULL);
sys_sem_signal(conn->sem);
}
if (conn->acceptmbox != SYS_MBOX_NULL) {
/* Register event with callback */
@ -296,7 +296,7 @@ err_tcp(void *arg, err_t err)
since the pcb has already been deleted! */
conn->state = NETCONN_NONE;
/* wake up the waiting task */
sys_mbox_post(conn->mbox, NULL);
sys_sem_signal(conn->sem);
}
}
@ -470,12 +470,12 @@ netconn_alloc(enum netconn_type t, netconn_callback callback)
conn->type = t;
conn->pcb.tcp = NULL;
if ((conn->mbox = sys_mbox_new(1)) == SYS_MBOX_NULL) {
if ((conn->sem = sys_sem_new(0)) == SYS_SEM_NULL) {
memp_free(MEMP_NETCONN, conn);
return NULL;
}
if ((conn->recvmbox = sys_mbox_new(DEFAULT_RECVMBOX_SIZE)) == SYS_MBOX_NULL) {
sys_mbox_free(conn->mbox);
sys_sem_free(conn->sem);
memp_free(MEMP_NETCONN, conn);
return NULL;
}
@ -530,8 +530,8 @@ netconn_free(struct netconn *conn)
conn->acceptmbox = SYS_MBOX_NULL;
}
sys_mbox_free(conn->mbox);
conn->mbox = SYS_MBOX_NULL;
sys_sem_free(conn->sem);
conn->sem = SYS_SEM_NULL;
memp_free(MEMP_NETCONN, conn);
}
@ -579,7 +579,7 @@ do_close_internal(struct netconn *conn)
API_EVENT(conn, NETCONN_EVT_RCVPLUS, 0);
API_EVENT(conn, NETCONN_EVT_SENDPLUS, 0);
/* wake up the application task */
sys_mbox_post(conn->mbox, NULL);
sys_sem_signal(conn->sem);
}
/* If closing didn't succeed, we get called again either
from poll_tcp or from sent_tcp */
@ -627,8 +627,8 @@ do_delconn(struct api_msg_msg *msg)
API_EVENT(msg->conn, NETCONN_EVT_RCVPLUS, 0);
API_EVENT(msg->conn, NETCONN_EVT_SENDPLUS, 0);
if (msg->conn->mbox != SYS_MBOX_NULL) {
sys_mbox_post(msg->conn->mbox, NULL);
if (msg->conn->sem != SYS_SEM_NULL) {
sys_sem_signal(msg->conn->sem);
}
}
@ -696,7 +696,7 @@ do_connected(void *arg, struct tcp_pcb *pcb, err_t err)
setup_tcp(conn);
}
conn->state = NETCONN_NONE;
sys_mbox_post(conn->mbox, NULL);
sys_sem_signal(conn->sem);
return ERR_OK;
}
#endif /* LWIP_TCP */
@ -712,7 +712,7 @@ void
do_connect(struct api_msg_msg *msg)
{
if (msg->conn->pcb.tcp == NULL) {
sys_mbox_post(msg->conn->mbox, NULL);
sys_sem_signal(msg->conn->sem);
return;
}
@ -720,13 +720,13 @@ do_connect(struct api_msg_msg *msg)
#if LWIP_RAW
case NETCONN_RAW:
msg->conn->err = raw_connect(msg->conn->pcb.raw, msg->msg.bc.ipaddr);
sys_mbox_post(msg->conn->mbox, NULL);
sys_sem_signal(msg->conn->sem);
break;
#endif /* LWIP_RAW */
#if LWIP_UDP
case NETCONN_UDP:
msg->conn->err = udp_connect(msg->conn->pcb.udp, msg->msg.bc.ipaddr, msg->msg.bc.port);
sys_mbox_post(msg->conn->mbox, NULL);
sys_sem_signal(msg->conn->sem);
break;
#endif /* LWIP_UDP */
#if LWIP_TCP
@ -735,7 +735,7 @@ do_connect(struct api_msg_msg *msg)
setup_tcp(msg->conn);
msg->conn->err = tcp_connect(msg->conn->pcb.tcp, msg->msg.bc.ipaddr, msg->msg.bc.port,
do_connected);
/* sys_mbox_post() is called from do_connected (or err_tcp()),
/* sys_sem_signal() is called from do_connected (or err_tcp()),
* when the connection is established! */
break;
#endif /* LWIP_TCP */
@ -955,7 +955,7 @@ do_writemore(struct netconn *conn)
if (conn->write_delayed != 0)
#endif
{
sys_mbox_post(conn->mbox, NULL);
sys_sem_signal(conn->sem);
}
}
#if LWIP_TCPIP_CORE_LOCKING
@ -987,7 +987,7 @@ do_write(struct api_msg_msg *msg)
if (do_writemore(msg->conn) != ERR_OK) {
LWIP_ASSERT("state!", msg->conn->state == NETCONN_WRITE);
UNLOCK_TCPIP_CORE();
sys_arch_mbox_fetch(msg->conn->mbox, NULL, 0);
sys_arch_sem_wait(msg->conn->sem, 0);
LOCK_TCPIP_CORE();
LWIP_ASSERT("state!", msg->conn->state == NETCONN_NONE);
}

View File

@ -1301,7 +1301,7 @@ lwip_getsockopt(int s, int level, int optname, void *optval, socklen_t *optlen)
data.optlen = optlen;
data.err = err;
tcpip_callback(lwip_getsockopt_internal, &data);
sys_arch_mbox_fetch(sock->conn->mbox, NULL, 0);
sys_arch_sem_wait(sock->conn->sem, 0);
/* maybe lwip_getsockopt_internal has changed err */
err = data.err;
@ -1485,7 +1485,7 @@ lwip_getsockopt_internal(void *arg)
break;
#endif /* LWIP_UDP */
} /* switch (level) */
sys_mbox_post(sock->conn->mbox, NULL);
sys_sem_signal(sock->conn->sem);
}
int
@ -1675,7 +1675,7 @@ lwip_setsockopt(int s, int level, int optname, const void *optval, socklen_t opt
data.optlen = &optlen;
data.err = err;
tcpip_callback(lwip_setsockopt_internal, &data);
sys_arch_mbox_fetch(sock->conn->mbox, NULL, 0);
sys_arch_sem_wait(sock->conn->sem, 0);
/* maybe lwip_setsockopt_internal has changed err */
err = data.err;
@ -1859,7 +1859,7 @@ lwip_setsockopt_internal(void *arg)
break;
#endif /* LWIP_UDP */
} /* switch (level) */
sys_mbox_post(sock->conn->mbox, NULL);
sys_sem_signal(sock->conn->sem);
}
int

View File

@ -410,7 +410,7 @@ tcpip_apimsg(struct api_msg *apimsg)
msg.type = TCPIP_MSG_API;
msg.msg.apimsg = apimsg;
sys_mbox_post(mbox, &msg);
sys_arch_mbox_fetch(apimsg->msg.conn->mbox, NULL, 0);
sys_arch_sem_wait(apimsg->msg.conn->sem, 0);
return ERR_OK;
}
return ERR_VAL;

View File

@ -118,9 +118,8 @@ struct netconn {
} pcb;
/** the last error this netconn had */
err_t err;
/** mbox that is used mutex-like to synchroneously execute functions
in the core context */
sys_mbox_t mbox;
/** sem that is used to synchroneously execute functions in the core context */
sys_sem_t sem;
/** mbox where received packets are stored until they are fetched
by the netconn application thread (can grow quite big) */
sys_mbox_t recvmbox;

View File

@ -59,7 +59,7 @@ extern sys_sem_t lock_tcpip_core;
#define LOCK_TCPIP_CORE()
#define UNLOCK_TCPIP_CORE()
#define TCPIP_APIMSG(m) tcpip_apimsg(m)
#define TCPIP_APIMSG_ACK(m) sys_mbox_post(m->conn->mbox, NULL)
#define TCPIP_APIMSG_ACK(m) sys_sem_signal(m->conn->sem)
#define TCPIP_NETIFAPI(m) tcpip_netifapi(m)
#define TCPIP_NETIFAPI_ACK(m) sys_sem_signal(m->sem)
#endif /* LWIP_TCPIP_CORE_LOCKING */