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.
This commit is contained in:
John Safranek
2018-06-18 15:17:16 -07:00
parent 1179969dcf
commit 9d7bcf8ec7

View File

@@ -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;
}