6 #ifndef RAVEN_SUPPORT_EVENTS_H 7 #define RAVEN_SUPPORT_EVENTS_H 12 #include <event2/event.h> 13 #include <event2/http.h> 15 #define MAKE_RAII(type) \ 17 struct type##_deleter {\ 18 void operator()(struct type* ob) {\ 23 typedef std::unique_ptr<struct type, type##_deleter> raii_##type 32 auto result = raii_event_base(event_base_new());
34 throw std::runtime_error(
"cannot create event_base");
38 inline raii_event
obtain_event(
struct event_base* base, evutil_socket_t s,
short events, event_callback_fn cb,
void* arg) {
39 return raii_event(event_new(base, s, events, cb, arg));
43 return raii_evhttp(evhttp_new(base));
47 return raii_evhttp_request(evhttp_request_new(cb, arg));
51 auto result = raii_evhttp_connection(evhttp_connection_base_new(base,
nullptr, host.c_str(), port));
53 throw std::runtime_error(
"create connection failed");
57 #endif // RAVEN_SUPPORT_EVENTS_H raii_event obtain_event(struct event_base *base, evutil_socket_t s, short events, event_callback_fn cb, void *arg)
raii_event_base obtain_event_base()
raii_evhttp obtain_evhttp(struct event_base *base)
raii_evhttp_request obtain_evhttp_request(void(*cb)(struct evhttp_request *, void *), void *arg)
raii_evhttp_connection obtain_evhttp_connection_base(struct event_base *base, std::string host, uint16_t port)