forked from wolfSSL/wolfssl
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:
26
src/wolfio.c
26
src/wolfio.c
@@ -676,21 +676,22 @@ int wolfIO_Send(SOCKET_T sd, char *buf, int sz, int wrFlags)
|
|||||||
return ret;
|
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)
|
int wolfIO_Select(SOCKET_T sockfd, int to_sec)
|
||||||
{
|
{
|
||||||
fd_set fds;
|
fd_set rfds, wfds;
|
||||||
SOCKET_T nfds = sockfd + 1;
|
int nfds = 0;
|
||||||
struct timeval timeout = { (to_sec > 0) ? to_sec : 0, 0};
|
struct timeval timeout = { (to_sec > 0) ? to_sec : 0, 0};
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
FD_ZERO(&fds);
|
#ifndef USE_WINDOWS_API
|
||||||
FD_SET(sockfd, &fds);
|
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) {
|
if (ret == 0) {
|
||||||
#ifdef DEBUG_HTTP
|
#ifdef DEBUG_HTTP
|
||||||
printf("Timeout: %d\n", ret);
|
printf("Timeout: %d\n", ret);
|
||||||
@@ -698,8 +699,11 @@ int wolfIO_Send(SOCKET_T sd, char *buf, int sz, int wrFlags)
|
|||||||
return HTTP_TIMEOUT;
|
return HTTP_TIMEOUT;
|
||||||
}
|
}
|
||||||
else if (ret > 0) {
|
else if (ret > 0) {
|
||||||
if (FD_ISSET(sockfd, &fds))
|
if (FD_ISSET(sockfd, &wfds)) {
|
||||||
return 0;
|
if (!FD_ISSET(sockfd, &rfds)) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return SOCKET_ERROR_E;
|
return SOCKET_ERROR_E;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user