Permalink
Browse files

First try.

  • Loading branch information...
1 parent 3d849e5 commit 2c980a21f4b453cc4326abafd1449663b8ca99c6 @nicolasff committed Dec 26, 2010
Showing with 34 additions and 3 deletions.
  1. +1 −1 Makefile
  2. +5 −0 cmd.c
  3. +7 −2 formats/json.c
  4. +18 −0 server.c
  5. +3 −0 server.h
View
@@ -3,7 +3,7 @@ HIREDIS_OBJ=hiredis/hiredis.o hiredis/sds.o hiredis/net.o hiredis/async.o
JANSSON_OBJ=jansson/src/dump.o jansson/src/error.o jansson/src/hashtable.o jansson/src/load.o jansson/src/strbuffer.o jansson/src/utf.o jansson/src/value.o jansson/src/variadic.o
FORMAT_OBJS=formats/json.o formats/raw.o
OBJS=turnip.o conf.o $(FORMAT_OBJS) cmd.o server.o $(HIREDIS_OBJ) $(JANSSON_OBJ)
-CFLAGS=-O3 -Wall -Wextra -I. -Ijansson/src
+CFLAGS=-O0 -ggdb -Wall -Wextra -I. -Ijansson/src
LDFLAGS=-levent
all: $(OUT) Makefile
View
5 cmd.c
@@ -71,6 +71,11 @@ cmd_run(struct server *s, struct evhttp_request *rq,
cmd->argv[0] = uri;
cmd->argv_len[0] = cmd_len;
+ /* check if we have to split the connection */
+ if(strncasecmp(cmd->argv[0], "SUBSCRIBE", cmd->argv_len[0]) == 0) {
+ s = server_copy(s);
+ }
+
if(!slash) {
redisAsyncCommandArgv(s->ac, fun, cmd, 1, cmd->argv, cmd->argv_len);
return;
View
@@ -31,12 +31,17 @@ json_reply(redisAsyncContext *c, void *r, void *privdata) {
/* get JSON as string, possibly with JSONP wrapper */
json_reply = json_string_output(j, cmd);
-
/* send reply */
body = evbuffer_new();
evbuffer_add(body, json_reply, strlen(json_reply));
evhttp_add_header(cmd->rq->output_headers, "Content-Type", "application/json");
- evhttp_send_reply(cmd->rq, 200, "OK", body);
+
+ if(strncasecmp(cmd->argv[0], "SUBSCRIBE", cmd->argv_len[0]) == 0) {
+ evhttp_send_reply_start(cmd->rq, 200, "OK");
+ evhttp_send_reply_chunk(cmd->rq, body);
+ } else {
+ evhttp_send_reply(cmd->rq, 200, "OK", body);
+ }
/* cleanup */
evbuffer_free(body);
View
@@ -66,3 +66,21 @@ turnip_connect(struct server *s) {
evtimer_add(&s->ev_reconnect, &s->tv_reconnect);
}
+static void
+turnip_connect_now(struct server *s) {
+ on_timer_reconnect(0, 0, s);
+}
+
+struct server *
+server_copy(const struct server *s) {
+ struct server *ret = calloc(1, sizeof(struct server));
+
+ *ret = *s;
+
+ /* create a new connection */
+ ret->ac = NULL;
+ turnip_connect_now(ret);
+
+ return ret;
+}
+
View
@@ -19,5 +19,8 @@ struct server {
void
turnip_connect(struct server *s);
+struct server *
+server_copy(const struct server *s);
+
#endif

0 comments on commit 2c980a2

Please sign in to comment.