Skip to content

Commit 0222174

Browse files
committed
ignore empty lines if "decode line fail, not a json string"
1 parent 0ac0015 commit 0222174

File tree

4 files changed

+17
-4
lines changed

4 files changed

+17
-4
lines changed

src/Utils.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,3 +228,7 @@ string str2lower(const string &str) {
228228
std::transform(data.begin(), data.end(), data.begin(), ::tolower);
229229
return data;
230230
}
231+
232+
bool strEmpty(const string &str) {
233+
return str.find_last_not_of(" \t\f\v\n\r") == str.npos;
234+
}

src/Utils.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,5 +133,6 @@ bool parseConfJson(const string &jsonStr,
133133
const char *splitNotify(const string &line, int number = 14);
134134

135135
string str2lower(const string &str);
136+
bool strEmpty(const string &str);
136137

137138
#endif

src/bitcoin/ServerBitcoin.cc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,9 @@ void UpStratumClientBitcoin::handleStratumMessage(const string &line) {
503503

504504
StratumMessageBitcoin smsg(line);
505505
if (!smsg.isValid()) {
506-
LOG(ERROR) << "decode line fail, not a json string" << std::endl;
506+
if (!strEmpty(line)) {
507+
LOG(ERROR) << "decode line fail, not a json string: " << line << std::endl;
508+
}
507509
return;
508510
}
509511

@@ -719,7 +721,9 @@ void StratumSessionBitcoin::handleStratumMessage(const string &line) {
719721

720722
StratumMessageBitcoin smsg(line);
721723
if (!smsg.isValid()) {
722-
LOG(ERROR) << "decode line fail, not a json string" << std::endl;
724+
if (!strEmpty(line)) {
725+
LOG(ERROR) << "decode line fail, not a json string: " << line << std::endl;
726+
}
723727
return;
724728
}
725729

src/eth/ServerEth.cc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,9 @@ void UpStratumClientEth::handleStratumMessage(const string &line) {
587587

588588
StratumMessageEth smsg(line);
589589
if (!smsg.isValid()) {
590-
LOG(ERROR) << "decode line fail, not a json string" << std::endl;
590+
if (!strEmpty(line)) {
591+
LOG(ERROR) << "decode line fail, not a json string: " << line << std::endl;
592+
}
591593
return;
592594
}
593595

@@ -792,7 +794,9 @@ void StratumSessionEth::handleStratumMessage(const string &line) {
792794

793795
StratumMessageEth smsg(line);
794796
if (!smsg.isValid()) {
795-
LOG(ERROR) << "decode line fail, not a json string" << std::endl;
797+
if (!strEmpty(line)) {
798+
LOG(ERROR) << "decode line fail, not a json string: " << line << std::endl;
799+
}
796800
return;
797801
}
798802

0 commit comments

Comments
 (0)