From 6a4da2814ce53d2e13a7a0ab789dd595358d141c Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Thu, 27 Nov 2014 15:11:35 +1100 Subject: [PATCH] Look for received json messages in the stratifier first since they'll be the most common --- src/stratifier.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/stratifier.c b/src/stratifier.c index 18e30b63..1813aab1 100644 --- a/src/stratifier.c +++ b/src/stratifier.c @@ -1443,11 +1443,20 @@ retry: dealloc(buf); buf = recv_unix_msg(sockd); - if (!buf) { + if (unlikely(!buf)) { Close(sockd); LOGWARNING("Failed to get message in stratum_loop"); goto retry; } + if (likely(buf[0] == '{')) { + /* The bulk of the messages will be received json from the + * connector so look for this first. The srecv_process frees + * the buf heap ram */ + ckmsgq_add(sdata->srecvs, buf); + Close(sockd); + buf = NULL; + goto retry; + } if (cmdmatch(buf, "ping")) { LOGDEBUG("Stratifier received ping request"); send_unix_msg(sockd, "pong"); @@ -1488,11 +1497,8 @@ retry: reconnect_clients(sdata, buf); } else if (cmdmatch(buf, "loglevel")) { sscanf(buf, "loglevel=%d", &ckp->loglevel); - } else { - /* The srecv_process frees the buf heap ram */ - ckmsgq_add(sdata->srecvs, buf); - buf = NULL; - } + } else + LOGWARNING("Unhandled stratifier message: %s", buf); goto retry; out: