Browse Source

Avoid needing to duplicate buffer to parse messages in parse_client_msg

master
Con Kolivas 9 years ago
parent
commit
eedc3eec1c
  1. 18
      src/connector.c

18
src/connector.c

@ -462,8 +462,8 @@ static void parse_client_msg(cdata_t *cdata, client_instance_t *client)
{
ckpool_t *ckp = cdata->ckp;
int buflen, ret;
char *msg, *eol;
json_t *val;
char *eol;
retry:
if (unlikely(client->bufofs > MAX_MSGSIZE)) {
@ -499,16 +499,10 @@ reparse:
return;
}
msg = alloca(round_up_page(buflen + 1));
memcpy(msg, client->buf, buflen);
msg[buflen] = '\0';
client->bufofs -= buflen;
memmove(client->buf, client->buf + buflen, client->bufofs);
client->buf[client->bufofs] = '\0';
if (!(val = json_loads(msg, 0, NULL))) {
if (!(val = json_loads(client->buf, JSON_DISABLE_EOF_CHECK, NULL))) {
char *buf = strdup("Invalid JSON, disconnecting\n");
LOGINFO("Client id %"PRId64" sent invalid json message %s", client->id, msg);
LOGINFO("Client id %"PRId64" sent invalid json message %s", client->id, client->buf);
send_client(cdata, client->id, buf);
invalidate_client(ckp, cdata, client);
return;
@ -522,7 +516,7 @@ reparse:
passthrough_id = (client->id << 32) | passthrough_id;
json_object_set_new_nocheck(val, "client_id", json_integer(passthrough_id));
} else {
if (ckp->redirector && !client->redirected && strstr(msg, "mining.submit"))
if (ckp->redirector && !client->redirected && strstr(client->buf, "mining.submit"))
parse_redirector_share(client, val);
json_object_set_new_nocheck(val, "client_id", json_integer(client->id));
json_object_set_new_nocheck(val, "address", json_string(client->address_name));
@ -543,6 +537,10 @@ reparse:
free(s);
json_decref(val);
}
client->bufofs -= buflen;
if (client->bufofs)
memmove(client->buf, client->buf + buflen, client->bufofs);
client->buf[client->bufofs] = '\0';
if (client->bufofs)
goto reparse;

Loading…
Cancel
Save