Exemplo n.º 1
0
void
ub_event_base_free(struct ub_event_base* base)
{
#ifdef USE_MINI_EVENT
	event_base_free(AS_EVENT_BASE(base));
#elif defined(HAVE_EVENT_BASE_FREE) && defined(HAVE_EVENT_BASE_ONCE)
	/* only libevent 1.2+ has it, but in 1.2 it is broken - 
	   assertion fails on signal handling ev that is not deleted
 	   in libevent 1.3c (event_base_once appears) this is fixed. */
	event_base_free(AS_EVENT_BASE(base));
#endif /* HAVE_EVENT_BASE_FREE and HAVE_EVENT_BASE_ONCE */
}
Exemplo n.º 2
0
int
ub_timer_add(struct ub_event* ev, struct ub_event_base* base,
	void (*cb)(int, short, void*), void* arg, struct timeval* tv)
{
	event_set(AS_EVENT(ev), -1, UB_EV_TIMEOUT, cb, arg);
	if (event_base_set(AS_EVENT_BASE(base), AS_EVENT(ev)) != 0)
		return -1;
	return evtimer_add(AS_EVENT(ev), tv);
}
Exemplo n.º 3
0
struct event_base *
ub_libevent_get_event_base(struct ub_event_base* base)
{
#ifdef USE_MINI_EVENT
	return NULL;
#else
	return AS_EVENT_BASE(libevent_base);
#endif
}
Exemplo n.º 4
0
void
ub_get_event_sys(struct ub_event_base* base, const char** n, const char** s,
	const char** m)
{
#ifdef USE_WINSOCK
	(void)base;
	*n = "event";
	*s = "winsock";
	*m = "WSAWaitForMultipleEvents";
#elif defined(USE_MINI_EVENT)
	(void)base;
	*n = "mini-event";
	*s = "internal";
	*m = "select";
#else
	struct event_base* b = AS_EVENT_BASE(base);
	*s = event_get_version();
#  if defined(HAVE_EV_LOOP) || defined(HAVE_EV_DEFAULT_LOOP)
	*n = "libev";
	if (!b)
		b = (struct event_base*)ev_default_loop(EVFLAG_AUTO);
#    ifdef EVBACKEND_SELECT
	*m = ub_ev_backend2str(ev_backend((struct ev_loop*)b));
#    else
	*m = "not obtainable";
#    endif
#  elif defined(HAVE_EVENT_BASE_GET_METHOD)
	*n = "libevent";
	if (!b)
		b = event_base_new();
	*m = event_base_get_method(b);
#  else
	*n = "unknown";
	*m = "not obtainable";
	(void)b;
#  endif
#  ifdef HAVE_EVENT_BASE_FREE
	if (b && b != AS_EVENT_BASE(base))
		event_base_free(b);
#  endif
#endif
}
Exemplo n.º 5
0
struct ub_event*
ub_signal_new(struct ub_event_base* base, int fd,
	void (*cb)(int, short, void*), void* arg)
{
	struct event *ev = (struct event*)calloc(1, sizeof(struct event));

	if (!ev)
		return NULL;

	signal_set(ev, fd, cb, arg);
	if (event_base_set(AS_EVENT_BASE(base), ev) != 0) {
		free(ev);
		return NULL;
	}
	return AS_UB_EVENT(ev);
}
Exemplo n.º 6
0
struct ub_event*
ub_event_new(struct ub_event_base* base, int fd, short bits,
	void (*cb)(int, short, void*), void* arg)
{
	struct event *ev = (struct event*)calloc(1, sizeof(struct event));

	if (!ev)
		return NULL;

	event_set(ev, fd, NATIVE_BITS(bits), NATIVE_BITS_CB(cb), arg);
	if (event_base_set(AS_EVENT_BASE(base), ev) != 0) {
		free(ev);
		return NULL;
	}
	return AS_UB_EVENT(ev);
}
Exemplo n.º 7
0
struct ub_event*
ub_winsock_register_wsaevent(struct ub_event_base* base, void* wsaevent,
	void (*cb)(int, short, void*), void* arg)
{
#if defined(USE_MINI_EVENT) && defined(USE_WINSOCK)
	struct event *ev = (struct event*)calloc(1, sizeof(struct event));

	if (!ev)
		return NULL;

	if (winsock_register_wsaevent(AS_EVENT_BASE(base), ev, wsaevent, cb,
				arg))
		return AS_UB_EVENT(ev);
	free(ev);
	return NULL;
#else
	(void)base;
	(void)wsaevent;
	(void)cb;
	(void)arg;
	return NULL;
#endif
}
Exemplo n.º 8
0
int
ub_event_base_loopexit(struct ub_event_base* base)
{
	return event_base_loopexit(AS_EVENT_BASE(base), NULL);
}
Exemplo n.º 9
0
int
ub_event_base_dispatch(struct ub_event_base* base)
{
	return event_base_dispatch(AS_EVENT_BASE(base));
}