Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion include/ela/ela.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,17 @@
*/

#include <stdint.h>
#include <sys/time.h>

#if !defined(_MSC_VER)
# include <sys/time.h>
#endif

/* GCC visibility */
#if defined(__GNUC__) && __GNUC__ >= 4 /** mkdoc:skip */
/** @internal */
# define ELA_EXPORT __attribute__ ((visibility("default")))
#elif defined(_MSC_VER) /** mkdoc:skip */
# define ELA_EXPORT __declspec(dllexport)
#else
/** @internal */
# define ELA_EXPORT
Expand Down
1 change: 1 addition & 0 deletions include/ela/libevent.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ struct event_base;

@returns an event loop, or NULL if libevent support is unavailable.
*/
ELA_EXPORT
struct ela_el *ela_libevent(struct event_base *event);

#endif
4 changes: 2 additions & 2 deletions src/ela.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
#include <string.h>

#if 0
# define DBG(a...) printf(a)
# define DBG(a, ...) printf(a, __VA_ARGS__)
#else
# define DBG(a...) do{}while(0)
# define DBG(a, ...) do{}while(0)
#endif

ela_error_t ela_set_fd(
Expand Down
37 changes: 30 additions & 7 deletions src/ela_libevent.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@

#include <event.h>

#if defined(__GNUC__)
#define INITIALIZER(f) \
static void f(void) __attribute__((constructor)); \
static void f(void)
#endif

struct libevent_mainloop
{
struct ela_el base;
Expand Down Expand Up @@ -79,6 +85,8 @@ ela_error_t _ela_event_set_fd(
{
struct libevent_mainloop *ctx = (struct libevent_mainloop *)ctx_;
ela_error_t err = 0;
uint32_t fd_flags
= (ELA_EVENT_ONCE|ELA_EVENT_READABLE|ELA_EVENT_WRITABLE);

(void)ctx;

Expand All @@ -88,9 +96,6 @@ ela_error_t _ela_event_set_fd(
if ( ela_flags & ELA_EVENT_READABLE ) ev_flags |= EV_READ;
if ( ela_flags & ELA_EVENT_WRITABLE ) ev_flags |= EV_WRITE;

const uint32_t fd_flags
= (ELA_EVENT_ONCE|ELA_EVENT_READABLE|ELA_EVENT_WRITABLE);

src->flags = (src->flags & ~fd_flags) | (ela_flags & fd_flags);

event_set(&src->event, fd, ev_flags, _ela_event_cb, src);
Expand Down Expand Up @@ -161,14 +166,14 @@ static
void _ela_event_run(struct ela_el *ctx_)
{
struct libevent_mainloop *ctx = (struct libevent_mainloop *)ctx_;
event_base_dispatch(ctx->event);
event_base_dispatch(ctx->event);
}

static
void _ela_event_exit(struct ela_el *ctx_)
{
struct libevent_mainloop *ctx = (struct libevent_mainloop *)ctx_;
event_base_loopbreak(ctx->event);
event_base_loopbreak(ctx->event);
}

static
Expand Down Expand Up @@ -241,8 +246,26 @@ struct ela_el *ela_libevent(struct event_base *event)
return &m->base;
}

__attribute__((constructor))
static void _ela_event_register(void)
#if defined(_MSC_VER)
BOOLEAN WINAPI
DllMain(IN HINSTANCE hDllHandle, IN DWORD nReason, IN LPVOID Reserved)
{
switch (nReason) {
case DLL_PROCESS_ATTACH:
//DisableThreadLibraryCalls(hDllHandle);
ela_register(&event_backend);
break;
case DLL_PROCESS_DETACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
break;
}

return TRUE;
}
#else
INITIALIZER(_ela_event_register)
{
ela_register(&event_backend);
}
#endif