} else { \
event_errx(_EVENT_ERR_ABORT, \
"%s: noting an add on a non-setup event %p" \
- " (events: 0x%x, fd: %d, flags: 0x%x)", \
+ " (events: 0x%x, fd: "EV_SOCK_FMT \
+ ", flags: 0x%x)", \
__func__, (ev), (ev)->ev_events, \
- (ev)->ev_fd, (ev)->ev_flags); \
+ EV_SOCK_ARG((ev)->ev_fd), (ev)->ev_flags); \
} \
EVLOCK_UNLOCK(_event_debug_map_lock, 0); \
} \
} else { \
event_errx(_EVENT_ERR_ABORT, \
"%s: noting a del on a non-setup event %p" \
- " (events: 0x%x, fd: %d, flags: 0x%x)", \
+ " (events: 0x%x, fd: "EV_SOCK_FMT \
+ ", flags: 0x%x)", \
__func__, (ev), (ev)->ev_events, \
- (ev)->ev_fd, (ev)->ev_flags); \
+ EV_SOCK_ARG((ev)->ev_fd), (ev)->ev_flags); \
} \
EVLOCK_UNLOCK(_event_debug_map_lock, 0); \
} \
if (!dent) { \
event_errx(_EVENT_ERR_ABORT, \
"%s called on a non-initialized event %p" \
- " (events: 0x%x, fd: %d, flags: 0x%x)", \
+ " (events: 0x%x, fd: "EV_SOCK_FMT\
+ ", flags: 0x%x)", \
__func__, (ev), (ev)->ev_events, \
- (ev)->ev_fd, (ev)->ev_flags); \
+ EV_SOCK_ARG((ev)->ev_fd), (ev)->ev_flags); \
} \
EVLOCK_UNLOCK(_event_debug_map_lock, 0); \
} \
if (dent && dent->added) { \
event_errx(_EVENT_ERR_ABORT, \
"%s called on an already added event %p" \
- " (events: 0x%x, fd: %d, flags: 0x%x)", \
+ " (events: 0x%x, fd: "EV_SOCK_FMT", " \
+ "flags: 0x%x)", \
__func__, (ev), (ev)->ev_events, \
- (ev)->ev_fd, (ev)->ev_flags); \
+ EV_SOCK_ARG((ev)->ev_fd), (ev)->ev_flags); \
} \
EVLOCK_UNLOCK(_event_debug_map_lock, 0); \
} \
_event_debug_assert_is_setup(ev);
event_debug((
- "event_add: event: %p (fd %d), %s%s%scall %p",
+ "event_add: event: %p (fd "EV_SOCK_FMT"), %s%s%scall %p",
ev,
- (int)ev->ev_fd,
+ EV_SOCK_ARG(ev->ev_fd),
ev->ev_events & EV_READ ? "EV_READ " : " ",
ev->ev_events & EV_WRITE ? "EV_WRITE " : " ",
tv ? "EV_TIMEOUT " : " ",
struct event_base *base;
int res = 0, notify = 0;
- event_debug(("event_del: %p (fd %d), callback %p",
- ev, (int)ev->ev_fd, ev->ev_callback));
+ event_debug(("event_del: %p (fd "EV_SOCK_FMT"), callback %p",
+ ev, EV_SOCK_ARG(ev->ev_fd), ev->ev_callback));
/* An event without a base has not been added */
if (ev->ev_base == NULL)
{
struct event_base *base;
- event_debug(("event_active: %p (fd %d), res %d, callback %p",
- ev, (int)ev->ev_fd, (int)res, ev->ev_callback));
+ event_debug(("event_active: %p (fd "EV_SOCK_FMT"), res %d, callback %p",
+ ev, EV_SOCK_ARG(ev->ev_fd), (int)res, ev->ev_callback));
/* We get different kinds of events, add them together */
EVENT_BASE_ASSERT_LOCKED(base);
if (!(ev->ev_flags & queue)) {
- event_errx(1, "%s: %p(fd %d) not on queue %x", __func__,
- ev, ev->ev_fd, queue);
+ event_errx(1, "%s: %p(fd "EV_SOCK_FMT") not on queue %x", __func__,
+ ev, EV_SOCK_ARG(ev->ev_fd), queue);
return;
}
if (queue & EVLIST_ACTIVE)
return;
- event_errx(1, "%s: %p(fd %d) already on queue %x", __func__,
- ev, ev->ev_fd, queue);
+ event_errx(1, "%s: %p(fd "EV_SOCK_FMT") already on queue %x", __func__,
+ ev, EV_SOCK_ARG(ev->ev_fd), queue);
return;
}
int i;
fprintf(output, "Inserted events:\n");
TAILQ_FOREACH(e, &base->eventqueue, ev_next) {
- fprintf(output, " %p [fd %ld]%s%s%s%s%s\n",
- (void*)e, (long)e->ev_fd,
+ fprintf(output, " %p [fd "EV_SOCK_FMT"]%s%s%s%s%s\n",
+ (void*)e, EV_SOCK_ARG(e->ev_fd),
(e->ev_events&EV_READ)?" Read":"",
(e->ev_events&EV_WRITE)?" Write":"",
(e->ev_events&EV_SIGNAL)?" Signal":"",
continue;
fprintf(output, "Active events [priority %d]:\n", i);
TAILQ_FOREACH(e, &base->eventqueue, ev_next) {
- fprintf(output, " %p [fd %ld]%s%s%s%s\n",
- (void*)e, (long)e->ev_fd,
+ fprintf(output, " %p [fd "EV_SOCK_FMT"]%s%s%s%s\n",
+ (void*)e, EV_SOCK_ARG(e->ev_fd),
(e->ev_res&EV_READ)?" Read active":"",
(e->ev_res&EV_WRITE)?" Write active":"",
(e->ev_res&EV_SIGNAL)?" Signal active":"",
break;
default:
- event_warnx("%s: bad header on %d", __func__, fd);
+ event_warnx("%s: bad header on "EV_SOCK_FMT, __func__,
+ EV_SOCK_ARG(fd));
evhttp_connection_fail(evcon, EVCON_HTTP_INVALID_HEADER);
break;
}
evcon = evhttp_get_request_connection(http, fd, sa, salen);
if (evcon == NULL) {
- event_sock_warn(fd, "%s: cannot get connection on %d", __func__, fd);
+ event_sock_warn(fd, "%s: cannot get connection on "EV_SOCK_FMT,
+ __func__, EV_SOCK_ARG(fd));
evutil_closesocket(fd);
return;
}
#include <event.h>
static void
-fifo_read(int fd, short event, void *arg)
+fifo_read(evutil_socket_t fd, short event, void *arg)
{
char buf[255];
int len;
event_add(ev, NULL);
fprintf(stderr, "fifo_read called with fd: %d, event: %d, arg: %p\n",
- fd, event, arg);
+ (int)fd, event, arg);
#ifdef WIN32
len = ReadFile((HANDLE)fd, buf, sizeof(buf) - 1, &dwBytesRead, NULL);
/* Initalize one event */
#ifdef WIN32
- event_set(&evfifo, (int)socket, EV_READ, fifo_read, &evfifo);
+ event_set(&evfifo, (evutil_socket_t)socket, EV_READ, fifo_read, &evfifo);
#else
event_set(&evfifo, socket, EV_READ, fifo_read, &evfifo);
#endif
#ifdef WIN32
WORD wVersionRequested;
WSADATA wsaData;
- int err;
wVersionRequested = MAKEWORD(2, 2);
- err = WSAStartup(wVersionRequested, &wsaData);
+ (void) WSAStartup(wVersionRequested, &wsaData);
#endif
/* Initalize the event library */
#ifdef WIN32
WORD wVersionRequested;
WSADATA wsaData;
- int err;
wVersionRequested = MAKEWORD(2, 2);
- err = WSAStartup(wVersionRequested, &wsaData);
+ (void)WSAStartup(wVersionRequested, &wsaData);
#endif
if (argc == 2 && !strcmp(argv[1], "-p")) {
#include <evutil.h>
static int count, writes, fired;
-static int *pipes;
+static evutil_socket_t *pipes;
static int num_pipes, num_active, num_writes;
static struct event *events;
static void
read_cb(evutil_socket_t fd, short which, void *arg)
{
- long idx = (long) arg, widx = idx + 1;
+ ev_intptr_t idx = (ev_intptr_t) arg, widx = idx + 1;
u_char ch;
count += recv(fd, (char*)&ch, sizeof(ch), 0);
static struct timeval *
run_once(void)
{
- int *cp, space;
+ evutil_socket_t *cp, space;
long i;
static struct timeval ts, te;
for (cp = pipes, i = 0; i < num_pipes; i++, cp += 2) {
if (event_initialized(&events[i]))
event_del(&events[i]);
- event_set(&events[i], cp[0], EV_READ | EV_PERSIST, read_cb, (void *) i);
+ event_set(&events[i], cp[0], EV_READ | EV_PERSIST, read_cb, (void *)(ev_intptr_t) i);
event_add(&events[i], NULL);
}
#endif
int i, c;
struct timeval *tv;
- int *cp;
+ evutil_socket_t *cp;
#ifdef WIN32
WSADATA WSAData;
#endif
events = calloc(num_pipes, sizeof(struct event));
- pipes = calloc(num_pipes * 2, sizeof(int));
+ pipes = calloc(num_pipes * 2, sizeof(evutil_socket_t));
if (events == NULL || pipes == NULL) {
perror("malloc");
exit(1);
*/
static int fired;
-static int *pipes;
+static evutil_socket_t *pipes;
static struct event *events;
static void
read_cb(evutil_socket_t fd, short which, void *arg)
{
char ch;
- long idx = (long) arg;
+ evutil_socket_t sock = (evutil_socket_t)(ev_intptr_t)arg;
recv(fd, &ch, sizeof(ch), 0);
- if (idx >= 0) {
- if (send(idx, "e", 1, 0) < 0)
+ if (sock >= 0) {
+ if (send(sock, "e", 1, 0) < 0)
perror("send");
}
fired++;
static struct timeval *
run_once(int num_pipes)
{
- int *cp, i;
+ int i;
+ evutil_socket_t *cp;
static struct timeval ts, te, tv_timeout;
events = calloc(num_pipes, sizeof(struct event));
- pipes = calloc(num_pipes * 2, sizeof(int));
+ pipes = calloc(num_pipes * 2, sizeof(evutil_socket_t));
if (events == NULL || pipes == NULL) {
perror("malloc");
tv_timeout.tv_sec = 60;
for (cp = pipes, i = 0; i < num_pipes; i++, cp += 2) {
- long fd = i < num_pipes - 1 ? cp[3] : -1;
- event_set(&events[i], cp[0], EV_READ, read_cb, (void *) fd);
+ evutil_socket_t fd = i < num_pipes - 1 ? cp[3] : -1;
+ event_set(&events[i], cp[0], EV_READ, read_cb,
+ (void *)(ev_intptr_t)fd);
event_add(&events[i], &tv_timeout);
}
#include "event2/util.h"
#include "bufferevent-internal.h"
+#include "util-internal.h"
#ifdef WIN32
#include "iocp-internal.h"
#endif
if (what & BEV_EVENT_ERROR) {
s = bufferevent_getfd(bev);
err = evutil_socket_error_to_string(evutil_socket_geterror(s));
- TT_BLATHER(("connection failure on %d: %s", s, err));
+ TT_BLATHER(("connection failure on "EV_SOCK_FMT": %s",
+ EV_SOCK_ARG(s), err));
test_ok = 1;
} else {
TT_FAIL(("didn't fail? what %hd", what));
if (ttl < 0)
goto out;
for (i = 0; i < count; ++i) {
- const char *b = inet_ntop(AF_INET6, &in6_addrs[i], buf,sizeof(buf));
+ const char *b = evutil_inet_ntop(AF_INET6, &in6_addrs[i], buf,sizeof(buf));
if (b)
TT_BLATHER(("%s ", b));
else
char buf[INET6_ADDRSTRLEN+1];
if (memcmp(&in6_addrs[0].s6_addr, "abcdefghijklmnop", 16)
|| ttl != 123) {
- const char *b = inet_ntop(AF_INET6, &in6_addrs[0],buf,sizeof(buf));
+ const char *b = evutil_inet_ntop(AF_INET6, &in6_addrs[0],buf,sizeof(buf));
printf("Bad IPv6 response \"%s\" %d. ", b, ttl);
dns_ok = 0;
goto out;
memset(&local_outcome, 0, sizeof(local_outcome));
r = evdns_getaddrinfo(dns_base, "www.google.com", "80",
&hints, gai_cb, &local_outcome);
- tt_int_op(r,==,0);
+ tt_ptr_op(r,==,NULL);
tt_int_op(local_outcome.err,==,EVUTIL_EAI_NONAME);
tt_ptr_op(local_outcome.ai,==,NULL);
#ifdef WIN32
WORD wVersionRequested;
WSADATA wsaData;
- int err;
wVersionRequested = MAKEWORD(2, 2);
- err = WSAStartup(wVersionRequested, &wsaData);
+ (void) WSAStartup(wVersionRequested, &wsaData);
#endif
#ifndef WIN32
static void
open_ssl_bufevs(struct bufferevent **bev1_out, struct bufferevent **bev2_out,
struct event_base *base, int is_open, int flags, SSL *ssl1, SSL *ssl2,
- int *fd_pair, struct bufferevent **underlying_pair)
+ evutil_socket_t *fd_pair, struct bufferevent **underlying_pair)
{
int state1 = is_open ? BUFFEREVENT_SSL_OPEN :BUFFEREVENT_SSL_CONNECTING;
int state2 = is_open ? BUFFEREVENT_SSL_OPEN :BUFFEREVENT_SSL_ACCEPTING;
const int filter = strstr((char*)data->setup_data, "filter")!=NULL;
int flags = BEV_OPT_DEFER_CALLBACKS;
struct bufferevent *bev_ll[2] = { NULL, NULL };
- int *fd_pair = NULL;
+ evutil_socket_t *fd_pair = NULL;
tt_assert(cert);
tt_assert(key);
hints.ai_flags = EVUTIL_AI_NUMERICHOST;
r = evutil_getaddrinfo("www.google.com", "80", &hints, &ai);
tt_int_op(r, ==, EVUTIL_EAI_NONAME);
- tt_int_op(ai, ==, NULL);
+ tt_ptr_op(ai, ==, NULL);
/* Try symbolic service names wit AI_NUMERICSERV */
memset(&hints, 0, sizeof(hints));
struct bufferevent *bev1=NULL, *bev2=NULL;
char buffer[8333];
z_stream z_input, z_output;
- int i, pair[2]={-1,-1}, r;
+ int i, r;
+ evutil_socket_t pair[2] = {-1, -1};
(void)arg;
infilter_calls = outfilter_calls = readcb_finished = writecb_finished
#ifdef WIN32
WORD wVersionRequested;
WSADATA wsaData;
- int err;
wVersionRequested = MAKEWORD(2, 2);
- err = WSAStartup(wVersionRequested, &wsaData);
+ (void) WSAStartup(wVersionRequested, &wsaData);
#endif
if (evutil_socketpair(AF_UNIX, SOCK_STREAM, 0, pair) == -1)
return (1);
#ifdef WIN32
WORD wVersionRequested;
WSADATA wsaData;
- int err;
wVersionRequested = MAKEWORD(2, 2);
- err = WSAStartup(wVersionRequested, &wsaData);
+ (void) WSAStartup(wVersionRequested, &wsaData);
#endif
if (evutil_socketpair(AF_UNIX, SOCK_STREAM, 0, pair) == -1)
#ifdef WIN32
WORD wVersionRequested;
WSADATA wsaData;
- int err;
wVersionRequested = MAKEWORD(2, 2);
- err = WSAStartup(wVersionRequested, &wsaData);
+ (void) WSAStartup(wVersionRequested, &wsaData);
#endif
/* Initalize the event library */
#ifdef WIN32
WORD wVersionRequested = MAKEWORD(2,2);
WSADATA wsaData;
- int err;
- err = WSAStartup(wVersionRequested, &wsaData);
+ (void) WSAStartup(wVersionRequested, &wsaData);
#endif
#ifndef WIN32
#ifdef WIN32
WORD wVersionRequested;
WSADATA wsaData;
- int err;
wVersionRequested = MAKEWORD(2, 2);
- err = WSAStartup(wVersionRequested, &wsaData);
+ (void) WSAStartup(wVersionRequested, &wsaData);
#endif
/* Initalize the event library */
#ifdef WIN32
WORD wVersionRequested;
WSADATA wsaData;
- int err;
wVersionRequested = MAKEWORD(2, 2);
- err = WSAStartup(wVersionRequested, &wsaData);
+ (void) WSAStartup(wVersionRequested, &wsaData);
#endif
#ifndef WIN32
#endif
#endif
+#ifdef _WIN32
+#define EV_SOCK_FMT EV_I64_FMT
+#define EV_SOCK_ARG(x) EV_I64_ARG((x))
+#else
+#define EV_SOCK_FMT "%d"
+#define EV_SOCK_ARG(x) (x)
+#endif
+
#if defined(__STDC__) && defined(__STDC_VERSION__)
#if (__STDC_VERSION__ >= 199901L)
#define EV_SIZE_FMT "%zu"