Permalink
Browse files

Refactoring.

  • Loading branch information...
1 parent 114d6c9 commit 4676cfebd0629e7a0b6605074898e2c5798cd641 @nicolasff committed Dec 29, 2010
Showing with 18 additions and 5 deletions.
  1. +11 −1 cmd.c
  2. +4 −1 cmd.h
  3. +3 −3 formats/json.c
View
12 cmd.c
@@ -144,7 +144,7 @@ cmd_run(struct server *s, struct evhttp_request *rq,
}
/* check if we have to split the connection */
- if(strncasecmp(cmd->argv[0], "SUBSCRIBE", cmd->argv_len[0]) == 0) {
+ if(cmd_is_subscribe(cmd)) {
struct pubsub_client *ps;
ps = calloc(1, sizeof(struct pubsub_client));
ps->s = s = server_copy(s);
@@ -204,3 +204,13 @@ get_formatting_funtion(struct evkeyvalq *params) {
return json_reply;
}
+
+int
+cmd_is_subscribe(struct cmd *cmd) {
+
+ if(strncasecmp(cmd->argv[0], "SUBSCRIBE", cmd->argv_len[0]) == 0 ||
+ strncasecmp(cmd->argv[0], "PSUBSCRIBE", cmd->argv_len[0]) == 0) {
+ return 1;
+ }
+ return 0;
+}
View
5 cmd.h
@@ -21,7 +21,7 @@ struct cmd {
struct evkeyvalq uri_params;
- int replied;
+ int started_responding;
};
struct cmd *
@@ -37,4 +37,7 @@ cmd_run(struct server *s, struct evhttp_request *rq,
formatting_fun
get_formatting_funtion(struct evkeyvalq *params);
+int
+cmd_is_subscribe(struct cmd *cmd);
+
#endif
View
@@ -43,7 +43,7 @@ json_reply(redisAsyncContext *c, void *r, void *privdata) {
evbuffer_add(body, jstr, strlen(jstr));
evhttp_add_header(cmd->rq->output_headers, "Content-Type", "application/json");
- if(strncasecmp(cmd->argv[0], "SUBSCRIBE", cmd->argv_len[0]) == 0) {
+ if(cmd_is_subscribe(cmd)) {
redisCallback cb;
free_cmd = 0;
@@ -53,8 +53,8 @@ json_reply(redisAsyncContext *c, void *r, void *privdata) {
__redisPushCallback(&c->replies, &cb);
/* start streaming */
- if(cmd->replied == 0) {
- cmd->replied = 1;
+ if(cmd->started_responding == 0) {
+ cmd->started_responding = 1;
evhttp_send_reply_start(cmd->rq, 200, "OK");
}
evhttp_send_reply_chunk(cmd->rq, body);

0 comments on commit 4676cfe

Please sign in to comment.