Browse Source

Pass recognised json messages sent to connector to stratifier with the added client_id field

master
Con Kolivas 11 years ago
parent
commit
1b745f0db3
  1. 16
      src/connector.c
  2. 5
      src/stratifier.c

16
src/connector.c

@ -93,9 +93,11 @@ static void invalidate_client(client_instance_t *client)
static void parse_client_msg(conn_instance_t *ci, client_instance_t *client) static void parse_client_msg(conn_instance_t *ci, client_instance_t *client)
{ {
ckpool_t *ckp = ci->pi->ckp;
char msg[PAGESIZE], *eol; char msg[PAGESIZE], *eol;
int buflen, ret; int buflen, ret;
bool moredata; bool moredata;
json_t *val;
retry: retry:
buflen = PAGESIZE - client->bufofs; buflen = PAGESIZE - client->bufofs;
@ -141,7 +143,19 @@ reparse:
msg[buflen] = 0; msg[buflen] = 0;
client->bufofs -= buflen; client->bufofs -= buflen;
memmove(client->buf, client->buf + buflen, client->bufofs); memmove(client->buf, client->buf + buflen, client->bufofs);
LOGWARNING("Client fd %d sent message %s", client->fd, msg); val = json_loads(msg, 0, NULL);
if (!val)
LOGWARNING("Client fd %d sent invalid json message %s", client->fd, msg);
else {
char *s;
json_object_set_new_nocheck(val, "client_id", json_integer(client->id));
s = json_dumps(val, 0);
send_proc(&ckp->stratifier, s);
free(s);
json_decref(val);
}
if (client->bufofs) if (client->bufofs)
goto reparse; goto reparse;
} }

5
src/stratifier.c

@ -298,9 +298,12 @@ retry:
LOGDEBUG("Stratifier received request: %s", buf); LOGDEBUG("Stratifier received request: %s", buf);
if (!strncasecmp(buf, "shutdown", 8)) if (!strncasecmp(buf, "shutdown", 8))
goto out; goto out;
if (!strncasecmp(buf, "update", 6)) { else if (!strncasecmp(buf, "update", 6)) {
update_base(ckp); update_base(ckp);
goto reset; goto reset;
} else {
LOGDEBUG("Received unrecognised message: %s", buf);
goto retry;
} }
out: out:

Loading…
Cancel
Save