Skip to content

Commit

Permalink
Merge remote-tracking branch 'antirez/master'
Browse files Browse the repository at this point in the history
Conflicts:
	hiredis.c
	net.c
Resolved
  • Loading branch information
koenvandesande committed Feb 2, 2012
2 parents ba399e3 + d5d8843 commit b2b9bb4
Show file tree
Hide file tree
Showing 8 changed files with 212 additions and 121 deletions.
20 changes: 11 additions & 9 deletions adapters/ae.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#ifndef __HIREDIS_AE_H__
#define __HIREDIS_AE_H__
#include <sys/types.h>
#include <ae.h>
#include "../hiredis.h"
Expand All @@ -10,21 +12,21 @@ typedef struct redisAeEvents {
int reading, writing;
} redisAeEvents;

void redisAeReadEvent(aeEventLoop *el, int fd, void *privdata, int mask) {
static void redisAeReadEvent(aeEventLoop *el, int fd, void *privdata, int mask) {
((void)el); ((void)fd); ((void)mask);

redisAeEvents *e = (redisAeEvents*)privdata;
redisAsyncHandleRead(e->context);
}

void redisAeWriteEvent(aeEventLoop *el, int fd, void *privdata, int mask) {
static void redisAeWriteEvent(aeEventLoop *el, int fd, void *privdata, int mask) {
((void)el); ((void)fd); ((void)mask);

redisAeEvents *e = (redisAeEvents*)privdata;
redisAsyncHandleWrite(e->context);
}

void redisAeAddRead(void *privdata) {
static void redisAeAddRead(void *privdata) {
redisAeEvents *e = (redisAeEvents*)privdata;
aeEventLoop *loop = e->loop;
if (!e->reading) {
Expand All @@ -33,7 +35,7 @@ void redisAeAddRead(void *privdata) {
}
}

void redisAeDelRead(void *privdata) {
static void redisAeDelRead(void *privdata) {
redisAeEvents *e = (redisAeEvents*)privdata;
aeEventLoop *loop = e->loop;
if (e->reading) {
Expand All @@ -42,7 +44,7 @@ void redisAeDelRead(void *privdata) {
}
}

void redisAeAddWrite(void *privdata) {
static void redisAeAddWrite(void *privdata) {
redisAeEvents *e = (redisAeEvents*)privdata;
aeEventLoop *loop = e->loop;
if (!e->writing) {
Expand All @@ -51,7 +53,7 @@ void redisAeAddWrite(void *privdata) {
}
}

void redisAeDelWrite(void *privdata) {
static void redisAeDelWrite(void *privdata) {
redisAeEvents *e = (redisAeEvents*)privdata;
aeEventLoop *loop = e->loop;
if (e->writing) {
Expand All @@ -60,14 +62,14 @@ void redisAeDelWrite(void *privdata) {
}
}

void redisAeCleanup(void *privdata) {
static void redisAeCleanup(void *privdata) {
redisAeEvents *e = (redisAeEvents*)privdata;
redisAeDelRead(privdata);
redisAeDelWrite(privdata);
free(e);
}

int redisAeAttach(aeEventLoop *loop, redisAsyncContext *ac) {
static int redisAeAttach(aeEventLoop *loop, redisAsyncContext *ac) {
redisContext *c = &(ac->c);
redisAeEvents *e;

Expand All @@ -92,4 +94,4 @@ int redisAeAttach(aeEventLoop *loop, redisAsyncContext *ac) {

return REDIS_OK;
}

#endif
20 changes: 12 additions & 8 deletions adapters/libev.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#ifndef __HIREDIS_LIBEV_H__
#define __HIREDIS_LIBEV_H__
#include <stdlib.h>
#include <sys/types.h>
#include <ev.h>
#include "../hiredis.h"
Expand All @@ -10,7 +13,7 @@ typedef struct redisLibevEvents {
ev_io rev, wev;
} redisLibevEvents;

void redisLibevReadEvent(EV_P_ ev_io *watcher, int revents) {
static void redisLibevReadEvent(EV_P_ ev_io *watcher, int revents) {
#if EV_MULTIPLICITY
((void)loop);
#endif
Expand All @@ -20,7 +23,7 @@ void redisLibevReadEvent(EV_P_ ev_io *watcher, int revents) {
redisAsyncHandleRead(e->context);
}

void redisLibevWriteEvent(EV_P_ ev_io *watcher, int revents) {
static void redisLibevWriteEvent(EV_P_ ev_io *watcher, int revents) {
#if EV_MULTIPLICITY
((void)loop);
#endif
Expand All @@ -30,7 +33,7 @@ void redisLibevWriteEvent(EV_P_ ev_io *watcher, int revents) {
redisAsyncHandleWrite(e->context);
}

void redisLibevAddRead(void *privdata) {
static void redisLibevAddRead(void *privdata) {
redisLibevEvents *e = (redisLibevEvents*)privdata;
struct ev_loop *loop = e->loop;
((void)loop);
Expand All @@ -40,7 +43,7 @@ void redisLibevAddRead(void *privdata) {
}
}

void redisLibevDelRead(void *privdata) {
static void redisLibevDelRead(void *privdata) {
redisLibevEvents *e = (redisLibevEvents*)privdata;
struct ev_loop *loop = e->loop;
((void)loop);
Expand All @@ -50,7 +53,7 @@ void redisLibevDelRead(void *privdata) {
}
}

void redisLibevAddWrite(void *privdata) {
static void redisLibevAddWrite(void *privdata) {
redisLibevEvents *e = (redisLibevEvents*)privdata;
struct ev_loop *loop = e->loop;
((void)loop);
Expand All @@ -60,7 +63,7 @@ void redisLibevAddWrite(void *privdata) {
}
}

void redisLibevDelWrite(void *privdata) {
static void redisLibevDelWrite(void *privdata) {
redisLibevEvents *e = (redisLibevEvents*)privdata;
struct ev_loop *loop = e->loop;
((void)loop);
Expand All @@ -70,14 +73,14 @@ void redisLibevDelWrite(void *privdata) {
}
}

void redisLibevCleanup(void *privdata) {
static void redisLibevCleanup(void *privdata) {
redisLibevEvents *e = (redisLibevEvents*)privdata;
redisLibevDelRead(privdata);
redisLibevDelWrite(privdata);
free(e);
}

int redisLibevAttach(EV_P_ redisAsyncContext *ac) {
static int redisLibevAttach(EV_P_ redisAsyncContext *ac) {
redisContext *c = &(ac->c);
redisLibevEvents *e;

Expand Down Expand Up @@ -111,3 +114,4 @@ int redisLibevAttach(EV_P_ redisAsyncContext *ac) {
return REDIS_OK;
}

#endif
19 changes: 11 additions & 8 deletions adapters/libevent.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#ifndef __HIREDIS_LIBEVENT_H__
#define __HIREDIS_LIBEVENT_H__
#include <event.h>
#include "../hiredis.h"
#include "../async.h"
Expand All @@ -7,46 +9,46 @@ typedef struct redisLibeventEvents {
struct event rev, wev;
} redisLibeventEvents;

void redisLibeventReadEvent(int fd, short event, void *arg) {
static void redisLibeventReadEvent(int fd, short event, void *arg) {
((void)fd); ((void)event);
redisLibeventEvents *e = (redisLibeventEvents*)arg;
redisAsyncHandleRead(e->context);
}

void redisLibeventWriteEvent(int fd, short event, void *arg) {
static void redisLibeventWriteEvent(int fd, short event, void *arg) {
((void)fd); ((void)event);
redisLibeventEvents *e = (redisLibeventEvents*)arg;
redisAsyncHandleWrite(e->context);
}

void redisLibeventAddRead(void *privdata) {
static void redisLibeventAddRead(void *privdata) {
redisLibeventEvents *e = (redisLibeventEvents*)privdata;
event_add(&e->rev,NULL);
}

void redisLibeventDelRead(void *privdata) {
static void redisLibeventDelRead(void *privdata) {
redisLibeventEvents *e = (redisLibeventEvents*)privdata;
event_del(&e->rev);
}

void redisLibeventAddWrite(void *privdata) {
static void redisLibeventAddWrite(void *privdata) {
redisLibeventEvents *e = (redisLibeventEvents*)privdata;
event_add(&e->wev,NULL);
}

void redisLibeventDelWrite(void *privdata) {
static void redisLibeventDelWrite(void *privdata) {
redisLibeventEvents *e = (redisLibeventEvents*)privdata;
event_del(&e->wev);
}

void redisLibeventCleanup(void *privdata) {
static void redisLibeventCleanup(void *privdata) {
redisLibeventEvents *e = (redisLibeventEvents*)privdata;
event_del(&e->rev);
event_del(&e->wev);
free(e);
}

int redisLibeventAttach(redisAsyncContext *ac, struct event_base *base) {
static int redisLibeventAttach(redisAsyncContext *ac, struct event_base *base) {
redisContext *c = &(ac->c);
redisLibeventEvents *e;

Expand All @@ -73,3 +75,4 @@ int redisLibeventAttach(redisAsyncContext *ac, struct event_base *base) {
event_base_set(base,&e->wev);
return REDIS_OK;
}
#endif
1 change: 1 addition & 0 deletions async.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

#include "config.h"
#include "fmacros.h"
#include <stdlib.h>
#include <string.h>
#ifndef HIREDIS_WIN
#include <strings.h>
Expand Down
99 changes: 73 additions & 26 deletions hiredis.c
Original file line number Diff line number Diff line change
Expand Up @@ -449,10 +449,10 @@ static int processMultiBulkItem(redisReader *r) {
long elements;
int root = 0;

/* Set error for nested multi bulks with depth > 1 */
if (r->ridx == 2) {
/* Set error for nested multi bulks with depth > 2 */
if (r->ridx == 3) {
__redisReaderSetError(r,REDIS_ERR_PROTOCOL,
"No support for nested multi bulk replies with depth > 1");
"No support for nested multi bulk replies with depth > 2");
return REDIS_ERR;
}

Expand Down Expand Up @@ -752,6 +752,7 @@ int redisvFormatCommand(char **target, const char *format, va_list ap) {
default:
/* Try to detect printf format */
{
static const char intfmts[] = "diouxX";
char _format[16];
const char *_p = c+1;
size_t _l = 0;
Expand All @@ -773,33 +774,79 @@ int redisvFormatCommand(char **target, const char *format, va_list ap) {
while (*_p != '\0' && isdigit(*_p)) _p++;
}

/* Modifiers */
if (*_p != '\0') {
if (*_p == 'h' || *_p == 'l') {
/* Allow a single repetition for these modifiers */
if (_p[0] == _p[1]) _p++;
_p++;
/* Copy va_list before consuming with va_arg */
va_copy(_cpy,ap);

/* Integer conversion (without modifiers) */
if (strchr(intfmts,*_p) != NULL) {
va_arg(ap,int);
goto fmt_valid;
}

/* Double conversion (without modifiers) */
if (strchr("eEfFgGaA",*_p) != NULL) {
va_arg(ap,double);
goto fmt_valid;
}

/* Size: char */
if (_p[0] == 'h' && _p[1] == 'h') {
_p += 2;
if (*_p != '\0' && strchr(intfmts,*_p) != NULL) {
va_arg(ap,int); /* char gets promoted to int */
goto fmt_valid;
}
goto fmt_invalid;
}

/* Size: short */
if (_p[0] == 'h') {
_p += 1;
if (*_p != '\0' && strchr(intfmts,*_p) != NULL) {
va_arg(ap,int); /* short gets promoted to int */
goto fmt_valid;
}
goto fmt_invalid;
}

/* Conversion specifier */
if (*_p != '\0' && strchr("diouxXeEfFgGaA",*_p) != NULL) {
_l = (_p+1)-c;
if (_l < sizeof(_format)-2) {
memcpy(_format,c,_l);
_format[_l] = '\0';
va_copy(_cpy,ap);
newarg = sdscatvprintf(curarg,_format,_cpy);
va_end(_cpy);

/* Update current position (note: outer blocks
* increment c twice so compensate here) */
c = _p-1;
/* Size: long long */
if (_p[0] == 'l' && _p[1] == 'l') {
_p += 2;
if (*_p != '\0' && strchr(intfmts,*_p) != NULL) {
va_arg(ap,long long);
goto fmt_valid;
}
goto fmt_invalid;
}

/* Size: long */
if (_p[0] == 'l') {
_p += 1;
if (*_p != '\0' && strchr(intfmts,*_p) != NULL) {
va_arg(ap,long);
goto fmt_valid;
}
goto fmt_invalid;
}

fmt_invalid:
va_end(_cpy);
goto err;

fmt_valid:
_l = (_p+1)-c;
if (_l < sizeof(_format)-2) {
memcpy(_format,c,_l);
_format[_l] = '\0';
newarg = sdscatvprintf(curarg,_format,_cpy);

/* Update current position (note: outer blocks
* increment c twice so compensate here) */
c = _p-1;
}

/* Consume and discard vararg */
va_arg(ap,char*);
va_end(_cpy);
break;
}
}

Expand Down Expand Up @@ -1083,10 +1130,10 @@ int redisBufferRead(redisContext *c) {
*
* Returns REDIS_OK when the buffer is empty, or (a part of) the buffer was
* succesfully written to the socket. When the buffer is empty after the
* write operation, "wdone" is set to 1 (if given).
* write operation, "done" is set to 1 (if given).
*
* Returns REDIS_ERR if an error occured trying to write and sets
* c->error to hold the appropriate error string.
* c->errstr to hold the appropriate error string.
*/
int redisBufferWrite(redisContext *c, int *done) {
int nwritten;
Expand Down
2 changes: 1 addition & 1 deletion hiredis.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ typedef struct redisReader {
size_t pos; /* Buffer cursor */
size_t len; /* Buffer length */

redisReadTask rstack[3];
redisReadTask rstack[4];
int ridx; /* Index of current read task */
void *reply; /* Temporary reply pointer */

Expand Down
Loading

0 comments on commit b2b9bb4

Please sign in to comment.