From c7cf6f004951615cf775431d4f47663a20f2db6e Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Fri, 5 Mar 2010 12:47:46 -0500 Subject: [PATCH] Replace users of "int fd" with "evutil_socket_t fd" in portable code Remeber, win32 has a socket type that's actually a handle, so if there's a chance that code is run on win32, we can't use "int" as the socket type. This isn't a blind search-and-replace: sometimes an fd is really in fact for a file, and not a socket at all. --- changelist-internal.h | 4 +-- event.c | 2 +- evmap-internal.h | 2 +- evmap.c | 4 +-- http.c | 2 +- sample/dns-example.c | 2 +- sample/signal-test.c | 2 +- test/bench.c | 2 +- test/bench_cascade.c | 2 +- test/bench_httpclient.c | 4 +-- test/regress.c | 54 ++++++++++++++++++++--------------------- test/regress_et.c | 2 +- test/regress_http.c | 34 +++++++++++++------------- test/regress_pthread.c | 2 +- test/regress_rpc.c | 2 +- test/test-eof.c | 2 +- test/test-time.c | 2 +- test/test-weof.c | 2 +- 18 files changed, 63 insertions(+), 63 deletions(-) diff --git a/changelist-internal.h b/changelist-internal.h index 9e5b6bf0..fcf634f9 100644 --- a/changelist-internal.h +++ b/changelist-internal.h @@ -92,10 +92,10 @@ void event_changelist_remove_all(struct event_changelist *changelist, void event_changelist_freemem(struct event_changelist *changelist); /** Implementation of eventop_add that queues the event in a changelist. */ -int event_changelist_add(struct event_base *base, int fd, short old, short events, +int event_changelist_add(struct event_base *base, evutil_socket_t fd, short old, short events, void *p); /** Implementation of eventop_del that queues the event in a changelist. */ -int event_changelist_del(struct event_base *base, int fd, short old, short events, +int event_changelist_del(struct event_base *base, evutil_socket_t fd, short old, short events, void *p); #endif diff --git a/event.c b/event.c index 62993323..3735a409 100644 --- a/event.c +++ b/event.c @@ -2420,7 +2420,7 @@ event_set_mem_functions(void *(*malloc_fn)(size_t sz), #if defined(_EVENT_HAVE_EVENTFD) && defined(_EVENT_HAVE_SYS_EVENTFD_H) static void -evthread_notify_drain_eventfd(int fd, short what, void *arg) +evthread_notify_drain_eventfd(evutil_socket_t fd, short what, void *arg) { ev_uint64_t msg; diff --git a/evmap-internal.h b/evmap-internal.h index a09c5909..8a67efac 100644 --- a/evmap-internal.h +++ b/evmap-internal.h @@ -77,7 +77,7 @@ void evmap_io_active(struct event_base *base, evutil_socket_t fd, short events); int evmap_signal_add(struct event_base *base, int signum, struct event *ev); int evmap_signal_del(struct event_base *base, int signum, struct event *ev); -void evmap_signal_active(struct event_base *base, int fd, int ncalls); +void evmap_signal_active(struct event_base *base, evutil_socket_t fd, int ncalls); void *evmap_io_get_fdinfo(struct event_io_map *ctx, evutil_socket_t fd); diff --git a/evmap.c b/evmap.c index 7cfe2a5b..2a056a50 100644 --- a/evmap.c +++ b/evmap.c @@ -628,7 +628,7 @@ event_changelist_get_or_construct(struct event_changelist *changelist, } int -event_changelist_add(struct event_base *base, int fd, short old, short events, +event_changelist_add(struct event_base *base, evutil_socket_t fd, short old, short events, void *p) { struct event_changelist *changelist = &base->changelist; @@ -659,7 +659,7 @@ event_changelist_add(struct event_base *base, int fd, short old, short events, } int -event_changelist_del(struct event_base *base, int fd, short old, short events, +event_changelist_del(struct event_base *base, evutil_socket_t fd, short old, short events, void *p) { struct event_changelist *changelist = &base->changelist; diff --git a/http.c b/http.c index a50c13af..af2c9e33 100644 --- a/http.c +++ b/http.c @@ -1698,7 +1698,7 @@ evhttp_read_header(struct evhttp_connection *evcon, struct evhttp_request *req) { enum message_read_status res; - int fd = evcon->fd; + evutil_socket_t fd = evcon->fd; res = evhttp_parse_headers(req, bufferevent_get_input(evcon->bufev)); if (res == DATA_CORRUPTED || res == DATA_TOO_LONG) { diff --git a/sample/dns-example.c b/sample/dns-example.c index 3d73d56d..507cd5c8 100644 --- a/sample/dns-example.c +++ b/sample/dns-example.c @@ -168,7 +168,7 @@ main(int c, char **v) { evdns_set_log_fn(logfn); if (servertest) { - int sock; + evutil_socket_t sock; struct sockaddr_in my_addr; sock = socket(PF_INET, SOCK_DGRAM, 0); evutil_make_socket_nonblocking(sock); diff --git a/sample/signal-test.c b/sample/signal-test.c index 7b4bbe51..58524ccd 100644 --- a/sample/signal-test.c +++ b/sample/signal-test.c @@ -33,7 +33,7 @@ int called = 0; static void -signal_cb(int fd, short event, void *arg) +signal_cb(evutil_socket_t fd, short event, void *arg) { struct event *signal = arg; diff --git a/test/bench.c b/test/bench.c index e77fc65c..d1629daa 100644 --- a/test/bench.c +++ b/test/bench.c @@ -62,7 +62,7 @@ static struct event *events; static void -read_cb(int fd, short which, void *arg) +read_cb(evutil_socket_t fd, short which, void *arg) { long idx = (long) arg, widx = idx + 1; u_char ch; diff --git a/test/bench_cascade.c b/test/bench_cascade.c index 2c77e9f8..bf0f032d 100644 --- a/test/bench_cascade.c +++ b/test/bench_cascade.c @@ -59,7 +59,7 @@ static int *pipes; static struct event *events; static void -read_cb(int fd, short which, void *arg) +read_cb(evutil_socket_t fd, short which, void *arg) { char ch; long idx = (long) arg; diff --git a/test/bench_httpclient.c b/test/bench_httpclient.c index 35ca6f39..a9a7f14c 100644 --- a/test/bench_httpclient.c +++ b/test/bench_httpclient.c @@ -107,7 +107,7 @@ errorcb(struct bufferevent *b, short what, void *arg) } static void -frob_socket(int sock) +frob_socket(evutil_socket_t sock) { struct linger l; int one = 1; @@ -121,7 +121,7 @@ frob_socket(int sock) static int launch_request(void) { - int sock; + evutil_socket_t sock; struct sockaddr_in sin; struct bufferevent *b; diff --git a/test/regress.c b/test/regress.c index 7e7831ce..f30bdf88 100644 --- a/test/regress.c +++ b/test/regress.c @@ -104,7 +104,7 @@ struct basic_cb_args }; static void -simple_read_cb(int fd, short event, void *arg) +simple_read_cb(evutil_socket_t fd, short event, void *arg) { char buf[256]; int len; @@ -123,7 +123,7 @@ simple_read_cb(int fd, short event, void *arg) } static void -basic_read_cb(int fd, short event, void *data) +basic_read_cb(evutil_socket_t fd, short event, void *data) { char buf[256]; int len; @@ -157,12 +157,12 @@ basic_read_cb(int fd, short event, void *data) } static void -dummy_read_cb(int fd, short event, void *arg) +dummy_read_cb(evutil_socket_t fd, short event, void *arg) { } static void -simple_write_cb(int fd, short event, void *arg) +simple_write_cb(evutil_socket_t fd, short event, void *arg) { int len; @@ -174,7 +174,7 @@ simple_write_cb(int fd, short event, void *arg) } static void -multiple_write_cb(int fd, short event, void *arg) +multiple_write_cb(evutil_socket_t fd, short event, void *arg) { struct event *ev = arg; int len; @@ -207,7 +207,7 @@ multiple_write_cb(int fd, short event, void *arg) } static void -multiple_read_cb(int fd, short event, void *arg) +multiple_read_cb(evutil_socket_t fd, short event, void *arg) { struct event *ev = arg; int len; @@ -229,7 +229,7 @@ multiple_read_cb(int fd, short event, void *arg) } static void -timeout_cb(int fd, short event, void *arg) +timeout_cb(evutil_socket_t fd, short event, void *arg) { struct timeval tv; int diff; @@ -254,7 +254,7 @@ struct both { }; static void -combined_read_cb(int fd, short event, void *arg) +combined_read_cb(evutil_socket_t fd, short event, void *arg) { struct both *both = arg; char buf[128]; @@ -272,7 +272,7 @@ combined_read_cb(int fd, short event, void *arg) } static void -combined_write_cb(int fd, short event, void *arg) +combined_write_cb(evutil_socket_t fd, short event, void *arg) { struct both *both = arg; char buf[128]; @@ -380,7 +380,7 @@ test_simplewrite(void) } static void -simpleread_multiple_cb(int fd, short event, void *arg) +simpleread_multiple_cb(evutil_socket_t fd, short event, void *arg) { if (++called == 2) test_ok = 1; @@ -517,7 +517,7 @@ test_simpletimeout(void) } static void -periodic_timeout_cb(int fd, short event, void *arg) +periodic_timeout_cb(evutil_socket_t fd, short event, void *arg) { int *count = arg; @@ -556,14 +556,14 @@ struct persist_active_timeout_called { }; static void -activate_cb(int fd, short event, void *arg) +activate_cb(evutil_socket_t fd, short event, void *arg) { struct event *ev = arg; event_active(ev, EV_READ, 1); } static void -persist_active_timeout_cb(int fd, short event, void *arg) +persist_active_timeout_cb(evutil_socket_t fd, short event, void *arg) { struct persist_active_timeout_called *c = arg; if (c->n < 15) { @@ -624,7 +624,7 @@ struct common_timeout_info { }; static void -common_timeout_cb(int fd, short event, void *arg) +common_timeout_cb(evutil_socket_t fd, short event, void *arg) { struct common_timeout_info *ti = arg; ++ti->count; @@ -709,12 +709,12 @@ end: } #ifndef WIN32 -static void signal_cb(int fd, short event, void *arg); +static void signal_cb(evutil_socket_t fd, short event, void *arg); extern struct event_base *current_base; static void -child_signal_cb(int fd, short event, void *arg) +child_signal_cb(evutil_socket_t fd, short event, void *arg) { struct timeval tv; int *pint = arg; @@ -803,7 +803,7 @@ signal_cb_sa(int sig) } static void -signal_cb(int fd, short event, void *arg) +signal_cb(evutil_socket_t fd, short event, void *arg) { struct event *ev = arg; @@ -1055,7 +1055,7 @@ signal_cb_swp(int sig, short event, void *arg) event_loopexit(NULL); } static void -timeout_cb_swp(int fd, short event, void *arg) +timeout_cb_swp(evutil_socket_t fd, short event, void *arg) { if (called == -1) { struct timeval tv = {5, 0}; @@ -1261,14 +1261,14 @@ end: } static void -break_cb(int fd, short events, void *arg) +break_cb(evutil_socket_t fd, short events, void *arg) { test_ok = 1; event_loopbreak(); } static void -fail_cb(int fd, short events, void *arg) +fail_cb(evutil_socket_t fd, short events, void *arg) { test_ok = 0; } @@ -1302,7 +1302,7 @@ end: static struct event *readd_test_event_last_added = NULL; static void -re_add_read_cb(int fd, short event, void *arg) +re_add_read_cb(evutil_socket_t fd, short event, void *arg) { char buf[256]; int len; @@ -1362,7 +1362,7 @@ struct test_pri_event { }; static void -test_priorities_cb(int fd, short what, void *arg) +test_priorities_cb(evutil_socket_t fd, short what, void *arg) { struct test_pri_event *pri = arg; struct timeval tv; @@ -1440,7 +1440,7 @@ test_priorities(void) static void -test_multiple_cb(int fd, short event, void *arg) +test_multiple_cb(evutil_socket_t fd, short event, void *arg) { if (event & EV_READ) test_ok |= 1; @@ -1477,7 +1477,7 @@ int evtag_encode_tag(struct evbuffer *evbuf, ev_uint32_t number); int evtag_decode_tag(ev_uint32_t *pnumber, struct evbuffer *evbuf); static void -read_once_cb(int fd, short event, void *arg) +read_once_cb(evutil_socket_t fd, short event, void *arg) { char buf[256]; int len; @@ -1845,7 +1845,7 @@ end: } static void -read_called_once_cb(int fd, short event, void *arg) +read_called_once_cb(evutil_socket_t fd, short event, void *arg) { tt_int_op(event, ==, EV_READ); called += 1; @@ -1854,7 +1854,7 @@ end: } static void -timeout_called_once_cb(int fd, short event, void *arg) +timeout_called_once_cb(evutil_socket_t fd, short event, void *arg) { tt_int_op(event, ==, EV_TIMEOUT); called += 100; @@ -2003,7 +2003,7 @@ end: #endif static void -many_event_cb(int fd, short event, void *arg) +many_event_cb(evutil_socket_t fd, short event, void *arg) { int *calledp = arg; *calledp += 1; diff --git a/test/regress_et.c b/test/regress_et.c index 287eb4db..ba932564 100644 --- a/test/regress_et.c +++ b/test/regress_et.c @@ -52,7 +52,7 @@ static int was_et = 0; static void -read_cb(int fd, short event, void *arg) +read_cb(evutil_socket_t fd, short event, void *arg) { char buf; int len; diff --git a/test/regress_http.c b/test/regress_http.c index 7498ccb9..0ee5ca76 100644 --- a/test/regress_http.c +++ b/test/regress_http.c @@ -127,7 +127,7 @@ http_connect(const char *address, u_short port) #endif struct sockaddr *sa; int slen; - int fd; + evutil_socket_t fd; #ifdef WIN32 if (!(he = gethostbyname(address))) { @@ -314,7 +314,7 @@ http_chunked_cb(struct evhttp_request *req, void *arg) } static void -http_complete_write(int fd, short what, void *arg) +http_complete_write(evutil_socket_t fd, short what, void *arg) { struct bufferevent *bev = arg; const char *http_request = "host\r\n" @@ -328,7 +328,7 @@ http_basic_test(void) { struct timeval tv; struct bufferevent *bev; - int fd; + evutil_socket_t fd; const char *http_request; short port = -1; @@ -485,7 +485,7 @@ http_badreq_readcb(struct bufferevent *bev, void *arg) } static void -http_badreq_successcb(int fd, short what, void *arg) +http_badreq_successcb(evutil_socket_t fd, short what, void *arg) { event_debug(("%s: called (what=%04x, arg=%p)", __func__, what, arg)); event_loopexit(NULL); @@ -496,7 +496,7 @@ http_bad_request_test(void) { struct timeval tv; struct bufferevent *bev; - int fd; + evutil_socket_t fd; const char *http_request; short port = -1; @@ -609,7 +609,7 @@ static void http_delete_test(void) { struct bufferevent *bev; - int fd; + evutil_socket_t fd; const char *http_request; short port = -1; @@ -758,7 +758,7 @@ http_connection_async_test(void) /* Add ourself as the only nameserver, and make sure we really are * the only nameserver. */ - evutil_snprintf(address, sizeof (address), "127.0.0.1:%d", portnum); + evutil_snprintf(address, sizeof(address), "127.0.0.1:%d", portnum); evdns_base_nameserver_ip_add(dns_base, address); test_ok = 0; @@ -1440,7 +1440,7 @@ static void http_failure_test(void) { struct bufferevent *bev; - int fd; + evutil_socket_t fd; const char *http_request; short port = -1; @@ -1486,7 +1486,7 @@ close_detect_done(struct evhttp_request *req, void *arg) } static void -close_detect_launch(int fd, short what, void *arg) +close_detect_launch(evutil_socket_t fd, short what, void *arg) { struct evhttp_connection *evcon = arg; struct evhttp_request *req; @@ -1659,7 +1659,7 @@ http_base_test(void) { struct event_base *tmp; struct bufferevent *bev; - int fd; + evutil_socket_t fd; const char *http_request; short port = -1; @@ -1727,7 +1727,7 @@ static void http_incomplete_writecb(struct bufferevent *bev, void *arg) { if (arg != NULL) { - int fd = *(int *)arg; + evutil_socket_t fd = *(evutil_socket_t *)arg; /* terminate the write side to simulate EOF */ shutdown(fd, SHUT_WR); } @@ -1742,7 +1742,7 @@ static void _http_incomplete_test(int use_timeout) { struct bufferevent *bev; - int fd; + evutil_socket_t fd; const char *http_request; short port = -1; struct timeval tv_start, tv_end; @@ -1944,7 +1944,7 @@ static void http_chunk_out_test(void) { struct bufferevent *bev; - int fd; + evutil_socket_t fd; const char *http_request; short port = -1; struct timeval tv_start, tv_end; @@ -2198,7 +2198,7 @@ http_connection_retry_done(struct evhttp_request *req, void *arg) } static void -http_make_web_server(int fd, short what, void *arg) +http_make_web_server(evutil_socket_t fd, short what, void *arg) { short port = -1; http = http_setup(&port, NULL); @@ -2522,7 +2522,7 @@ http_data_length_constraints_test(void) struct terminate_state { struct evhttp_request *req; struct bufferevent *bev; - int fd; + evutil_socket_t fd; int gotclosecb: 1; } terminate_state; @@ -2577,7 +2577,7 @@ terminate_chunked_cb(struct evhttp_request *req, void *arg) } static void -terminate_chunked_client(int fd, short event, void *arg) +terminate_chunked_client(evutil_socket_t fd, short event, void *arg) { struct terminate_state *state = arg; bufferevent_free(state->bev); @@ -2599,7 +2599,7 @@ http_terminate_chunked_test(void) struct timeval tv; const char *http_request; short port = -1; - int fd = -1; + evutil_socket_t fd = -1; test_ok = 0; diff --git a/test/regress_pthread.c b/test/regress_pthread.c index fb6258be..27e59012 100644 --- a/test/regress_pthread.c +++ b/test/regress_pthread.c @@ -46,7 +46,7 @@ struct cond_wait { }; static void -basic_timeout(int fd, short what, void *arg) +basic_timeout(evutil_socket_t fd, short what, void *arg) { struct cond_wait *cw = arg; assert(pthread_mutex_lock(&cw->lock) == 0); diff --git a/test/regress_rpc.c b/test/regress_rpc.c index 4c14ee68..3b6cdf38 100644 --- a/test/regress_rpc.c +++ b/test/regress_rpc.c @@ -587,7 +587,7 @@ struct _rpc_hook_ctx { static int hook_pause_cb_called=0; static void -rpc_hook_pause_cb(int fd, short what, void *arg) +rpc_hook_pause_cb(evutil_socket_t fd, short what, void *arg) { struct _rpc_hook_ctx *ctx = arg; ++hook_pause_cb_called; diff --git a/test/test-eof.c b/test/test-eof.c index d0c600c1..a5933c51 100644 --- a/test/test-eof.c +++ b/test/test-eof.c @@ -34,7 +34,7 @@ int test_okay = 1; int called = 0; static void -read_cb(int fd, short event, void *arg) +read_cb(evutil_socket_t fd, short event, void *arg) { char buf[256]; int len; diff --git a/test/test-time.c b/test/test-time.c index 17a019a6..c1b449b2 100644 --- a/test/test-time.c +++ b/test/test-time.c @@ -37,7 +37,7 @@ rand_int(int n) } static void -time_cb(int fd, short event, void *arg) +time_cb(evutil_socket_t fd, short event, void *arg) { struct timeval tv; int i, j; diff --git a/test/test-weof.c b/test/test-weof.c index a6aa5ea7..f0da92b7 100644 --- a/test/test-weof.c +++ b/test/test-weof.c @@ -38,7 +38,7 @@ int test_okay = 1; int called = 0; static void -write_cb(int fd, short event, void *arg) +write_cb(evutil_socket_t fd, short event, void *arg) { const char *test = "test string"; int len;