Check against EVUTIL_INVALID_SOCKET

This commit is contained in:
Cœur 2024-06-24 14:19:12 +08:00 committed by Azat Khuzhin
parent 3f799ab675
commit 5485887c47
5 changed files with 13 additions and 9 deletions

View File

@ -391,7 +391,7 @@ test_simpleclose_rw(void *ptr)
{ {
/* Test that a close of FD is detected as a read and as a write. */ /* Test that a close of FD is detected as a read and as a write. */
struct event_base *base = event_base_new(); struct event_base *base = event_base_new();
evutil_socket_t pair1[2]={-1,-1}, pair2[2] = {-1, -1}; evutil_socket_t pair1[2]={EVUTIL_INVALID_SOCKET,EVUTIL_INVALID_SOCKET}, pair2[2] = {EVUTIL_INVALID_SOCKET, EVUTIL_INVALID_SOCKET};
evutil_socket_t *to_close[2]; evutil_socket_t *to_close[2];
struct event *rev=NULL, *wev=NULL, *closeev=NULL; struct event *rev=NULL, *wev=NULL, *closeev=NULL;
struct timeval tv; struct timeval tv;

View File

@ -249,7 +249,7 @@ void *
basic_test_setup(const struct testcase_t *testcase) basic_test_setup(const struct testcase_t *testcase)
{ {
struct event_base *base = NULL; struct event_base *base = NULL;
evutil_socket_t spair[2] = { -1, -1 }; evutil_socket_t spair[2] = { EVUTIL_INVALID_SOCKET, EVUTIL_INVALID_SOCKET };
struct basic_test_data *data = NULL; struct basic_test_data *data = NULL;
#if defined(EVTHREAD_USE_PTHREADS_IMPLEMENTED) #if defined(EVTHREAD_USE_PTHREADS_IMPLEMENTED)

View File

@ -1731,7 +1731,7 @@ test_evutil_win_socketpair(void *arg)
struct basic_test_data *data = arg; struct basic_test_data *data = arg;
const int inet = strstr(data->setup_data, "inet") != NULL; const int inet = strstr(data->setup_data, "inet") != NULL;
int family = inet ? AF_INET : AF_UNIX; int family = inet ? AF_INET : AF_UNIX;
evutil_socket_t fd[2] = { -1, -1 }; evutil_socket_t fd[2] = { EVUTIL_INVALID_SOCKET, EVUTIL_INVALID_SOCKET };
int r; int r;
int type; int type;
ev_socklen_t typelen; ev_socklen_t typelen;

View File

@ -282,7 +282,7 @@ test_bufferevent_zlib(void *arg)
char buffer[8333]; char buffer[8333];
z_stream *z_input, *z_output; z_stream *z_input, *z_output;
int i, r; int i, r;
evutil_socket_t pair[2] = {-1, -1}; evutil_socket_t pair[2] = {EVUTIL_INVALID_SOCKET, EVUTIL_INVALID_SOCKET};
(void)arg; (void)arg;
infilter_calls = outfilter_calls = readcb_finished = writecb_finished infilter_calls = outfilter_calls = readcb_finished = writecb_finished

View File

@ -165,7 +165,7 @@ main(int argc, char **argv)
struct event* timeout = NULL; struct event* timeout = NULL;
struct event_base* base = NULL; struct event_base* base = NULL;
evutil_socket_t pair[2]; evutil_socket_t pair[2] = {EVUTIL_INVALID_SOCKET, EVUTIL_INVALID_SOCKET};
struct timeval tv; struct timeval tv;
struct cpu_usage_timer timer; struct cpu_usage_timer timer;
@ -188,12 +188,16 @@ main(int argc, char **argv)
/* Initialize a timeout to terminate the test */ /* Initialize a timeout to terminate the test */
timeout = evtimer_new(base,timeout_cb,&timeout); timeout = evtimer_new(base,timeout_cb,&timeout);
if (timeout == NULL) if (timeout == NULL) {
perror("evtimer_new");
goto err; goto err;
}
/* and watch for writability on one end of the pipe */ /* and watch for writability on one end of the pipe */
ev = event_new(base,pair[1],EV_WRITE | EV_PERSIST, write_cb, &ev); ev = event_new(base,pair[1],EV_WRITE | EV_PERSIST, write_cb, &ev);
if (ev == NULL) if (ev == NULL) {
perror("event_new");
goto err; goto err;
}
tv.tv_sec = 1; tv.tv_sec = 1;
tv.tv_usec = 500*1000; tv.tv_usec = 500*1000;
@ -228,9 +232,9 @@ err:
event_free(ev); event_free(ev);
if (timeout) if (timeout)
event_free(timeout); event_free(timeout);
if (pair[0] >= 0) if (pair[0] != EVUTIL_INVALID_SOCKET)
evutil_closesocket(pair[0]); evutil_closesocket(pair[0]);
if (pair[1] >= 0) if (pair[1] != EVUTIL_INVALID_SOCKET)
evutil_closesocket(pair[1]); evutil_closesocket(pair[1]);
if (base) if (base)
event_base_free(base); event_base_free(base);