diff --git a/CHANGELOG b/CHANGELOG index d7f0b5ff..78e42f6d 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -19,6 +19,11 @@ HISTORY ++ New features: + 2008-01-10 Frédéric Bernon + * tcpip.h, tcpip.c: add tcpip_callback_with_block function for the task #7490 + "Add return value to sys_mbox_post". tcpip_callback is always defined as + "blocking" ("block" parameter = 1). + 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 diff --git a/src/api/tcpip.c b/src/api/tcpip.c index 4160a9b7..c7a3ca1f 100644 --- a/src/api/tcpip.c +++ b/src/api/tcpip.c @@ -349,10 +349,11 @@ tcpip_input(struct pbuf *p, struct netif *inp) * * @param f the function to call * @param ctx parameter passed to f + * @param block 1 to block until the request is posted, 0 to non-blocking mode * @return ERR_OK if the function was called, another err_t if not */ err_t -tcpip_callback(void (*f)(void *ctx), void *ctx) +tcpip_callback_with_block(void (*f)(void *ctx), void *ctx, u8_t block) { struct tcpip_msg *msg; @@ -365,7 +366,14 @@ tcpip_callback(void (*f)(void *ctx), void *ctx) msg->type = TCPIP_MSG_CALLBACK; msg->msg.cb.f = f; msg->msg.cb.ctx = ctx; - sys_mbox_post(mbox, msg); + if (block) { + sys_mbox_post(mbox, msg); + } else { + if (sys_mbox_trypost(mbox, msg) != ERR_OK) { + memp_free(MEMP_TCPIP_MSG_API, msg); + return ERR_MEM; + } + } return ERR_OK; } return ERR_VAL; diff --git a/src/include/lwip/tcpip.h b/src/include/lwip/tcpip.h index ee9ce3c4..fb2dbdeb 100644 --- a/src/include/lwip/tcpip.h +++ b/src/include/lwip/tcpip.h @@ -82,7 +82,9 @@ err_t tcpip_netifapi_lock(struct netifapi_msg *netifapimsg); #endif /* LWIP_TCPIP_CORE_LOCKING */ #endif /* LWIP_NETIF_API */ -err_t tcpip_callback(void (*f)(void *ctx), void *ctx); +err_t tcpip_callback_with_block(void (*f)(void *ctx), void *ctx, u8_t block); +#define tcpip_callback(f,ctx) tcpip_callback_with_block(f,ctx,1) + err_t tcpip_timeout(u32_t msecs, sys_timeout_handler h, void *arg); #define tcpip_untimeout(h, arg) tcpip_timeout(0xffffffff, h, arg)