From: Azat Khuzhin Date: Tue, 29 Jan 2019 18:12:33 +0000 (+0300) Subject: Eliminate fd conversion warnings and introduce EVUTIL_INVALID_SOCKET (windows) X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b29207dceee33832bb28ab103a833df6a2fd29d3;p=libevent Eliminate fd conversion warnings and introduce EVUTIL_INVALID_SOCKET (windows) windows has intptr_t instead of regular int. Also tt_fd_op() had been introduced, since we cannot use tt_int_op() for comparing fd, since it is not always int. --- diff --git a/bufferevent_async.c b/bufferevent_async.c index d2eefed4..141cf34f 100644 --- a/bufferevent_async.c +++ b/bufferevent_async.c @@ -402,10 +402,10 @@ be_async_destruct(struct bufferevent *bev) bev_async_del_write(bev_async); fd = evbuffer_overlapped_get_fd_(bev->input); - if (fd != (evutil_socket_t)INVALID_SOCKET && + if (fd != (evutil_socket_t)EVUTIL_INVALID_SOCKET && (bev_p->options & BEV_OPT_CLOSE_ON_FREE)) { evutil_closesocket(fd); - evbuffer_overlapped_set_fd_(bev->input, INVALID_SOCKET); + evbuffer_overlapped_set_fd_(bev->input, EVUTIL_INVALID_SOCKET); } } @@ -688,10 +688,10 @@ be_async_ctrl(struct bufferevent *bev, enum bufferevent_ctrl_op op, case BEV_CTRL_CANCEL_ALL: { struct bufferevent_async *bev_a = upcast(bev); evutil_socket_t fd = evbuffer_overlapped_get_fd_(bev->input); - if (fd != (evutil_socket_t)INVALID_SOCKET && + if (fd != (evutil_socket_t)EVUTIL_INVALID_SOCKET && (bev_a->bev.options & BEV_OPT_CLOSE_ON_FREE)) { closesocket(fd); - evbuffer_overlapped_set_fd_(bev->input, INVALID_SOCKET); + evbuffer_overlapped_set_fd_(bev->input, EVUTIL_INVALID_SOCKET); } bev_a->ok = 0; return 0; diff --git a/bufferevent_openssl.c b/bufferevent_openssl.c index 8e2b361c..beebe071 100644 --- a/bufferevent_openssl.c +++ b/bufferevent_openssl.c @@ -964,8 +964,8 @@ be_openssl_writeeventcb(evutil_socket_t fd, short what, void *ptr) bufferevent_decref_and_unlock_(&bev_ssl->bev.bev); } -static int -be_openssl_auto_fd(struct bufferevent_openssl *bev_ssl, int fd) +static evutil_socket_t +be_openssl_auto_fd(struct bufferevent_openssl *bev_ssl, evutil_socket_t fd) { if (!bev_ssl->underlying) { struct bufferevent *bev = &bev_ssl->bev.bev; @@ -1031,7 +1031,7 @@ do_handshake(struct bufferevent_openssl *bev_ssl) decrement_buckets(bev_ssl); if (r==1) { - int fd = event_get_fd(&bev_ssl->bev.bev.ev_read); + evutil_socket_t fd = event_get_fd(&bev_ssl->bev.bev.ev_read); /* We're done! */ bev_ssl->state = BUFFEREVENT_SSL_OPEN; set_open_callbacks(bev_ssl, fd); /* XXXX handle failure */ @@ -1229,7 +1229,7 @@ be_openssl_destruct(struct bufferevent *bev) if (bev_ssl->bev.options & BEV_OPT_CLOSE_ON_FREE) { if (! bev_ssl->underlying) { - evutil_socket_t fd = -1; + evutil_socket_t fd = EVUTIL_INVALID_SOCKET; BIO *bio = SSL_get_wbio(bev_ssl->ssl); if (bio) fd = BIO_get_fd(bio, NULL); @@ -1262,7 +1262,7 @@ be_openssl_flush(struct bufferevent *bufev, static int be_openssl_set_fd(struct bufferevent_openssl *bev_ssl, - enum bufferevent_ssl_state state, int fd) + enum bufferevent_ssl_state state, evutil_socket_t fd) { bev_ssl->state = state; @@ -1301,7 +1301,7 @@ be_openssl_ctrl(struct bufferevent *bev, case BEV_CTRL_SET_FD: if (!bev_ssl->underlying) { BIO *bio; - bio = BIO_new_socket(data->fd, 0); + bio = BIO_new_socket((int)data->fd, 0); SSL_set_bio(bev_ssl->ssl, bio, bio); } else { BIO *bio; @@ -1465,7 +1465,7 @@ bufferevent_openssl_socket_new(struct event_base *base, /* The SSL isn't configured with a BIO with an fd. */ if (fd >= 0) { /* ... and we have an fd we want to use. */ - bio = BIO_new_socket(fd, 0); + bio = BIO_new_socket((int)fd, 0); SSL_set_bio(ssl, bio, bio); } else { /* Leave the fd unset. */ diff --git a/bufferevent_sock.c b/bufferevent_sock.c index 48d6c7e9..f275b023 100644 --- a/bufferevent_sock.c +++ b/bufferevent_sock.c @@ -104,7 +104,8 @@ bufferevent_socket_get_conn_address_(struct bufferevent *bev) } void -bufferevent_socket_set_conn_address_fd_(struct bufferevent *bev, int fd) +bufferevent_socket_set_conn_address_fd_(struct bufferevent *bev, + evutil_socket_t fd) { struct bufferevent_private *bev_p = BEV_UPCAST(bev); diff --git a/event_iocp.c b/event_iocp.c index a9902fbc..6b2a2e15 100644 --- a/event_iocp.c +++ b/event_iocp.c @@ -151,7 +151,7 @@ init_extension_functions(struct win32_extension_fns *ext) const GUID connectex = WSAID_CONNECTEX; const GUID getacceptexsockaddrs = WSAID_GETACCEPTEXSOCKADDRS; SOCKET s = socket(AF_INET, SOCK_STREAM, 0); - if (s == INVALID_SOCKET) + if (s == EVUTIL_INVALID_SOCKET) return; ext->AcceptEx = get_extension_function(s, &acceptex); ext->ConnectEx = get_extension_function(s, &connectex); diff --git a/include/event2/util.h b/include/event2/util.h index 80574c71..7c872737 100644 --- a/include/event2/util.h +++ b/include/event2/util.h @@ -484,6 +484,7 @@ int evutil_socket_geterror(evutil_socket_t sock); /** Convert a socket error to a string. */ EVENT2_EXPORT_SYMBOL const char *evutil_socket_error_to_string(int errcode); +#define EVUTIL_INVALID_SOCKET INVALID_SOCKET #elif defined(EVENT_IN_DOXYGEN_) /** @name Socket error functions @@ -507,14 +508,16 @@ const char *evutil_socket_error_to_string(int errcode); #define evutil_socket_geterror(sock) ... /** Convert a socket error to a string. */ #define evutil_socket_error_to_string(errcode) ... +#define EVUTIL_INVALID_SOCKET -1 /**@}*/ -#else +#else /** !EVENT_IN_DOXYGEN_ && !_WIN32 */ #define EVUTIL_SOCKET_ERROR() (errno) #define EVUTIL_SET_SOCKET_ERROR(errcode) \ do { errno = (errcode); } while (0) #define evutil_socket_geterror(sock) (errno) #define evutil_socket_error_to_string(errcode) (strerror(errcode)) -#endif +#define EVUTIL_INVALID_SOCKET -1 +#endif /** !_WIN32 */ /** diff --git a/listener.c b/listener.c index e803bed1..387a89e9 100644 --- a/listener.c +++ b/listener.c @@ -512,7 +512,7 @@ new_accepting_socket(struct evconnlistener_iocp *lev, int family) return NULL; event_overlapped_init_(&res->overlapped, accepted_socket_cb); - res->s = INVALID_SOCKET; + res->s = EVUTIL_INVALID_SOCKET; res->lev = lev; res->buflen = buflen; res->family = family; @@ -530,7 +530,7 @@ static void free_and_unlock_accepting_socket(struct accepting_socket *as) { /* requires lock. */ - if (as->s != INVALID_SOCKET) + if (as->s != EVUTIL_INVALID_SOCKET) closesocket(as->s); LeaveCriticalSection(&as->lock); @@ -550,7 +550,7 @@ start_accepting(struct accepting_socket *as) if (!as->lev->base.enabled) return 0; - if (s == INVALID_SOCKET) { + if (s == EVUTIL_INVALID_SOCKET) { error = WSAGetLastError(); goto report_err; } @@ -597,7 +597,7 @@ stop_accepting(struct accepting_socket *as) { /* requires lock. */ SOCKET s = as->s; - as->s = INVALID_SOCKET; + as->s = EVUTIL_INVALID_SOCKET; closesocket(s); } @@ -639,7 +639,7 @@ accepted_socket_invoke_user_cb(struct event_callback *dcb, void *arg) &socklen_remote); sock = as->s; cb = lev->cb; - as->s = INVALID_SOCKET; + as->s = EVUTIL_INVALID_SOCKET; /* We need to call this so getsockname, getpeername, and * shutdown work correctly on the accepted socket. */ @@ -687,7 +687,7 @@ accepted_socket_cb(struct event_overlapped *o, ev_uintptr_t key, ev_ssize_t n, i free_and_unlock_accepting_socket(as); listener_decref_and_unlock(lev); return; - } else if (as->s == INVALID_SOCKET) { + } else if (as->s == EVUTIL_INVALID_SOCKET) { /* This is okay; we were disabled by iocp_listener_disable. */ LeaveCriticalSection(&as->lock); } else { @@ -725,7 +725,7 @@ iocp_listener_enable(struct evconnlistener *lev) if (!as) continue; EnterCriticalSection(&as->lock); - if (!as->free_on_cb && as->s == INVALID_SOCKET) + if (!as->free_on_cb && as->s == EVUTIL_INVALID_SOCKET) start_accepting(as); LeaveCriticalSection(&as->lock); } @@ -747,7 +747,7 @@ iocp_listener_disable_impl(struct evconnlistener *lev, int shutdown) if (!as) continue; EnterCriticalSection(&as->lock); - if (!as->free_on_cb && as->s != INVALID_SOCKET) { + if (!as->free_on_cb && as->s != EVUTIL_INVALID_SOCKET) { if (shutdown) as->free_on_cb = 1; stop_accepting(as); diff --git a/test/regress.c b/test/regress.c index c08accc5..2c17dba3 100644 --- a/test/regress.c +++ b/test/regress.c @@ -3118,7 +3118,7 @@ test_get_assignment(void *arg) event_get_assignment(ev1, &b, &s, &what, &cb, &cb_arg); tt_ptr_op(b, ==, base); - tt_int_op(s, ==, data->pair[1]); + tt_fd_op(s, ==, data->pair[1]); tt_int_op(what, ==, EV_READ); tt_ptr_op(cb, ==, dummy_read_cb); tt_ptr_op(cb_arg, ==, str); diff --git a/test/regress_bufferevent.c b/test/regress_bufferevent.c index 55d8e135..3ed48fae 100644 --- a/test/regress_bufferevent.c +++ b/test/regress_bufferevent.c @@ -137,14 +137,14 @@ test_bufferevent_impl(int use_pair, int flush) bev2 = pair[1]; bufferevent_setcb(bev1, readcb, writecb, errorcb, bev1); bufferevent_setcb(bev2, readcb, writecb, errorcb, NULL); - tt_int_op(bufferevent_getfd(bev1), ==, -1); + tt_fd_op(bufferevent_getfd(bev1), ==, EVUTIL_INVALID_SOCKET); tt_ptr_op(bufferevent_get_underlying(bev1), ==, NULL); tt_ptr_op(bufferevent_pair_get_partner(bev1), ==, bev2); tt_ptr_op(bufferevent_pair_get_partner(bev2), ==, bev1); } else { bev1 = bufferevent_new(pair[0], readcb, writecb, errorcb, NULL); bev2 = bufferevent_new(pair[1], readcb, writecb, errorcb, NULL); - tt_int_op(bufferevent_getfd(bev1), ==, pair[0]); + tt_fd_op(bufferevent_getfd(bev1), ==, pair[0]); tt_ptr_op(bufferevent_get_underlying(bev1), ==, NULL); tt_ptr_op(bufferevent_pair_get_partner(bev1), ==, NULL); tt_ptr_op(bufferevent_pair_get_partner(bev2), ==, NULL); @@ -569,8 +569,8 @@ test_bufferevent_filters_impl(int use_pair, int disable) tt_ptr_op(bufferevent_get_underlying(bev1), ==, bev1_base); tt_ptr_op(bufferevent_get_underlying(bev2), ==, bev2_base); - tt_int_op(bufferevent_getfd(bev1), ==, bufferevent_getfd(bev1_base)); - tt_int_op(bufferevent_getfd(bev2), ==, bufferevent_getfd(bev2_base)); + tt_fd_op(bufferevent_getfd(bev1), ==, bufferevent_getfd(bev1_base)); + tt_fd_op(bufferevent_getfd(bev2), ==, bufferevent_getfd(bev2_base)); bufferevent_disable(bev1, EV_READ); bufferevent_enable(bev2, EV_READ); @@ -640,7 +640,7 @@ end: ; } -static int +static evutil_socket_t fake_listener_create(struct sockaddr_in *localhost) { struct sockaddr *sa = (struct sockaddr *)localhost; diff --git a/test/regress_http.c b/test/regress_http.c index 85c062f9..f4e8bcd6 100644 --- a/test/regress_http.c +++ b/test/regress_http.c @@ -181,7 +181,7 @@ http_connect(const char *address, ev_uint16_t port) char strport[NI_MAXSERV]; struct sockaddr *sa; - int slen; + size_t slen; evutil_socket_t fd; memset(&ai, 0, sizeof(ai)); @@ -374,7 +374,7 @@ end: evbuffer_free(evb); } -static void http_timeout_reply_cb(int fd, short events, void *arg) +static void http_timeout_reply_cb(evutil_socket_t fd, short events, void *arg) { struct evhttp_request *req = arg; evhttp_send_reply(req, HTTP_OK, "Everything is fine", NULL); @@ -457,7 +457,7 @@ http_chunked_cb(struct evhttp_request *req, void *arg) } static struct bufferevent * -create_bev(struct event_base *base, int fd, int ssl_mask) +create_bev(struct event_base *base, evutil_socket_t fd, int ssl_mask) { int flags = BEV_OPT_DEFER_CALLBACKS; struct bufferevent *bev = NULL; @@ -684,7 +684,7 @@ http_bad_request_test(void *arg) struct basic_test_data *data = arg; struct timeval tv; struct bufferevent *bev = NULL; - evutil_socket_t fd = -1; + evutil_socket_t fd = EVUTIL_INVALID_SOCKET; const char *http_request; ev_uint16_t port=0, port2=0; struct evhttp *http = http_setup(&port, data->base, 0); @@ -698,7 +698,7 @@ http_bad_request_test(void *arg) /* NULL request test */ fd = http_connect("127.0.0.1", port); - tt_int_op(fd, >=, 0); + tt_assert(fd != EVUTIL_INVALID_SOCKET); /* Stupid thing to send a request */ bev = bufferevent_socket_new(data->base, fd, 0); @@ -730,6 +730,7 @@ http_bad_request_test(void *arg) /* connect to the second port */ fd = http_connect("127.0.0.1", port2); + tt_assert(fd != EVUTIL_INVALID_SOCKET); /* Stupid thing to send a request */ bev = bufferevent_socket_new(data->base, fd, 0); @@ -805,7 +806,7 @@ http_delete_test(void *arg) { struct basic_test_data *data = arg; struct bufferevent *bev; - evutil_socket_t fd = -1; + evutil_socket_t fd = EVUTIL_INVALID_SOCKET; const char *http_request; ev_uint16_t port = 0; struct evhttp *http = http_setup(&port, data->base, 0); @@ -815,7 +816,7 @@ http_delete_test(void *arg) tt_assert(http); fd = http_connect("127.0.0.1", port); - tt_int_op(fd, >=, 0); + tt_assert(fd != EVUTIL_INVALID_SOCKET); /* Stupid thing to send a request */ bev = bufferevent_socket_new(data->base, fd, 0); @@ -834,7 +835,7 @@ http_delete_test(void *arg) bufferevent_free(bev); evutil_closesocket(fd); - fd = -1; + fd = EVUTIL_INVALID_SOCKET; evhttp_free(http); @@ -889,7 +890,7 @@ http_on_complete_test(void *arg) { struct basic_test_data *data = arg; struct bufferevent *bev; - evutil_socket_t fd = -1; + evutil_socket_t fd = EVUTIL_INVALID_SOCKET; const char *http_request; ev_uint16_t port = 0; struct evhttp *http = http_setup(&port, data->base, 0); @@ -898,7 +899,7 @@ http_on_complete_test(void *arg) test_ok = 0; fd = http_connect("127.0.0.1", port); - tt_int_op(fd, >=, 0); + tt_assert(fd != EVUTIL_INVALID_SOCKET); /* Stupid thing to send a request */ bev = bufferevent_socket_new(data->base, fd, 0); @@ -959,7 +960,7 @@ http_allowed_methods_test(void *arg) test_ok = 0; fd1 = http_connect("127.0.0.1", port); - tt_int_op(fd1, >=, 0); + tt_assert(fd1 != EVUTIL_INVALID_SOCKET); /* GET is out; PATCH is in. */ evhttp_set_allowed_methods(http, EVHTTP_REQ_PATCH); @@ -981,7 +982,7 @@ http_allowed_methods_test(void *arg) event_base_dispatch(data->base); fd2 = http_connect("127.0.0.1", port); - tt_int_op(fd2, >=, 0); + tt_assert(fd2 != EVUTIL_INVALID_SOCKET); bev2 = bufferevent_socket_new(data->base, fd2, 0); bufferevent_enable(bev2, EV_READ|EV_WRITE); @@ -999,7 +1000,7 @@ http_allowed_methods_test(void *arg) event_base_dispatch(data->base); fd3 = http_connect("127.0.0.1", port); - tt_int_op(fd3, >=, 0); + tt_assert(fd3 != EVUTIL_INVALID_SOCKET); bev3 = bufferevent_socket_new(data->base, fd3, 0); bufferevent_enable(bev3, EV_READ|EV_WRITE); @@ -1787,6 +1788,7 @@ http_virtual_host_test(void *arg) /* Now make a raw request with an absolute URI. */ fd = http_connect("127.0.0.1", port); + tt_assert(fd != EVUTIL_INVALID_SOCKET); /* Stupid thing to send a request */ bev = bufferevent_socket_new(data->base, fd, 0); @@ -2229,7 +2231,7 @@ http_failure_test(void *arg) { struct basic_test_data *data = arg; struct bufferevent *bev; - evutil_socket_t fd = -1; + evutil_socket_t fd = EVUTIL_INVALID_SOCKET; const char *http_request; ev_uint16_t port = 0; struct evhttp *http = http_setup(&port, data->base, 0); @@ -2237,7 +2239,7 @@ http_failure_test(void *arg) test_ok = 0; fd = http_connect("127.0.0.1", port); - tt_int_op(fd, >=, 0); + tt_assert(fd != EVUTIL_INVALID_SOCKET); /* Stupid thing to send a request */ bev = bufferevent_socket_new(data->base, fd, 0); @@ -3083,7 +3085,7 @@ http_base_test(void *ptr) http = http_setup(&port, base, 0); fd = http_connect("127.0.0.1", port); - tt_int_op(fd, >=, 0); + tt_assert(fd != EVUTIL_INVALID_SOCKET); /* Stupid thing to send a request */ bev = bufferevent_socket_new(base, fd, 0); @@ -3170,7 +3172,7 @@ http_incomplete_test_(struct basic_test_data *data, int use_timeout, int ssl) evhttp_set_timeout(http, 1); fd = http_connect("127.0.0.1", port); - tt_int_op(fd, >=, 0); + tt_assert(fd != EVUTIL_INVALID_SOCKET); /* Stupid thing to send a request */ bev = create_bev(data->base, fd, ssl); @@ -3194,7 +3196,7 @@ http_incomplete_test_(struct basic_test_data *data, int use_timeout, int ssl) bufferevent_free(bev); if (use_timeout) { evutil_closesocket(fd); - fd = -1; + fd = EVUTIL_INVALID_SOCKET; } evhttp_free(http); @@ -3387,6 +3389,7 @@ http_chunk_out_test_impl(void *arg, int ssl) test_ok = 0; fd = http_connect("127.0.0.1", port); + tt_assert(fd != EVUTIL_INVALID_SOCKET); /* Stupid thing to send a request */ bev = create_bev(data->base, fd, ssl); @@ -3965,7 +3968,7 @@ http_multi_line_header_test(void *arg) { struct basic_test_data *data = arg; struct bufferevent *bev= NULL; - evutil_socket_t fd = -1; + evutil_socket_t fd = EVUTIL_INVALID_SOCKET; const char *http_start_request; ev_uint16_t port = 0; struct evhttp *http = http_setup(&port, data->base, 0); @@ -3976,8 +3979,7 @@ http_multi_line_header_test(void *arg) tt_ptr_op(http, !=, NULL); fd = http_connect("127.0.0.1", port); - - tt_int_op(fd, !=, -1); + tt_assert(fd != EVUTIL_INVALID_SOCKET); /* Stupid thing to send a request */ bev = bufferevent_socket_new(data->base, fd, 0); @@ -4369,7 +4371,7 @@ http_terminate_chunked_test_impl(void *arg, int oneshot) struct timeval tv; const char *http_request; ev_uint16_t port = 0; - evutil_socket_t fd = -1; + evutil_socket_t fd = EVUTIL_INVALID_SOCKET; struct terminate_state terminate_state; struct evhttp *http = http_setup(&port, data->base, 0); @@ -4380,6 +4382,7 @@ http_terminate_chunked_test_impl(void *arg, int oneshot) terminate_chunked_cb, &terminate_state) == 0); fd = http_connect("127.0.0.1", port); + tt_assert(fd != EVUTIL_INVALID_SOCKET); /* Stupid thing to send a request */ bev = bufferevent_socket_new(data->base, fd, 0); @@ -4560,7 +4563,7 @@ http_write_during_read_test_impl(void *arg, int ssl) ev_uint16_t port = 0; struct bufferevent *bev = NULL; struct timeval tv; - int fd; + evutil_socket_t fd; const char *http_request; struct evhttp *http = http_setup(&port, data->base, ssl ? HTTP_BIND_SSL : 0); @@ -4568,6 +4571,7 @@ http_write_during_read_test_impl(void *arg, int ssl) exit_base = data->base; fd = http_connect("127.0.0.1", port); + tt_assert(fd != EVUTIL_INVALID_SOCKET); bev = create_bev(data->base, fd, 0); bufferevent_setcb(bev, NULL, NULL, NULL, data->base); bufferevent_disable(bev, EV_READ); @@ -4584,6 +4588,7 @@ http_write_during_read_test_impl(void *arg, int ssl) event_base_dispatch(data->base); +end: if (bev) bufferevent_free(bev); if (http) @@ -4636,6 +4641,7 @@ static void http_run_bev_request(struct event_base *base, int port, struct evbuffer *out; fd = http_connect("127.0.0.1", port); + tt_assert(fd != EVUTIL_INVALID_SOCKET); /* Stupid thing to send a request */ bev = create_bev(base, fd, 0); @@ -4649,7 +4655,9 @@ static void http_run_bev_request(struct event_base *base, int port, event_base_dispatch(base); - bufferevent_free(bev); +end: + if (bev) + bufferevent_free(bev); } static void http_request_extra_body_test(void *arg) diff --git a/test/regress_listener.c b/test/regress_listener.c index 070e5e34..b60529f2 100644 --- a/test/regress_listener.c +++ b/test/regress_listener.c @@ -80,8 +80,9 @@ regress_pick_a_port(void *arg) ev_socklen_t slen1 = sizeof(ss1), slen2 = sizeof(ss2); unsigned int flags = LEV_OPT_CLOSE_ON_FREE|LEV_OPT_REUSEABLE|LEV_OPT_CLOSE_ON_EXEC; + evutil_socket_t fd1, fd2, fd3; - evutil_socket_t fd1 = -1, fd2 = -1, fd3 = -1; + fd1 = fd2 = fd3 = EVUTIL_INVALID_SOCKET; if (data->setup_data && strstr((char*)data->setup_data, "ts")) { flags |= LEV_OPT_THREADSAFE; @@ -99,8 +100,8 @@ regress_pick_a_port(void *arg) flags, -1, (struct sockaddr *)&sin, sizeof(sin)); tt_assert(listener2); - tt_int_op(evconnlistener_get_fd(listener1), >=, 0); - tt_int_op(evconnlistener_get_fd(listener2), >=, 0); + tt_assert(evconnlistener_get_fd(listener1) != EVUTIL_INVALID_SOCKET); + tt_assert(evconnlistener_get_fd(listener2) != EVUTIL_INVALID_SOCKET); tt_assert(getsockname(evconnlistener_get_fd(listener1), (struct sockaddr*)&ss1, &slen1) == 0); tt_assert(getsockname(evconnlistener_get_fd(listener2), @@ -117,7 +118,7 @@ regress_pick_a_port(void *arg) tt_ptr_op(evconnlistener_get_base(listener1), ==, base); tt_ptr_op(evconnlistener_get_base(listener2), ==, base); - fd1 = fd2 = fd3 = -1; + fd1 = fd2 = fd3 = EVUTIL_INVALID_SOCKET; evutil_socket_connect_(&fd1, (struct sockaddr*)&ss1, slen1); evutil_socket_connect_(&fd2, (struct sockaddr*)&ss1, slen1); evutil_socket_connect_(&fd3, (struct sockaddr*)&ss2, slen2); @@ -208,7 +209,7 @@ regress_listener_close_accepted_fd(void *arg) ev_socklen_t slen = sizeof(ss); int count = 1; unsigned int flags = LEV_OPT_CLOSE_ON_FREE|LEV_OPT_REUSEABLE; - int fd = -1; + evutil_socket_t fd = EVUTIL_INVALID_SOCKET; memset(&sin, 0, sizeof(sin)); sin.sin_family = AF_INET; @@ -241,7 +242,7 @@ regress_listener_immediate_close(void *arg) ev_socklen_t slen = sizeof(ss); int count = 1; unsigned int flags = LEV_OPT_CLOSE_ON_FREE|LEV_OPT_REUSEABLE; - int fd1 = -1, fd2 = -1; + evutil_socket_t fd1 = EVUTIL_INVALID_SOCKET, fd2 = EVUTIL_INVALID_SOCKET; memset(&sin, 0, sizeof(sin)); sin.sin_family = AF_INET; diff --git a/test/regress_ssl.c b/test/regress_ssl.c index 45ce540d..b486b803 100644 --- a/test/regress_ssl.c +++ b/test/regress_ssl.c @@ -287,12 +287,12 @@ enum regress_openssl_type static void bufferevent_openssl_check_fd(struct bufferevent *bev, int filter) { - tt_int_op(bufferevent_getfd(bev), !=, -1); - tt_int_op(bufferevent_setfd(bev, -1), ==, 0); + tt_fd_op(bufferevent_getfd(bev), !=, EVUTIL_INVALID_SOCKET); + tt_fd_op(bufferevent_setfd(bev, EVUTIL_INVALID_SOCKET), ==, 0); if (filter) { - tt_int_op(bufferevent_getfd(bev), !=, -1); + tt_fd_op(bufferevent_getfd(bev), !=, EVUTIL_INVALID_SOCKET); } else { - tt_int_op(bufferevent_getfd(bev), ==, -1); + tt_fd_op(bufferevent_getfd(bev), ==, EVUTIL_INVALID_SOCKET); } end: @@ -501,7 +501,7 @@ regress_bufferevent_openssl(void *arg) fd_pair, bev_ll, type); if (!(type & REGRESS_OPENSSL_FILTER)) { - tt_int_op(bufferevent_getfd(bev1), ==, data->pair[0]); + tt_fd_op(bufferevent_getfd(bev1), ==, data->pair[0]); } else { tt_ptr_op(bufferevent_get_underlying(bev1), ==, bev_ll[0]); } @@ -614,7 +614,7 @@ end: struct rwcount { - int fd; + evutil_socket_t fd; size_t read; size_t write; }; diff --git a/test/tinytest_macros.h b/test/tinytest_macros.h index 2c02a741..e34e74ec 100644 --- a/test/tinytest_macros.h +++ b/test/tinytest_macros.h @@ -158,6 +158,14 @@ tt_assert_test_type(a,b,#a" "#op" "#b,long,(val1_ op val2_), \ "%ld",TT_EXIT_TEST_FUNCTION) +/** To compare SOCKET(windows)/fd */ +#define tt_fd_op(a,op,b) do { \ + int _a = (int)(a); \ + int _b = (int)(b); \ + tt_assert_test_type(_a,_b,#a" "#op" "#b,long,(val1_ op val2_), \ + "%ld",TT_EXIT_TEST_FUNCTION); \ +} while (0) + #define tt_uint_op(a,op,b) \ tt_assert_test_type(a,b,#a" "#op" "#b,unsigned long, \ (val1_ op val2_),"%lu",TT_EXIT_TEST_FUNCTION)