diff --git a/CHANGELOG b/CHANGELOG index 3273d99d..f0d35c52 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -23,6 +23,10 @@ HISTORY ++ New features: + 2007-04-11 Jonathan Larmour + * sys.h, api_lib.c: Provide new sys_mbox_tryfetch function. Require ports to provide new + sys_arch_mbox_tryfetch function to get a message if one is there. + 2007-04-06 Frédéric Bernon, Simon Goldschmidt * opt.h, tcpip.h, tcpip.c, netifapi.h, netifapi.c: New configuration option LWIP_NETIF_API allow to use thread-safe functions to add/remove netif in list, and to start/stop dhcp diff --git a/src/api/api_lib.c b/src/api/api_lib.c index dc4c2207..de47f92f 100644 --- a/src/api/api_lib.c +++ b/src/api/api_lib.c @@ -284,7 +284,7 @@ netconn_delete(struct netconn *conn) /* Drain the recvmbox. */ if (conn->recvmbox != SYS_MBOX_NULL) { - while (sys_arch_mbox_fetch(conn->recvmbox, &mem, 1) != SYS_ARCH_TIMEOUT) { + while (sys_mbox_tryfetch(conn->recvmbox, &mem) != SYS_MBOX_EMPTY) { if (conn->type == NETCONN_TCP) { if(mem != NULL) pbuf_free((struct pbuf *)mem); @@ -299,7 +299,7 @@ netconn_delete(struct netconn *conn) /* Drain the acceptmbox. */ if (conn->acceptmbox != SYS_MBOX_NULL) { - while (sys_arch_mbox_fetch(conn->acceptmbox, &mem, 1) != SYS_ARCH_TIMEOUT) { + while (sys_mbox_tryfetch(conn->acceptmbox, &mem) != SYS_MBOX_EMPTY) { netconn_delete((struct netconn *)mem); } sys_mbox_free(conn->acceptmbox); diff --git a/src/include/lwip/sys.h b/src/include/lwip/sys.h index d631ad1b..50613c62 100644 --- a/src/include/lwip/sys.h +++ b/src/include/lwip/sys.h @@ -67,6 +67,11 @@ struct sys_timeo {u8_t dummy;}; /** Return code for timeouts from sys_arch_mbox_fetch and sys_arch_sem_wait */ #define SYS_ARCH_TIMEOUT 0xffffffffUL +/* sys_mbox_tryfetch returns SYS_MBOX_EMPTY if appropriate. + * For now we use the same magic value, but we allow this to change in future. + */ +#define SYS_MBOX_EMPTY SYS_ARCH_TIMEOUT + typedef void (* sys_timeout_handler)(void *arg); struct sys_timeo { @@ -116,6 +121,11 @@ u32_t sys_jiffies(void); /* since power up. */ sys_mbox_t sys_mbox_new(void); void sys_mbox_post(sys_mbox_t mbox, void *msg); u32_t sys_arch_mbox_fetch(sys_mbox_t mbox, void **msg, u32_t timeout); +#ifndef sys_arch_mbox_tryfetch /* Allow port to override with a macro */ +u32_t sys_arch_mbox_tryfetch(sys_mbox_t mbox, void **msg); +#endif +/* For now, we map straight to sys_arch implementation. */ +#define sys_mbox_tryfetch(mbox, msg) sys_arch_mbox_tryfetch(mbox, msg) void sys_mbox_free(sys_mbox_t mbox); #if LWIP_SO_RCVTIMEO void sys_mbox_fetch_timeout(sys_mbox_t mbox, void **msg, u32_t timeout);