Refactoring.

master
Nicolas Favre-Felix 14 years ago
parent 114d6c9a80
commit 4676cfebd0

12
cmd.c

@ -144,7 +144,7 @@ cmd_run(struct server *s, struct evhttp_request *rq,
} }
/* check if we have to split the connection */ /* 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; struct pubsub_client *ps;
ps = calloc(1, sizeof(struct pubsub_client)); ps = calloc(1, sizeof(struct pubsub_client));
ps->s = s = server_copy(s); ps->s = s = server_copy(s);
@ -204,3 +204,13 @@ get_formatting_funtion(struct evkeyvalq *params) {
return json_reply; 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;
}

@ -21,7 +21,7 @@ struct cmd {
struct evkeyvalq uri_params; struct evkeyvalq uri_params;
int replied; int started_responding;
}; };
struct cmd * struct cmd *
@ -37,4 +37,7 @@ cmd_run(struct server *s, struct evhttp_request *rq,
formatting_fun formatting_fun
get_formatting_funtion(struct evkeyvalq *params); get_formatting_funtion(struct evkeyvalq *params);
int
cmd_is_subscribe(struct cmd *cmd);
#endif #endif

@ -43,7 +43,7 @@ json_reply(redisAsyncContext *c, void *r, void *privdata) {
evbuffer_add(body, jstr, strlen(jstr)); evbuffer_add(body, jstr, strlen(jstr));
evhttp_add_header(cmd->rq->output_headers, "Content-Type", "application/json"); 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; redisCallback cb;
free_cmd = 0; free_cmd = 0;
@ -53,8 +53,8 @@ json_reply(redisAsyncContext *c, void *r, void *privdata) {
__redisPushCallback(&c->replies, &cb); __redisPushCallback(&c->replies, &cb);
/* start streaming */ /* start streaming */
if(cmd->replied == 0) { if(cmd->started_responding == 0) {
cmd->replied = 1; cmd->started_responding = 1;
evhttp_send_reply_start(cmd->rq, 200, "OK"); evhttp_send_reply_start(cmd->rq, 200, "OK");
} }
evhttp_send_reply_chunk(cmd->rq, body); evhttp_send_reply_chunk(cmd->rq, body);

Loading…
Cancel
Save