Rename variables
This commit is contained in:
parent
5a38356cc4
commit
97920b443e
@ -10,40 +10,39 @@
|
|||||||
* redisContext to the read and write handlers. */
|
* redisContext to the read and write handlers. */
|
||||||
typedef struct redisEvents {
|
typedef struct redisEvents {
|
||||||
redisContext *context;
|
redisContext *context;
|
||||||
struct event read;
|
struct event rev, wev;
|
||||||
struct event write;
|
|
||||||
} redisEvents;
|
} redisEvents;
|
||||||
|
|
||||||
void redisLibEventRead(int fd, short event, void *arg) {
|
void redisLibEventRead(int fd, short event, void *arg) {
|
||||||
NOT_USED(fd); NOT_USED(event);
|
NOT_USED(fd); NOT_USED(event);
|
||||||
redisEvents *re = arg;
|
redisEvents *e = arg;
|
||||||
|
|
||||||
/* Always re-schedule read events */
|
/* Always re-schedule read events */
|
||||||
event_add(&re->read,NULL);
|
event_add(&e->rev,NULL);
|
||||||
|
|
||||||
if (redisBufferRead(re->context) == REDIS_ERR) {
|
if (redisBufferRead(e->context) == REDIS_ERR) {
|
||||||
/* Handle error. */
|
/* Handle error. */
|
||||||
printf("Read error: %s\n", re->context->error);
|
printf("Read error: %s\n", e->context->error);
|
||||||
} else {
|
} else {
|
||||||
/* Check replies. */
|
/* Check replies. */
|
||||||
redisProcessCallbacks(re->context);
|
redisProcessCallbacks(e->context);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void redisLibEventWrite(int fd, short event, void *arg) {
|
void redisLibEventWrite(int fd, short event, void *arg) {
|
||||||
NOT_USED(fd); NOT_USED(event);
|
NOT_USED(fd); NOT_USED(event);
|
||||||
redisEvents *re = arg;
|
redisEvents *e = arg;
|
||||||
int done = 0;
|
int done = 0;
|
||||||
|
|
||||||
if (redisBufferWrite(re->context, &done) == REDIS_ERR) {
|
if (redisBufferWrite(e->context, &done) == REDIS_ERR) {
|
||||||
/* Handle error */
|
/* Handle error */
|
||||||
printf("Write error: %s\n", re->context->error);
|
printf("Write error: %s\n", e->context->error);
|
||||||
} else {
|
} else {
|
||||||
/* Schedule write event again when writing is not done. */
|
/* Schedule write event again when writing is not done. */
|
||||||
if (!done) {
|
if (!done) {
|
||||||
event_add(&re->write,NULL);
|
event_add(&e->wev,NULL);
|
||||||
} else {
|
} else {
|
||||||
event_add(&re->read,NULL);
|
event_add(&e->rev,NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -53,7 +52,7 @@ void redisLibEventWrite(int fd, short event, void *arg) {
|
|||||||
void redisLibEventOnWrite(redisContext *c, void *privdata) {
|
void redisLibEventOnWrite(redisContext *c, void *privdata) {
|
||||||
NOT_USED(c);
|
NOT_USED(c);
|
||||||
redisEvents *e = privdata;
|
redisEvents *e = privdata;
|
||||||
event_add(&e->write,NULL);
|
event_add(&e->wev,NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Free the redisEvents struct when the context is free'd. */
|
/* Free the redisEvents struct when the context is free'd. */
|
||||||
@ -68,8 +67,8 @@ redisContext *redisLibEventConnect(const char *ip, int port) {
|
|||||||
e->context = redisConnectNonBlock(ip, port, NULL);
|
e->context = redisConnectNonBlock(ip, port, NULL);
|
||||||
redisSetCommandCallback(e->context, redisLibEventOnWrite, e);
|
redisSetCommandCallback(e->context, redisLibEventOnWrite, e);
|
||||||
redisSetFreeCallback(e->context, redisLibEventOnFree, e);
|
redisSetFreeCallback(e->context, redisLibEventOnFree, e);
|
||||||
event_set(&e->read, e->context->fd, EV_READ, redisLibEventRead, e);
|
event_set(&e->rev, e->context->fd, EV_READ, redisLibEventRead, e);
|
||||||
event_set(&e->write, e->context->fd, EV_WRITE, redisLibEventWrite, e);
|
event_set(&e->wev, e->context->fd, EV_WRITE, redisLibEventWrite, e);
|
||||||
return e->context;
|
return e->context;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user