mirror of
https://github.com/libevent/libevent.git
synced 2025-01-09 00:56:20 +08:00
Unit tests for listener error callbacks
This commit is contained in:
parent
c4be8d82b3
commit
045eef4cde
@ -472,7 +472,7 @@ accepted_socket_cb(struct event_overlapped *o, ev_uintptr_t key, ev_ssize_t n, i
|
||||
/* Some error on accept that we couldn't actually handle. */
|
||||
event_sock_warn(as->s, "Unexpected error on AcceptEx");
|
||||
LeaveCriticalSection(&as->lock);
|
||||
/* XXXX recover better. */
|
||||
/* XXXX send error to user */
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -133,12 +133,51 @@ end:
|
||||
evconnlistener_free(listener2);
|
||||
}
|
||||
|
||||
static void
|
||||
errorcb(struct evconnlistener *lis, void *data_)
|
||||
{
|
||||
int *data = data_;
|
||||
*data = 1000;
|
||||
evconnlistener_disable(lis);
|
||||
}
|
||||
|
||||
static void
|
||||
regress_listener_error(void *arg)
|
||||
{
|
||||
struct basic_test_data *data = arg;
|
||||
struct event_base *base = data->base;
|
||||
struct evconnlistener *listener = NULL;
|
||||
int count = 1;
|
||||
|
||||
/* send, so that pair[0] will look 'readable'*/
|
||||
send(data->pair[1], "hello", 5, 0);
|
||||
|
||||
/* Start a listener with a bogus socket. */
|
||||
listener = evconnlistener_new(base, acceptcb, &count,
|
||||
LEV_OPT_CLOSE_ON_FREE|LEV_OPT_REUSEABLE, 0,
|
||||
data->pair[0]);
|
||||
tt_assert(listener);
|
||||
|
||||
evconnlistener_set_error_cb(listener, errorcb);
|
||||
|
||||
tt_assert(listener);
|
||||
|
||||
event_base_dispatch(base);
|
||||
tt_int_op(count,==,1000); /* set by error cb */
|
||||
|
||||
end:
|
||||
evconnlistener_free(listener);
|
||||
}
|
||||
|
||||
struct testcase_t listener_testcases[] = {
|
||||
|
||||
{ "randport", regress_pick_a_port, TT_FORK|TT_NEED_BASE,
|
||||
&basic_setup, NULL},
|
||||
|
||||
{ "error", regress_listener_error,
|
||||
TT_FORK|TT_NEED_BASE|TT_NEED_SOCKETPAIR,
|
||||
&basic_setup, NULL},
|
||||
|
||||
END_OF_TESTCASES,
|
||||
};
|
||||
|
||||
@ -147,5 +186,9 @@ struct testcase_t listener_iocp_testcases[] = {
|
||||
TT_FORK|TT_NEED_BASE|TT_ENABLE_IOCP,
|
||||
&basic_setup, NULL},
|
||||
|
||||
{ "error", regress_listener_error,
|
||||
TT_FORK|TT_NEED_BASE|TT_NEED_SOCKETPAIR|TT_ENABLE_IOCP,
|
||||
&basic_setup, NULL},
|
||||
|
||||
END_OF_TESTCASES,
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user