From 4d21d8da23d32d8d3475d08a89cc50a7946fd721 Mon Sep 17 00:00:00 2001 From: Our Air Quality Date: Sun, 8 Oct 2017 14:26:34 +1100 Subject: [PATCH] Allow LWIP_SOCKET_OFFSET with an external FD_SET Signed-off-by: goldsimon --- src/api/sockets.c | 2 +- src/include/lwip/sockets.h | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/api/sockets.c b/src/api/sockets.c index a137bab8..c342ce09 100644 --- a/src/api/sockets.c +++ b/src/api/sockets.c @@ -1910,7 +1910,7 @@ lwip_select(int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptset, timeout ? (s32_t)timeout->tv_sec : (s32_t) - 1, timeout ? (s32_t)timeout->tv_usec : (s32_t) - 1)); - if ((maxfdp1 < 0) || (maxfdp1 > (FD_SETSIZE + LWIP_SOCKET_OFFSET))) { + if ((maxfdp1 < 0) || (maxfdp1 > LWIP_SELECT_MAXNFDS)) { set_errno(EINVAL); return -1; } diff --git a/src/include/lwip/sockets.h b/src/include/lwip/sockets.h index 46f03368..08de9455 100644 --- a/src/include/lwip/sockets.h +++ b/src/include/lwip/sockets.h @@ -465,6 +465,7 @@ typedef struct ipv6_mreq { #undef FD_SETSIZE /* Make FD_SETSIZE match NUM_SOCKETS in socket.c */ #define FD_SETSIZE MEMP_NUM_NETCONN +#define LWIP_SELECT_MAXNFDS (FD_SETSIZE + LWIP_SOCKET_OFFSET) #define FDSETSAFESET(n, code) do { \ if (((n) - LWIP_SOCKET_OFFSET < MEMP_NUM_NETCONN) && (((int)(n) - LWIP_SOCKET_OFFSET) >= 0)) { \ code; }} while(0) @@ -480,10 +481,10 @@ typedef struct fd_set unsigned char fd_bits [(FD_SETSIZE+7)/8]; } fd_set; -#elif LWIP_SOCKET_OFFSET -#error LWIP_SOCKET_OFFSET does not work with external FD_SET! -#elif FD_SETSIZE < MEMP_NUM_NETCONN +#elif FD_SETSIZE < (LWIP_SOCKET_OFFSET + MEMP_NUM_NETCONN) #error "external FD_SETSIZE too small for number of sockets" +#else +#define LWIP_SELECT_MAXNFDS FD_SETSIZE #endif /* FD_SET */ /* poll-related defines and types */