summaryrefslogtreecommitdiff
path: root/adapters/libsdevent.h
diff options
context:
space:
mode:
Diffstat (limited to 'adapters/libsdevent.h')
-rw-r--r--adapters/libsdevent.h104
1 files changed, 52 insertions, 52 deletions
diff --git a/adapters/libsdevent.h b/adapters/libsdevent.h
index dc4249a..103d69e 100644
--- a/adapters/libsdevent.h
+++ b/adapters/libsdevent.h
@@ -9,26 +9,26 @@
*
*/
-#ifndef HIREDIS_LIBSDEVENT_H
-#define HIREDIS_LIBSDEVENT_H
+#ifndef HIREDICT_LIBSDEVENT_H
+#define HIREDICT_LIBSDEVENT_H
#include <systemd/sd-event.h>
#include "../hiredict.h"
#include "../async.h"
-#define REDIS_LIBSDEVENT_DELETED 0x01
-#define REDIS_LIBSDEVENT_ENTERED 0x02
+#define REDICT_LIBSDEVENT_DELETED 0x01
+#define REDICT_LIBSDEVENT_ENTERED 0x02
-typedef struct redisLibsdeventEvents {
- redisAsyncContext *context;
+typedef struct redictLibsdeventEvents {
+ redictAsyncContext *context;
struct sd_event *event;
struct sd_event_source *fdSource;
struct sd_event_source *timerSource;
int fd;
short flags;
short state;
-} redisLibsdeventEvents;
+} redictLibsdeventEvents;
-static void redisLibsdeventDestroy(redisLibsdeventEvents *e) {
+static void redictLibsdeventDestroy(redictLibsdeventEvents *e) {
if (e->fdSource) {
e->fdSource = sd_event_source_disable_unref(e->fdSource);
}
@@ -39,43 +39,43 @@ static void redisLibsdeventDestroy(redisLibsdeventEvents *e) {
hi_free(e);
}
-static int redisLibsdeventTimeoutHandler(sd_event_source *s, uint64_t usec, void *userdata) {
+static int redictLibsdeventTimeoutHandler(sd_event_source *s, uint64_t usec, void *userdata) {
((void)s);
((void)usec);
- redisLibsdeventEvents *e = (redisLibsdeventEvents*)userdata;
- redisAsyncHandleTimeout(e->context);
+ redictLibsdeventEvents *e = (redictLibsdeventEvents*)userdata;
+ redictAsyncHandleTimeout(e->context);
return 0;
}
-static int redisLibsdeventHandler(sd_event_source *s, int fd, uint32_t event, void *userdata) {
+static int redictLibsdeventHandler(sd_event_source *s, int fd, uint32_t event, void *userdata) {
((void)s);
((void)fd);
- redisLibsdeventEvents *e = (redisLibsdeventEvents*)userdata;
- e->state |= REDIS_LIBSDEVENT_ENTERED;
+ redictLibsdeventEvents *e = (redictLibsdeventEvents*)userdata;
+ e->state |= REDICT_LIBSDEVENT_ENTERED;
-#define CHECK_DELETED() if (e->state & REDIS_LIBSDEVENT_DELETED) {\
- redisLibsdeventDestroy(e);\
+#define CHECK_DELETED() if (e->state & REDICT_LIBSDEVENT_DELETED) {\
+ redictLibsdeventDestroy(e);\
return 0; \
}
- if ((event & EPOLLIN) && e->context && (e->state & REDIS_LIBSDEVENT_DELETED) == 0) {
- redisAsyncHandleRead(e->context);
+ if ((event & EPOLLIN) && e->context && (e->state & REDICT_LIBSDEVENT_DELETED) == 0) {
+ redictAsyncHandleRead(e->context);
CHECK_DELETED();
}
- if ((event & EPOLLOUT) && e->context && (e->state & REDIS_LIBSDEVENT_DELETED) == 0) {
- redisAsyncHandleWrite(e->context);
+ if ((event & EPOLLOUT) && e->context && (e->state & REDICT_LIBSDEVENT_DELETED) == 0) {
+ redictAsyncHandleWrite(e->context);
CHECK_DELETED();
}
- e->state &= ~REDIS_LIBSDEVENT_ENTERED;
+ e->state &= ~REDICT_LIBSDEVENT_ENTERED;
#undef CHECK_DELETED
return 0;
}
-static void redisLibsdeventAddRead(void *userdata) {
- redisLibsdeventEvents *e = (redisLibsdeventEvents*)userdata;
+static void redictLibsdeventAddRead(void *userdata) {
+ redictLibsdeventEvents *e = (redictLibsdeventEvents*)userdata;
if (e->flags & EPOLLIN) {
return;
@@ -86,12 +86,12 @@ static void redisLibsdeventAddRead(void *userdata) {
if (e->flags & EPOLLOUT) {
sd_event_source_set_io_events(e->fdSource, e->flags);
} else {
- sd_event_add_io(e->event, &e->fdSource, e->fd, e->flags, redisLibsdeventHandler, e);
+ sd_event_add_io(e->event, &e->fdSource, e->fd, e->flags, redictLibsdeventHandler, e);
}
}
-static void redisLibsdeventDelRead(void *userdata) {
- redisLibsdeventEvents *e = (redisLibsdeventEvents*)userdata;
+static void redictLibsdeventDelRead(void *userdata) {
+ redictLibsdeventEvents *e = (redictLibsdeventEvents*)userdata;
e->flags &= ~EPOLLIN;
@@ -102,8 +102,8 @@ static void redisLibsdeventDelRead(void *userdata) {
}
}
-static void redisLibsdeventAddWrite(void *userdata) {
- redisLibsdeventEvents *e = (redisLibsdeventEvents*)userdata;
+static void redictLibsdeventAddWrite(void *userdata) {
+ redictLibsdeventEvents *e = (redictLibsdeventEvents*)userdata;
if (e->flags & EPOLLOUT) {
return;
@@ -114,12 +114,12 @@ static void redisLibsdeventAddWrite(void *userdata) {
if (e->flags & EPOLLIN) {
sd_event_source_set_io_events(e->fdSource, e->flags);
} else {
- sd_event_add_io(e->event, &e->fdSource, e->fd, e->flags, redisLibsdeventHandler, e);
+ sd_event_add_io(e->event, &e->fdSource, e->fd, e->flags, redictLibsdeventHandler, e);
}
}
-static void redisLibsdeventDelWrite(void *userdata) {
- redisLibsdeventEvents *e = (redisLibsdeventEvents*)userdata;
+static void redictLibsdeventDelWrite(void *userdata) {
+ redictLibsdeventEvents *e = (redictLibsdeventEvents*)userdata;
e->flags &= ~EPOLLOUT;
@@ -130,43 +130,43 @@ static void redisLibsdeventDelWrite(void *userdata) {
}
}
-static void redisLibsdeventCleanup(void *userdata) {
- redisLibsdeventEvents *e = (redisLibsdeventEvents*)userdata;
+static void redictLibsdeventCleanup(void *userdata) {
+ redictLibsdeventEvents *e = (redictLibsdeventEvents*)userdata;
if (!e) {
return;
}
- if (e->state & REDIS_LIBSDEVENT_ENTERED) {
- e->state |= REDIS_LIBSDEVENT_DELETED;
+ if (e->state & REDICT_LIBSDEVENT_ENTERED) {
+ e->state |= REDICT_LIBSDEVENT_DELETED;
} else {
- redisLibsdeventDestroy(e);
+ redictLibsdeventDestroy(e);
}
}
-static void redisLibsdeventSetTimeout(void *userdata, struct timeval tv) {
- redisLibsdeventEvents *e = (redisLibsdeventEvents *)userdata;
+static void redictLibsdeventSetTimeout(void *userdata, struct timeval tv) {
+ redictLibsdeventEvents *e = (redictLibsdeventEvents *)userdata;
uint64_t usec = tv.tv_sec * 1000000 + tv.tv_usec;
if (!e->timerSource) {
- sd_event_add_time_relative(e->event, &e->timerSource, CLOCK_MONOTONIC, usec, 1, redisLibsdeventTimeoutHandler, e);
+ sd_event_add_time_relative(e->event, &e->timerSource, CLOCK_MONOTONIC, usec, 1, redictLibsdeventTimeoutHandler, e);
} else {
sd_event_source_set_time_relative(e->timerSource, usec);
}
}
-static int redisLibsdeventAttach(redisAsyncContext *ac, struct sd_event *event) {
- redisContext *c = &(ac->c);
- redisLibsdeventEvents *e;
+static int redictLibsdeventAttach(redictAsyncContext *ac, struct sd_event *event) {
+ redictContext *c = &(ac->c);
+ redictLibsdeventEvents *e;
/* Nothing should be attached when something is already attached */
if (ac->ev.data != NULL)
- return REDIS_ERR;
+ return REDICT_ERR;
/* Create container for context and r/w events */
- e = (redisLibsdeventEvents*)hi_calloc(1, sizeof(*e));
+ e = (redictLibsdeventEvents*)hi_calloc(1, sizeof(*e));
if (e == NULL)
- return REDIS_ERR;
+ return REDICT_ERR;
/* Initialize and increase event refcount */
e->context = ac;
@@ -175,14 +175,14 @@ static int redisLibsdeventAttach(redisAsyncContext *ac, struct sd_event *event)
sd_event_ref(event);
/* Register functions to start/stop listening for events */
- ac->ev.addRead = redisLibsdeventAddRead;
- ac->ev.delRead = redisLibsdeventDelRead;
- ac->ev.addWrite = redisLibsdeventAddWrite;
- ac->ev.delWrite = redisLibsdeventDelWrite;
- ac->ev.cleanup = redisLibsdeventCleanup;
- ac->ev.scheduleTimer = redisLibsdeventSetTimeout;
+ ac->ev.addRead = redictLibsdeventAddRead;
+ ac->ev.delRead = redictLibsdeventDelRead;
+ ac->ev.addWrite = redictLibsdeventAddWrite;
+ ac->ev.delWrite = redictLibsdeventDelWrite;
+ ac->ev.cleanup = redictLibsdeventCleanup;
+ ac->ev.scheduleTimer = redictLibsdeventSetTimeout;
ac->ev.data = e;
- return REDIS_OK;
+ return REDICT_OK;
}
#endif