summaryrefslogtreecommitdiff
path: root/adapters/libuv.h
diff options
context:
space:
mode:
Diffstat (limited to 'adapters/libuv.h')
-rw-r--r--adapters/libuv.h90
1 files changed, 45 insertions, 45 deletions
diff --git a/adapters/libuv.h b/adapters/libuv.h
index 317d5e1..e91b872 100644
--- a/adapters/libuv.h
+++ b/adapters/libuv.h
@@ -9,37 +9,37 @@
*
*/
-#ifndef __HIREDIS_LIBUV_H__
-#define __HIREDIS_LIBUV_H__
+#ifndef __HIREDICT_LIBUV_H__
+#define __HIREDICT_LIBUV_H__
#include <stdlib.h>
#include <uv.h>
#include "../hiredict.h"
#include "../async.h"
#include <string.h>
-typedef struct redisLibuvEvents {
- redisAsyncContext* context;
+typedef struct redictLibuvEvents {
+ redictAsyncContext* context;
uv_poll_t handle;
uv_timer_t timer;
int events;
-} redisLibuvEvents;
+} redictLibuvEvents;
-static void redisLibuvPoll(uv_poll_t* handle, int status, int events) {
- redisLibuvEvents* p = (redisLibuvEvents*)handle->data;
+static void redictLibuvPoll(uv_poll_t* handle, int status, int events) {
+ redictLibuvEvents* p = (redictLibuvEvents*)handle->data;
int ev = (status ? p->events : events);
if (p->context != NULL && (ev & UV_READABLE)) {
- redisAsyncHandleRead(p->context);
+ redictAsyncHandleRead(p->context);
}
if (p->context != NULL && (ev & UV_WRITABLE)) {
- redisAsyncHandleWrite(p->context);
+ redictAsyncHandleWrite(p->context);
}
}
-static void redisLibuvAddRead(void *privdata) {
- redisLibuvEvents* p = (redisLibuvEvents*)privdata;
+static void redictLibuvAddRead(void *privdata) {
+ redictLibuvEvents* p = (redictLibuvEvents*)privdata;
if (p->events & UV_READABLE) {
return;
@@ -47,25 +47,25 @@ static void redisLibuvAddRead(void *privdata) {
p->events |= UV_READABLE;
- uv_poll_start(&p->handle, p->events, redisLibuvPoll);
+ uv_poll_start(&p->handle, p->events, redictLibuvPoll);
}
-static void redisLibuvDelRead(void *privdata) {
- redisLibuvEvents* p = (redisLibuvEvents*)privdata;
+static void redictLibuvDelRead(void *privdata) {
+ redictLibuvEvents* p = (redictLibuvEvents*)privdata;
p->events &= ~UV_READABLE;
if (p->events) {
- uv_poll_start(&p->handle, p->events, redisLibuvPoll);
+ uv_poll_start(&p->handle, p->events, redictLibuvPoll);
} else {
uv_poll_stop(&p->handle);
}
}
-static void redisLibuvAddWrite(void *privdata) {
- redisLibuvEvents* p = (redisLibuvEvents*)privdata;
+static void redictLibuvAddWrite(void *privdata) {
+ redictLibuvEvents* p = (redictLibuvEvents*)privdata;
if (p->events & UV_WRITABLE) {
return;
@@ -73,24 +73,24 @@ static void redisLibuvAddWrite(void *privdata) {
p->events |= UV_WRITABLE;
- uv_poll_start(&p->handle, p->events, redisLibuvPoll);
+ uv_poll_start(&p->handle, p->events, redictLibuvPoll);
}
-static void redisLibuvDelWrite(void *privdata) {
- redisLibuvEvents* p = (redisLibuvEvents*)privdata;
+static void redictLibuvDelWrite(void *privdata) {
+ redictLibuvEvents* p = (redictLibuvEvents*)privdata;
p->events &= ~UV_WRITABLE;
if (p->events) {
- uv_poll_start(&p->handle, p->events, redisLibuvPoll);
+ uv_poll_start(&p->handle, p->events, redictLibuvPoll);
} else {
uv_poll_stop(&p->handle);
}
}
static void on_timer_close(uv_handle_t *handle) {
- redisLibuvEvents* p = (redisLibuvEvents*)handle->data;
+ redictLibuvEvents* p = (redictLibuvEvents*)handle->data;
p->timer.data = NULL;
if (!p->handle.data) {
// both timer and handle are closed
@@ -100,7 +100,7 @@ static void on_timer_close(uv_handle_t *handle) {
}
static void on_handle_close(uv_handle_t *handle) {
- redisLibuvEvents* p = (redisLibuvEvents*)handle->data;
+ redictLibuvEvents* p = (redictLibuvEvents*)handle->data;
p->handle.data = NULL;
if (!p->timer.data) {
// timer never started, or timer already destroyed
@@ -113,17 +113,17 @@ static void on_handle_close(uv_handle_t *handle) {
// see: https://github.com/libuv/libuv/blob/v0.11.23/include/uv.h
#if (UV_VERSION_MAJOR == 0 && UV_VERSION_MINOR < 11) || \
(UV_VERSION_MAJOR == 0 && UV_VERSION_MINOR == 11 && UV_VERSION_PATCH < 23)
-static void redisLibuvTimeout(uv_timer_t *timer, int status) {
+static void redictLibuvTimeout(uv_timer_t *timer, int status) {
(void)status; // unused
#else
-static void redisLibuvTimeout(uv_timer_t *timer) {
+static void redictLibuvTimeout(uv_timer_t *timer) {
#endif
- redisLibuvEvents *e = (redisLibuvEvents*)timer->data;
- redisAsyncHandleTimeout(e->context);
+ redictLibuvEvents *e = (redictLibuvEvents*)timer->data;
+ redictAsyncHandleTimeout(e->context);
}
-static void redisLibuvSetTimeout(void *privdata, struct timeval tv) {
- redisLibuvEvents* p = (redisLibuvEvents*)privdata;
+static void redictLibuvSetTimeout(void *privdata, struct timeval tv) {
+ redictLibuvEvents* p = (redictLibuvEvents*)privdata;
uint64_t millsec = tv.tv_sec * 1000 + tv.tv_usec / 1000.0;
if (!p->timer.data) {
@@ -135,11 +135,11 @@ static void redisLibuvSetTimeout(void *privdata, struct timeval tv) {
}
// updates the timeout if the timer has already started
// or start the timer
- uv_timer_start(&p->timer, redisLibuvTimeout, millsec, 0);
+ uv_timer_start(&p->timer, redictLibuvTimeout, millsec, 0);
}
-static void redisLibuvCleanup(void *privdata) {
- redisLibuvEvents* p = (redisLibuvEvents*)privdata;
+static void redictLibuvCleanup(void *privdata) {
+ redictLibuvEvents* p = (redictLibuvEvents*)privdata;
p->context = NULL; // indicate that context might no longer exist
if (p->timer.data) {
@@ -149,35 +149,35 @@ static void redisLibuvCleanup(void *privdata) {
}
-static int redisLibuvAttach(redisAsyncContext* ac, uv_loop_t* loop) {
- redisContext *c = &(ac->c);
+static int redictLibuvAttach(redictAsyncContext* ac, uv_loop_t* loop) {
+ redictContext *c = &(ac->c);
if (ac->ev.data != NULL) {
- return REDIS_ERR;
+ return REDICT_ERR;
}
- ac->ev.addRead = redisLibuvAddRead;
- ac->ev.delRead = redisLibuvDelRead;
- ac->ev.addWrite = redisLibuvAddWrite;
- ac->ev.delWrite = redisLibuvDelWrite;
- ac->ev.cleanup = redisLibuvCleanup;
- ac->ev.scheduleTimer = redisLibuvSetTimeout;
+ ac->ev.addRead = redictLibuvAddRead;
+ ac->ev.delRead = redictLibuvDelRead;
+ ac->ev.addWrite = redictLibuvAddWrite;
+ ac->ev.delWrite = redictLibuvDelWrite;
+ ac->ev.cleanup = redictLibuvCleanup;
+ ac->ev.scheduleTimer = redictLibuvSetTimeout;
- redisLibuvEvents* p = (redisLibuvEvents*)hi_malloc(sizeof(*p));
+ redictLibuvEvents* p = (redictLibuvEvents*)hi_malloc(sizeof(*p));
if (p == NULL)
- return REDIS_ERR;
+ return REDICT_ERR;
memset(p, 0, sizeof(*p));
if (uv_poll_init_socket(loop, &p->handle, c->fd) != 0) {
hi_free(p);
- return REDIS_ERR;
+ return REDICT_ERR;
}
ac->ev.data = p;
p->handle.data = p;
p->context = ac;
- return REDIS_OK;
+ return REDICT_OK;
}
#endif