]> granicus.if.org Git - libevent/commitdiff
Replace users of "int fd" with "evutil_socket_t fd" in portable code
authorNick Mathewson <nickm@torproject.org>
Fri, 5 Mar 2010 17:47:46 +0000 (12:47 -0500)
committerNick Mathewson <nickm@torproject.org>
Fri, 5 Mar 2010 17:47:46 +0000 (12:47 -0500)
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.

18 files changed:
changelist-internal.h
event.c
evmap-internal.h
evmap.c
http.c
sample/dns-example.c
sample/signal-test.c
test/bench.c
test/bench_cascade.c
test/bench_httpclient.c
test/regress.c
test/regress_et.c
test/regress_http.c
test/regress_pthread.c
test/regress_rpc.c
test/test-eof.c
test/test-time.c
test/test-weof.c

index 9e5b6bf00a5f99868df08689e0c65fbde890e9f1..fcf634f90149313e4122fad629863325968e6e7b 100644 (file)
@@ -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 629933232b2fb6c519d08adc1d298980a10bd15e..3735a4096869cced0182e0a7a313ee0592b1bb49 100644 (file)
--- 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;
 
index a09c590920aab310c87661e5218c022d575a8e68..8a67efacc605e3d63420975a490e5fc6beb1796a 100644 (file)
@@ -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 7cfe2a5bee55c1aab83cdc601ef00c515ea1183d..2a056a503f2131dfe17d3726e0e462ec2b2ecd2c 100644 (file)
--- 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 a50c13afb463b8a1a7254e09d837eb6baf31d923..af2c9e334e84f1ca0acee049e5d58af5a7fccffa 100644 (file)
--- 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) {
index 3d73d56db8e9bb695de8a300cac97e3e8e0c2a3d..507cd5c89cbbc2dc69a6722bd80fdf5b6c974321 100644 (file)
@@ -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);
index 7b4bbe51161bac6926e869efa3742859b81cd724..58524ccd1e7266ad97188750f0d36a936111f6c6 100644 (file)
@@ -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;
 
index e77fc65ce5723c46726bcebbc50449216177c976..d1629daa12b6ce7fcebd18be5e175d5e43a43b2f 100644 (file)
@@ -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;
index 2c77e9f880cd5a4b12684d7ac3f03fc23b3faad2..bf0f032da4c551dffcf9fa00db376a433cb5a2cb 100644 (file)
@@ -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;
index 35ca6f39843d6875558f61bbc42dde213c56eb2e..a9a7f14cad352539dc71b5af6ef893d12396d003 100644 (file)
@@ -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;
 
index 7e7831ce634e02f4a2e44c00e6161166cd162fd5..f30bdf886cb35d6c2eb0624f9c1ace859b1805e2 100644 (file)
@@ -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;
index 287eb4db6d2d3a6254e6b4618b2ac01cbcdc7bc9..ba9325649063b97a698591c2a2dbfb164077df13 100644 (file)
@@ -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;
index 7498ccb96934a36579058bf642ddbc420503959b..0ee5ca7632905151a0e283b6cd6a47f51a56ba54 100644 (file)
@@ -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;
 
index fb6258be0d9947b154213e8795d042621b5b4fbb..27e59012e7c5d60d2715714d011934464e5831f6 100644 (file)
@@ -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);
index 4c14ee680ac5b2cae8af404e7bcf4e68c7e75705..3b6cdf38b4969b0dcf196f389ad14c5c67b17d3a 100644 (file)
@@ -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;
index d0c600c10601b9d2fc390e440b065374be621cc8..a5933c512d953bac2f4a5c0e1b77b035ff8fc7d1 100644 (file)
@@ -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;
index 17a019a627a11e082ac2b0c22d7885d4a62f639d..c1b449b2a927ad1d87c6ce1b4d41fcbd1e5cb52f 100644 (file)
@@ -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;
index a6aa5ea762c5ea8f43c8fdb833137a80de6ebd76..f0da92b7d49528e6eeeb8f94d191732044e35c73 100644 (file)
@@ -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;