summaryrefslogtreecommitdiff
path: root/adapters/poll.h
diff options
context:
space:
mode:
Diffstat (limited to 'adapters/poll.h')
-rw-r--r--adapters/poll.h102
1 files changed, 51 insertions, 51 deletions
diff --git a/adapters/poll.h b/adapters/poll.h
index 23b3eba..adc0aab 100644
--- a/adapters/poll.h
+++ b/adapters/poll.h
@@ -9,43 +9,43 @@
*
*/
-#ifndef HIREDIS_POLL_H
-#define HIREDIS_POLL_H
+#ifndef HIREDICT_POLL_H
+#define HIREDICT_POLL_H
#include "../async.h"
#include "../sockcompat.h"
#include <string.h> // for memset
#include <errno.h>
-/* Values to return from redisPollTick */
-#define REDIS_POLL_HANDLED_READ 1
-#define REDIS_POLL_HANDLED_WRITE 2
-#define REDIS_POLL_HANDLED_TIMEOUT 4
+/* Values to return from redictPollTick */
+#define REDICT_POLL_HANDLED_READ 1
+#define REDICT_POLL_HANDLED_WRITE 2
+#define REDICT_POLL_HANDLED_TIMEOUT 4
/* An adapter to allow manual polling of the async context by checking the state
* of the underlying file descriptor. Useful in cases where there is no formal
* IO event loop but regular ticking can be used, such as in game engines. */
-typedef struct redisPollEvents {
- redisAsyncContext *context;
- redisFD fd;
+typedef struct redictPollEvents {
+ redictAsyncContext *context;
+ redictFD fd;
char reading, writing;
char in_tick;
char deleted;
double deadline;
-} redisPollEvents;
+} redictPollEvents;
-static double redisPollTimevalToDouble(struct timeval *tv) {
+static double redictPollTimevalToDouble(struct timeval *tv) {
if (tv == NULL)
return 0.0;
return tv->tv_sec + tv->tv_usec / 1000000.00;
}
-static double redisPollGetNow(void) {
+static double redictPollGetNow(void) {
#ifndef _MSC_VER
struct timeval tv;
gettimeofday(&tv,NULL);
- return redisPollTimevalToDouble(&tv);
+ return redictPollTimevalToDouble(&tv);
#else
FILETIME ft;
ULARGE_INTEGER li;
@@ -59,14 +59,14 @@ static double redisPollGetNow(void) {
/* Poll for io, handling any pending callbacks. The timeout argument can be
* positive to wait for a maximum given time for IO, zero to poll, or negative
* to wait forever */
-static int redisPollTick(redisAsyncContext *ac, double timeout) {
+static int redictPollTick(redictAsyncContext *ac, double timeout) {
int reading, writing;
struct pollfd pfd;
int handled;
int ns;
int itimeout;
- redisPollEvents *e = (redisPollEvents*)ac->ev.data;
+ redictPollEvents *e = (redictPollEvents*)ac->ev.data;
if (!e)
return 0;
@@ -101,29 +101,29 @@ static int redisPollTick(redisAsyncContext *ac, double timeout) {
e->in_tick = 1;
if (ns) {
if (reading && (pfd.revents & POLLIN)) {
- redisAsyncHandleRead(ac);
- handled |= REDIS_POLL_HANDLED_READ;
+ redictAsyncHandleRead(ac);
+ handled |= REDICT_POLL_HANDLED_READ;
}
/* on Windows, connection failure is indicated with the Exception fdset.
* handle it the same as writable. */
if (writing && (pfd.revents & (POLLOUT | POLLERR))) {
/* context Read callback may have caused context to be deleted, e.g.
- by doing an redisAsyncDisconnect() */
+ by doing an redictAsyncDisconnect() */
if (!e->deleted) {
- redisAsyncHandleWrite(ac);
- handled |= REDIS_POLL_HANDLED_WRITE;
+ redictAsyncHandleWrite(ac);
+ handled |= REDICT_POLL_HANDLED_WRITE;
}
}
}
/* perform timeouts */
if (!e->deleted && e->deadline != 0.0) {
- double now = redisPollGetNow();
+ double now = redictPollGetNow();
if (now >= e->deadline) {
/* deadline has passed. disable timeout and perform callback */
e->deadline = 0.0;
- redisAsyncHandleTimeout(ac);
- handled |= REDIS_POLL_HANDLED_TIMEOUT;
+ redictAsyncHandleTimeout(ac);
+ handled |= REDICT_POLL_HANDLED_TIMEOUT;
}
}
@@ -136,28 +136,28 @@ static int redisPollTick(redisAsyncContext *ac, double timeout) {
return handled;
}
-static void redisPollAddRead(void *data) {
- redisPollEvents *e = (redisPollEvents*)data;
+static void redictPollAddRead(void *data) {
+ redictPollEvents *e = (redictPollEvents*)data;
e->reading = 1;
}
-static void redisPollDelRead(void *data) {
- redisPollEvents *e = (redisPollEvents*)data;
+static void redictPollDelRead(void *data) {
+ redictPollEvents *e = (redictPollEvents*)data;
e->reading = 0;
}
-static void redisPollAddWrite(void *data) {
- redisPollEvents *e = (redisPollEvents*)data;
+static void redictPollAddWrite(void *data) {
+ redictPollEvents *e = (redictPollEvents*)data;
e->writing = 1;
}
-static void redisPollDelWrite(void *data) {
- redisPollEvents *e = (redisPollEvents*)data;
+static void redictPollDelWrite(void *data) {
+ redictPollEvents *e = (redictPollEvents*)data;
e->writing = 0;
}
-static void redisPollCleanup(void *data) {
- redisPollEvents *e = (redisPollEvents*)data;
+static void redictPollCleanup(void *data) {
+ redictPollEvents *e = (redictPollEvents*)data;
/* if we are currently processing a tick, postpone deletion */
if (e->in_tick)
@@ -166,25 +166,25 @@ static void redisPollCleanup(void *data) {
hi_free(e);
}
-static void redisPollScheduleTimer(void *data, struct timeval tv)
+static void redictPollScheduleTimer(void *data, struct timeval tv)
{
- redisPollEvents *e = (redisPollEvents*)data;
- double now = redisPollGetNow();
- e->deadline = now + redisPollTimevalToDouble(&tv);
+ redictPollEvents *e = (redictPollEvents*)data;
+ double now = redictPollGetNow();
+ e->deadline = now + redictPollTimevalToDouble(&tv);
}
-static int redisPollAttach(redisAsyncContext *ac) {
- redisContext *c = &(ac->c);
- redisPollEvents *e;
+static int redictPollAttach(redictAsyncContext *ac) {
+ redictContext *c = &(ac->c);
+ redictPollEvents *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 = (redisPollEvents*)hi_malloc(sizeof(*e));
+ e = (redictPollEvents*)hi_malloc(sizeof(*e));
if (e == NULL)
- return REDIS_ERR;
+ return REDICT_ERR;
memset(e, 0, sizeof(*e));
e->context = ac;
@@ -194,14 +194,14 @@ static int redisPollAttach(redisAsyncContext *ac) {
e->deadline = 0.0;
/* Register functions to start/stop listening for events */
- ac->ev.addRead = redisPollAddRead;
- ac->ev.delRead = redisPollDelRead;
- ac->ev.addWrite = redisPollAddWrite;
- ac->ev.delWrite = redisPollDelWrite;
- ac->ev.scheduleTimer = redisPollScheduleTimer;
- ac->ev.cleanup = redisPollCleanup;
+ ac->ev.addRead = redictPollAddRead;
+ ac->ev.delRead = redictPollDelRead;
+ ac->ev.addWrite = redictPollAddWrite;
+ ac->ev.delWrite = redictPollDelWrite;
+ ac->ev.scheduleTimer = redictPollScheduleTimer;
+ ac->ev.cleanup = redictPollCleanup;
ac->ev.data = e;
- return REDIS_OK;
+ return REDICT_OK;
}
-#endif /* HIREDIS_POLL_H */
+#endif /* HIREDICT_POLL_H */