aboutsummaryrefslogtreecommitdiff
path: root/tests/server/sockfilt.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/server/sockfilt.c')
-rw-r--r--tests/server/sockfilt.c31
1 files changed, 21 insertions, 10 deletions
diff --git a/tests/server/sockfilt.c b/tests/server/sockfilt.c
index f5281817d..ccd9c4782 100644
--- a/tests/server/sockfilt.c
+++ b/tests/server/sockfilt.c
@@ -5,11 +5,11 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2021, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
- * are also available at https://curl.haxx.se/docs/copyright.html.
+ * are also available at https://curl.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
@@ -668,7 +668,7 @@ static int select_ws(int nfds, fd_set *readfds, fd_set *writefds,
/* allocate internal array for the internal data */
data = calloc(nfds, sizeof(struct select_ws_data));
- if(data == NULL) {
+ if(!data) {
CloseHandle(abort);
CloseHandle(mutex);
errno = ENOMEM;
@@ -677,7 +677,7 @@ static int select_ws(int nfds, fd_set *readfds, fd_set *writefds,
/* allocate internal array for the internal event handles */
handles = calloc(nfds + 1, sizeof(HANDLE));
- if(handles == NULL) {
+ if(!handles) {
CloseHandle(abort);
CloseHandle(mutex);
free(data);
@@ -725,6 +725,7 @@ static int select_ws(int nfds, fd_set *readfds, fd_set *writefds,
handles[nfd] = signal;
data[nth].signal = signal;
data[nth].thread = handle;
+ nfd++;
nth++;
}
else {
@@ -734,13 +735,18 @@ static int select_ws(int nfds, fd_set *readfds, fd_set *writefds,
}
else if(fd == fileno(stdout)) {
handles[nfd] = GetStdHandle(STD_OUTPUT_HANDLE);
+ nfd++;
}
else if(fd == fileno(stderr)) {
handles[nfd] = GetStdHandle(STD_ERROR_HANDLE);
+ nfd++;
}
else {
wsaevent = WSACreateEvent();
if(wsaevent != WSA_INVALID_EVENT) {
+ if(wsaevents.lNetworkEvents & FD_WRITE) {
+ send(wsasock, NULL, 0, 0); /* reset FD_WRITE */
+ }
error = WSAEventSelect(wsasock, wsaevent, wsaevents.lNetworkEvents);
if(error != SOCKET_ERROR) {
handles[nfd] = (HANDLE)wsaevent;
@@ -760,6 +766,7 @@ static int select_ws(int nfds, fd_set *readfds, fd_set *writefds,
if(FD_ISSET(wsasock, &exceptsock))
data[nfd].wsastate |= FD_OOB;
}
+ nfd++;
nws++;
}
else {
@@ -772,6 +779,7 @@ static int select_ws(int nfds, fd_set *readfds, fd_set *writefds,
handles[nfd] = signal;
data[nth].signal = signal;
data[nth].thread = handle;
+ nfd++;
nth++;
}
else {
@@ -781,7 +789,6 @@ static int select_ws(int nfds, fd_set *readfds, fd_set *writefds,
}
}
}
- nfd++;
}
}
@@ -1313,8 +1320,9 @@ int main(int argc, char *argv[])
curl_socket_t sock = CURL_SOCKET_BAD;
curl_socket_t msgsock = CURL_SOCKET_BAD;
int wrotepidfile = 0;
+ int wroteportfile = 0;
const char *pidname = ".sockfilt.pid";
- const char *portfile = NULL; /* none by default */
+ const char *portname = NULL; /* none by default */
bool juggle_again;
int rc;
int error;
@@ -1345,7 +1353,7 @@ int main(int argc, char *argv[])
else if(!strcmp("--portfile", argv[arg])) {
arg++;
if(argc > arg)
- portfile = argv[arg++];
+ portname = argv[arg++];
}
else if(!strcmp("--logfile", argv[arg])) {
arg++;
@@ -1411,6 +1419,7 @@ int main(int argc, char *argv[])
" --verbose\n"
" --logfile [file]\n"
" --pidfile [file]\n"
+ " --portfile [file]\n"
" --ipv4\n"
" --ipv6\n"
" --bindonly\n"
@@ -1511,9 +1520,9 @@ int main(int argc, char *argv[])
write_stdout("FAIL\n", 5);
goto sockfilt_cleanup;
}
- if(portfile) {
- wrotepidfile = write_portfile(portfile, port);
- if(!wrotepidfile) {
+ if(portname) {
+ wroteportfile = write_portfile(portname, port);
+ if(!wroteportfile) {
write_stdout("FAIL\n", 5);
goto sockfilt_cleanup;
}
@@ -1533,6 +1542,8 @@ sockfilt_cleanup:
if(wrotepidfile)
unlink(pidname);
+ if(wroteportfile)
+ unlink(portname);
restore_signal_handlers(false);