mirror of
https://github.com/wolfSSL/wolfssl.git
synced 2025-08-01 03:34:39 +02:00
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;
|
||||
}
|
||||
|
||||
#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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user