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.
This commit is contained in:
Nick Mathewson 2010-03-05 12:47:46 -05:00
parent 38b7b571c8
commit c7cf6f0049
18 changed files with 63 additions and 63 deletions

View File

@ -92,10 +92,10 @@ void event_changelist_remove_all(struct event_changelist *changelist,
void event_changelist_freemem(struct event_changelist *changelist); void event_changelist_freemem(struct event_changelist *changelist);
/** Implementation of eventop_add that queues the event in a 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); void *p);
/** Implementation of eventop_del that queues the event in a changelist. */ /** 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); void *p);
#endif #endif

View File

@ -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) #if defined(_EVENT_HAVE_EVENTFD) && defined(_EVENT_HAVE_SYS_EVENTFD_H)
static void 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; ev_uint64_t msg;

View 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_add(struct event_base *base, int signum, struct event *ev);
int evmap_signal_del(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); void *evmap_io_get_fdinfo(struct event_io_map *ctx, evutil_socket_t fd);

View File

@ -628,7 +628,7 @@ event_changelist_get_or_construct(struct event_changelist *changelist,
} }
int 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) void *p)
{ {
struct event_changelist *changelist = &base->changelist; struct event_changelist *changelist = &base->changelist;
@ -659,7 +659,7 @@ event_changelist_add(struct event_base *base, int fd, short old, short events,
} }
int 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) void *p)
{ {
struct event_changelist *changelist = &base->changelist; struct event_changelist *changelist = &base->changelist;

2
http.c
View File

@ -1698,7 +1698,7 @@ evhttp_read_header(struct evhttp_connection *evcon,
struct evhttp_request *req) struct evhttp_request *req)
{ {
enum message_read_status res; 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)); res = evhttp_parse_headers(req, bufferevent_get_input(evcon->bufev));
if (res == DATA_CORRUPTED || res == DATA_TOO_LONG) { if (res == DATA_CORRUPTED || res == DATA_TOO_LONG) {

View File

@ -168,7 +168,7 @@ main(int c, char **v) {
evdns_set_log_fn(logfn); evdns_set_log_fn(logfn);
if (servertest) { if (servertest) {
int sock; evutil_socket_t sock;
struct sockaddr_in my_addr; struct sockaddr_in my_addr;
sock = socket(PF_INET, SOCK_DGRAM, 0); sock = socket(PF_INET, SOCK_DGRAM, 0);
evutil_make_socket_nonblocking(sock); evutil_make_socket_nonblocking(sock);

View File

@ -33,7 +33,7 @@
int called = 0; int called = 0;
static void static void
signal_cb(int fd, short event, void *arg) signal_cb(evutil_socket_t fd, short event, void *arg)
{ {
struct event *signal = arg; struct event *signal = arg;

View File

@ -62,7 +62,7 @@ static struct event *events;
static void 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; long idx = (long) arg, widx = idx + 1;
u_char ch; u_char ch;

View File

@ -59,7 +59,7 @@ static int *pipes;
static struct event *events; static struct event *events;
static void static void
read_cb(int fd, short which, void *arg) read_cb(evutil_socket_t fd, short which, void *arg)
{ {
char ch; char ch;
long idx = (long) arg; long idx = (long) arg;

View File

@ -107,7 +107,7 @@ errorcb(struct bufferevent *b, short what, void *arg)
} }
static void static void
frob_socket(int sock) frob_socket(evutil_socket_t sock)
{ {
struct linger l; struct linger l;
int one = 1; int one = 1;
@ -121,7 +121,7 @@ frob_socket(int sock)
static int static int
launch_request(void) launch_request(void)
{ {
int sock; evutil_socket_t sock;
struct sockaddr_in sin; struct sockaddr_in sin;
struct bufferevent *b; struct bufferevent *b;

View File

@ -104,7 +104,7 @@ struct basic_cb_args
}; };
static void 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]; char buf[256];
int len; int len;
@ -123,7 +123,7 @@ simple_read_cb(int fd, short event, void *arg)
} }
static void 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]; char buf[256];
int len; int len;
@ -157,12 +157,12 @@ basic_read_cb(int fd, short event, void *data)
} }
static void static void
dummy_read_cb(int fd, short event, void *arg) dummy_read_cb(evutil_socket_t fd, short event, void *arg)
{ {
} }
static void static void
simple_write_cb(int fd, short event, void *arg) simple_write_cb(evutil_socket_t fd, short event, void *arg)
{ {
int len; int len;
@ -174,7 +174,7 @@ simple_write_cb(int fd, short event, void *arg)
} }
static void 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; struct event *ev = arg;
int len; int len;
@ -207,7 +207,7 @@ multiple_write_cb(int fd, short event, void *arg)
} }
static void 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; struct event *ev = arg;
int len; int len;
@ -229,7 +229,7 @@ multiple_read_cb(int fd, short event, void *arg)
} }
static void static void
timeout_cb(int fd, short event, void *arg) timeout_cb(evutil_socket_t fd, short event, void *arg)
{ {
struct timeval tv; struct timeval tv;
int diff; int diff;
@ -254,7 +254,7 @@ struct both {
}; };
static void 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; struct both *both = arg;
char buf[128]; char buf[128];
@ -272,7 +272,7 @@ combined_read_cb(int fd, short event, void *arg)
} }
static void 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; struct both *both = arg;
char buf[128]; char buf[128];
@ -380,7 +380,7 @@ test_simplewrite(void)
} }
static 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) if (++called == 2)
test_ok = 1; test_ok = 1;
@ -517,7 +517,7 @@ test_simpletimeout(void)
} }
static 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; int *count = arg;
@ -556,14 +556,14 @@ struct persist_active_timeout_called {
}; };
static void static void
activate_cb(int fd, short event, void *arg) activate_cb(evutil_socket_t fd, short event, void *arg)
{ {
struct event *ev = arg; struct event *ev = arg;
event_active(ev, EV_READ, 1); event_active(ev, EV_READ, 1);
} }
static void 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; struct persist_active_timeout_called *c = arg;
if (c->n < 15) { if (c->n < 15) {
@ -624,7 +624,7 @@ struct common_timeout_info {
}; };
static void 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; struct common_timeout_info *ti = arg;
++ti->count; ++ti->count;
@ -709,12 +709,12 @@ end:
} }
#ifndef WIN32 #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; extern struct event_base *current_base;
static void 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; struct timeval tv;
int *pint = arg; int *pint = arg;
@ -803,7 +803,7 @@ signal_cb_sa(int sig)
} }
static void static void
signal_cb(int fd, short event, void *arg) signal_cb(evutil_socket_t fd, short event, void *arg)
{ {
struct event *ev = arg; struct event *ev = arg;
@ -1055,7 +1055,7 @@ signal_cb_swp(int sig, short event, void *arg)
event_loopexit(NULL); event_loopexit(NULL);
} }
static void 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) { if (called == -1) {
struct timeval tv = {5, 0}; struct timeval tv = {5, 0};
@ -1261,14 +1261,14 @@ end:
} }
static void static void
break_cb(int fd, short events, void *arg) break_cb(evutil_socket_t fd, short events, void *arg)
{ {
test_ok = 1; test_ok = 1;
event_loopbreak(); event_loopbreak();
} }
static void static void
fail_cb(int fd, short events, void *arg) fail_cb(evutil_socket_t fd, short events, void *arg)
{ {
test_ok = 0; test_ok = 0;
} }
@ -1302,7 +1302,7 @@ end:
static struct event *readd_test_event_last_added = NULL; static struct event *readd_test_event_last_added = NULL;
static void 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]; char buf[256];
int len; int len;
@ -1362,7 +1362,7 @@ struct test_pri_event {
}; };
static void 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 test_pri_event *pri = arg;
struct timeval tv; struct timeval tv;
@ -1440,7 +1440,7 @@ test_priorities(void)
static 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) if (event & EV_READ)
test_ok |= 1; 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); int evtag_decode_tag(ev_uint32_t *pnumber, struct evbuffer *evbuf);
static void 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]; char buf[256];
int len; int len;
@ -1845,7 +1845,7 @@ end:
} }
static void 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); tt_int_op(event, ==, EV_READ);
called += 1; called += 1;
@ -1854,7 +1854,7 @@ end:
} }
static void 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); tt_int_op(event, ==, EV_TIMEOUT);
called += 100; called += 100;
@ -2003,7 +2003,7 @@ end:
#endif #endif
static void 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; int *calledp = arg;
*calledp += 1; *calledp += 1;

View File

@ -52,7 +52,7 @@
static int was_et = 0; static int was_et = 0;
static void static void
read_cb(int fd, short event, void *arg) read_cb(evutil_socket_t fd, short event, void *arg)
{ {
char buf; char buf;
int len; int len;

View File

@ -127,7 +127,7 @@ http_connect(const char *address, u_short port)
#endif #endif
struct sockaddr *sa; struct sockaddr *sa;
int slen; int slen;
int fd; evutil_socket_t fd;
#ifdef WIN32 #ifdef WIN32
if (!(he = gethostbyname(address))) { if (!(he = gethostbyname(address))) {
@ -314,7 +314,7 @@ http_chunked_cb(struct evhttp_request *req, void *arg)
} }
static void 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; struct bufferevent *bev = arg;
const char *http_request = "host\r\n" const char *http_request = "host\r\n"
@ -328,7 +328,7 @@ http_basic_test(void)
{ {
struct timeval tv; struct timeval tv;
struct bufferevent *bev; struct bufferevent *bev;
int fd; evutil_socket_t fd;
const char *http_request; const char *http_request;
short port = -1; short port = -1;
@ -485,7 +485,7 @@ http_badreq_readcb(struct bufferevent *bev, void *arg)
} }
static void 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_debug(("%s: called (what=%04x, arg=%p)", __func__, what, arg));
event_loopexit(NULL); event_loopexit(NULL);
@ -496,7 +496,7 @@ http_bad_request_test(void)
{ {
struct timeval tv; struct timeval tv;
struct bufferevent *bev; struct bufferevent *bev;
int fd; evutil_socket_t fd;
const char *http_request; const char *http_request;
short port = -1; short port = -1;
@ -609,7 +609,7 @@ static void
http_delete_test(void) http_delete_test(void)
{ {
struct bufferevent *bev; struct bufferevent *bev;
int fd; evutil_socket_t fd;
const char *http_request; const char *http_request;
short port = -1; short port = -1;
@ -758,7 +758,7 @@ http_connection_async_test(void)
/* Add ourself as the only nameserver, and make sure we really are /* Add ourself as the only nameserver, and make sure we really are
* the only nameserver. */ * 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); evdns_base_nameserver_ip_add(dns_base, address);
test_ok = 0; test_ok = 0;
@ -1440,7 +1440,7 @@ static void
http_failure_test(void) http_failure_test(void)
{ {
struct bufferevent *bev; struct bufferevent *bev;
int fd; evutil_socket_t fd;
const char *http_request; const char *http_request;
short port = -1; short port = -1;
@ -1486,7 +1486,7 @@ close_detect_done(struct evhttp_request *req, void *arg)
} }
static void 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_connection *evcon = arg;
struct evhttp_request *req; struct evhttp_request *req;
@ -1659,7 +1659,7 @@ http_base_test(void)
{ {
struct event_base *tmp; struct event_base *tmp;
struct bufferevent *bev; struct bufferevent *bev;
int fd; evutil_socket_t fd;
const char *http_request; const char *http_request;
short port = -1; short port = -1;
@ -1727,7 +1727,7 @@ static void
http_incomplete_writecb(struct bufferevent *bev, void *arg) http_incomplete_writecb(struct bufferevent *bev, void *arg)
{ {
if (arg != NULL) { if (arg != NULL) {
int fd = *(int *)arg; evutil_socket_t fd = *(evutil_socket_t *)arg;
/* terminate the write side to simulate EOF */ /* terminate the write side to simulate EOF */
shutdown(fd, SHUT_WR); shutdown(fd, SHUT_WR);
} }
@ -1742,7 +1742,7 @@ static void
_http_incomplete_test(int use_timeout) _http_incomplete_test(int use_timeout)
{ {
struct bufferevent *bev; struct bufferevent *bev;
int fd; evutil_socket_t fd;
const char *http_request; const char *http_request;
short port = -1; short port = -1;
struct timeval tv_start, tv_end; struct timeval tv_start, tv_end;
@ -1944,7 +1944,7 @@ static void
http_chunk_out_test(void) http_chunk_out_test(void)
{ {
struct bufferevent *bev; struct bufferevent *bev;
int fd; evutil_socket_t fd;
const char *http_request; const char *http_request;
short port = -1; short port = -1;
struct timeval tv_start, tv_end; struct timeval tv_start, tv_end;
@ -2198,7 +2198,7 @@ http_connection_retry_done(struct evhttp_request *req, void *arg)
} }
static void 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; short port = -1;
http = http_setup(&port, NULL); http = http_setup(&port, NULL);
@ -2522,7 +2522,7 @@ http_data_length_constraints_test(void)
struct terminate_state { struct terminate_state {
struct evhttp_request *req; struct evhttp_request *req;
struct bufferevent *bev; struct bufferevent *bev;
int fd; evutil_socket_t fd;
int gotclosecb: 1; int gotclosecb: 1;
} terminate_state; } terminate_state;
@ -2577,7 +2577,7 @@ terminate_chunked_cb(struct evhttp_request *req, void *arg)
} }
static void 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; struct terminate_state *state = arg;
bufferevent_free(state->bev); bufferevent_free(state->bev);
@ -2599,7 +2599,7 @@ http_terminate_chunked_test(void)
struct timeval tv; struct timeval tv;
const char *http_request; const char *http_request;
short port = -1; short port = -1;
int fd = -1; evutil_socket_t fd = -1;
test_ok = 0; test_ok = 0;

View File

@ -46,7 +46,7 @@ struct cond_wait {
}; };
static void 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; struct cond_wait *cw = arg;
assert(pthread_mutex_lock(&cw->lock) == 0); assert(pthread_mutex_lock(&cw->lock) == 0);

View File

@ -587,7 +587,7 @@ struct _rpc_hook_ctx {
static int hook_pause_cb_called=0; static int hook_pause_cb_called=0;
static void 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; struct _rpc_hook_ctx *ctx = arg;
++hook_pause_cb_called; ++hook_pause_cb_called;

View File

@ -34,7 +34,7 @@ int test_okay = 1;
int called = 0; int called = 0;
static void static void
read_cb(int fd, short event, void *arg) read_cb(evutil_socket_t fd, short event, void *arg)
{ {
char buf[256]; char buf[256];
int len; int len;

View File

@ -37,7 +37,7 @@ rand_int(int n)
} }
static void static void
time_cb(int fd, short event, void *arg) time_cb(evutil_socket_t fd, short event, void *arg)
{ {
struct timeval tv; struct timeval tv;
int i, j; int i, j;

View File

@ -38,7 +38,7 @@ int test_okay = 1;
int called = 0; int called = 0;
static void 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"; const char *test = "test string";
int len; int len;