mirror of
https://github.com/cuberite/libevent.git
synced 2025-09-07 19:31:01 -04:00
test/regress: cover a polling of invalid fd
Test that an event's callback is called if the fd is closed prior to being polled for activity. azat: make it run only for poll backend/method, and do not close fd twice
This commit is contained in:
parent
675974ce30
commit
cb0df5cfac
@ -2836,15 +2836,47 @@ end:
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef _WIN32
|
||||
/* You can't do this test on windows, since dup2 doesn't work on sockets */
|
||||
|
||||
static void
|
||||
dfd_cb(evutil_socket_t fd, short e, void *data)
|
||||
{
|
||||
*(int*)data = (int)e;
|
||||
}
|
||||
|
||||
static void
|
||||
test_event_closed_fd_poll(void *arg)
|
||||
{
|
||||
struct timeval tv;
|
||||
struct event *e;
|
||||
struct basic_test_data *data = (struct basic_test_data *)arg;
|
||||
int i = 0;
|
||||
|
||||
if (strcmp(event_base_get_method(data->base), "poll")) {
|
||||
tinytest_set_test_skipped_();
|
||||
return;
|
||||
}
|
||||
|
||||
e = event_new(data->base, data->pair[0], EV_READ, dfd_cb, &i);
|
||||
tt_assert(e);
|
||||
|
||||
tv.tv_sec = 0;
|
||||
tv.tv_usec = 500 * 1000;
|
||||
event_add(e, &tv);
|
||||
tt_assert(event_pending(e, EV_READ, NULL));
|
||||
close(data->pair[0]);
|
||||
data->pair[0] = -1; /** avoids double-close */
|
||||
event_base_loop(data->base, EVLOOP_ONCE);
|
||||
tt_int_op(i, ==, EV_READ);
|
||||
|
||||
end:
|
||||
if (e) {
|
||||
event_del(e);
|
||||
event_free(e);
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef _WIN32
|
||||
/* You can't do this test on windows, since dup2 doesn't work on sockets */
|
||||
|
||||
/* Regression test for our workaround for a fun epoll/linux related bug
|
||||
* where fd2 = dup(fd1); add(fd2); close(fd2); dup2(fd1,fd2); add(fd2)
|
||||
* will get you an EEXIST */
|
||||
@ -3381,6 +3413,9 @@ struct testcase_t main_testcases[] = {
|
||||
{ "event_once_never", test_event_once_never, TT_ISOLATED, &basic_setup, NULL },
|
||||
{ "event_pending", test_event_pending, TT_ISOLATED, &basic_setup,
|
||||
NULL },
|
||||
{ "event_closed_fd_poll", test_event_closed_fd_poll, TT_ISOLATED, &basic_setup,
|
||||
NULL },
|
||||
|
||||
#ifndef _WIN32
|
||||
{ "dup_fd", test_dup_fd, TT_ISOLATED, &basic_setup, NULL },
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user