From a3fdc33f88dc2837d9719b38cf16a2ec6ebd230d Mon Sep 17 00:00:00 2001 From: fbernon Date: Wed, 23 May 2007 19:18:09 +0000 Subject: [PATCH] api_lib.c: Implement SO_RCVTIMEO for accept and recv on TCP connections, such present in patch #5959. --- CHANGELOG | 4 ++++ src/api/api_lib.c | 18 +++++++++++++++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 4bc354af..d029267c 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -19,6 +19,10 @@ HISTORY ++ New features: + 2007-05-23 Frédéric Bernon + * api_lib.c, sockets.c: Implement SO_RCVTIMEO for accept and recv on TCP + connections, such present in patch #5959. + 2007-05-23 Frédéric Bernon * api.h, api_lib.c, api_msg.c, sockets.c: group the different NETCONN_UDPxxx code in only one part... diff --git a/src/api/api_lib.c b/src/api/api_lib.c index fb8eb2b0..5b802744 100644 --- a/src/api/api_lib.c +++ b/src/api/api_lib.c @@ -352,8 +352,7 @@ netconn_bind(struct netconn *conn, struct ip_addr *addr, u16_t port) LWIP_ASSERT("netconn_bind: invalid conn", (conn != NULL)); - if (conn->type != NETCONN_TCP && - conn->recvmbox == SYS_MBOX_NULL) { + if (conn->type != NETCONN_TCP && conn->recvmbox == SYS_MBOX_NULL) { if ((conn->recvmbox = sys_mbox_new()) == SYS_MBOX_NULL) { return ERR_MEM; } @@ -424,10 +423,17 @@ netconn_accept(struct netconn *conn) LWIP_ASSERT("netconn_accept: invalid conn", (conn != NULL)); LWIP_ASSERT("netconn_accept: invalid acceptmbox", (conn->acceptmbox != SYS_MBOX_NULL)); + #if LWIP_SO_RCVTIMEO + if (sys_arch_mbox_fetch(conn->acceptmbox, (void *)&newconn, conn->recv_timeout)==SYS_ARCH_TIMEOUT) { + newconn = NULL; + } + #else sys_arch_mbox_fetch(conn->acceptmbox, (void *)&newconn, 0); + #endif /* LWIP_SO_RCVTIMEO*/ + /* Register event with callback */ if (conn->callback) - (*conn->callback)(conn, NETCONN_EVT_RCVMINUS, 0); + (*conn->callback)(conn, NETCONN_EVT_RCVMINUS, 0); return newconn; } @@ -467,7 +473,13 @@ netconn_recv(struct netconn *conn) return NULL; } +#if LWIP_SO_RCVTIMEO + if (sys_arch_mbox_fetch(conn->recvmbox, (void *)&p, conn->recv_timeout)==SYS_ARCH_TIMEOUT) { + p = NULL; + } +#else sys_arch_mbox_fetch(conn->recvmbox, (void *)&p, 0); +#endif /* LWIP_SO_RCVTIMEO*/ if (p != NULL) { len = p->tot_len;