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.
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);
}
}
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;
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;
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 */
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);
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;
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;
/* 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. */
}
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);
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);
/** 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
#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 */
/**
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;
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);
if (!as->lev->base.enabled)
return 0;
- if (s == INVALID_SOCKET) {
+ if (s == EVUTIL_INVALID_SOCKET) {
error = WSAGetLastError();
goto report_err;
}
{
/* requires lock. */
SOCKET s = as->s;
- as->s = INVALID_SOCKET;
+ as->s = EVUTIL_INVALID_SOCKET;
closesocket(s);
}
&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. */
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 {
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);
}
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);
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);
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);
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);
;
}
-static int
+static evutil_socket_t
fake_listener_create(struct sockaddr_in *localhost)
{
struct sockaddr *sa = (struct sockaddr *)localhost;
char strport[NI_MAXSERV];
struct sockaddr *sa;
- int slen;
+ size_t slen;
evutil_socket_t fd;
memset(&ai, 0, sizeof(ai));
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);
}
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;
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);
/* 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);
/* 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);
{
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);
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);
bufferevent_free(bev);
evutil_closesocket(fd);
- fd = -1;
+ fd = EVUTIL_INVALID_SOCKET;
evhttp_free(http);
{
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);
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);
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);
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);
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);
/* 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);
{
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);
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);
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);
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);
bufferevent_free(bev);
if (use_timeout) {
evutil_closesocket(fd);
- fd = -1;
+ fd = EVUTIL_INVALID_SOCKET;
}
evhttp_free(http);
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);
{
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);
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);
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);
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);
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);
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);
event_base_dispatch(data->base);
+end:
if (bev)
bufferevent_free(bev);
if (http)
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);
event_base_dispatch(base);
- bufferevent_free(bev);
+end:
+ if (bev)
+ bufferevent_free(bev);
}
static void
http_request_extra_body_test(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;
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),
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);
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;
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;
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:
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]);
}
struct rwcount
{
- int fd;
+ evutil_socket_t fd;
size_t read;
size_t write;
};
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)