From 9d7bcf8ec7c74fdccfe187c4fa4cbcb8e2684320 Mon Sep 17 00:00:00 2001 From: John Safranek Date: Mon, 18 Jun 2018 15:17:16 -0700 Subject: [PATCH] wolfIO Select Update 1. In wolfIO_Select(), separate out the fd lists into separate read and write lists. 2. Check the read and write fds lists to see if the connect() succeeded or failed. 3. Windows doesn't use the nfds parameter to Select. Initialize it to zero and reset it to the right value when building for not-Windows. 4. Remove the warning disable for Windows. GCC 8.1 checks that "restrict" pointer parameters don't point to the same thing and will error if they do. --- src/wolfio.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/src/wolfio.c b/src/wolfio.c index d99280236..74aa9a566 100644 --- a/src/wolfio.c +++ b/src/wolfio.c @@ -676,21 +676,22 @@ int wolfIO_Send(SOCKET_T sd, char *buf, int sz, int wrFlags) return ret; } - #ifdef _MSC_VER - /* 4204: non-constant aggregate initializer (nfds = sockfd + 1) */ - #pragma warning(disable: 4204) - #endif int wolfIO_Select(SOCKET_T sockfd, int to_sec) { - fd_set fds; - SOCKET_T nfds = sockfd + 1; + fd_set rfds, wfds; + int nfds = 0; struct timeval timeout = { (to_sec > 0) ? to_sec : 0, 0}; int ret; - FD_ZERO(&fds); - FD_SET(sockfd, &fds); + #ifndef USE_WINDOWS_API + nfds = (int)sockfd + 1; + #endif - ret = select(nfds, &fds, &fds, NULL, &timeout); + FD_ZERO(&rfds); + FD_SET(sockfd, &rfds); + wfds = rfds; + + ret = select(nfds, &rfds, &wfds, NULL, &timeout); if (ret == 0) { #ifdef DEBUG_HTTP printf("Timeout: %d\n", ret); @@ -698,8 +699,11 @@ int wolfIO_Send(SOCKET_T sd, char *buf, int sz, int wrFlags) return HTTP_TIMEOUT; } else if (ret > 0) { - if (FD_ISSET(sockfd, &fds)) - return 0; + if (FD_ISSET(sockfd, &wfds)) { + if (!FD_ISSET(sockfd, &rfds)) { + return 0; + } + } } return SOCKET_ERROR_E; }