Skip to content

Instantly share code, notes, and snippets.

@azat
Created April 4, 2020 22:49
Show Gist options
  • Select an option

  • Save azat/7d7dbfe35167c227006937c66a240b7d to your computer and use it in GitHub Desktop.

Select an option

Save azat/7d7dbfe35167c227006937c66a240b7d to your computer and use it in GitHub Desktop.
// https://github.com/libevent/libevent/issues/984
#include <event2/event.h>
#include <event2/event_struct.h>
#include <unistd.h>
#include <cassert>
int main()
{
event_base* base = event_base_new();
event *ev1, *ev2;
int fd[2];
bool closed = false;
assert(!pipe(fd));
ev1 = event_new(base, fd[0], EV_ET | EV_CLOSED,
[](evutil_socket_t, short what, void* arg) -> void {
bool* closed = static_cast<bool*>(arg);
*closed = true;
assert(what != EV_READ);
},
&closed);
assert(ev1);
event_add(ev1, nullptr);
ev2 = event_new(base, fd[0], EV_ET | EV_READ,
[](evutil_socket_t, short what, void* arg) -> void {
assert(false);
}, nullptr);
assert(ev2);
event_add(ev2, nullptr);
close(fd[1]);
event_base_loop(base, EVLOOP_NONBLOCK);
assert(closed);
event_free(ev1);
event_free(ev2);
event_base_free(base);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment