Skip to content

Commit

Permalink
ignore empty lines if "decode line fail, not a json string"
Browse files Browse the repository at this point in the history
  • Loading branch information
SwimmingTiger committed Apr 10, 2020
1 parent 0ac0015 commit 0222174
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
4 changes: 4 additions & 0 deletions src/Utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -228,3 +228,7 @@ string str2lower(const string &str) {
std::transform(data.begin(), data.end(), data.begin(), ::tolower);
return data;
}

bool strEmpty(const string &str) {
return str.find_last_not_of(" \t\f\v\n\r") == str.npos;
}
1 change: 1 addition & 0 deletions src/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,5 +133,6 @@ bool parseConfJson(const string &jsonStr,
const char *splitNotify(const string &line, int number = 14);

string str2lower(const string &str);
bool strEmpty(const string &str);

#endif
8 changes: 6 additions & 2 deletions src/bitcoin/ServerBitcoin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,9 @@ void UpStratumClientBitcoin::handleStratumMessage(const string &line) {

StratumMessageBitcoin smsg(line);
if (!smsg.isValid()) {
LOG(ERROR) << "decode line fail, not a json string" << std::endl;
if (!strEmpty(line)) {
LOG(ERROR) << "decode line fail, not a json string: " << line << std::endl;
}
return;
}

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

StratumMessageBitcoin smsg(line);
if (!smsg.isValid()) {
LOG(ERROR) << "decode line fail, not a json string" << std::endl;
if (!strEmpty(line)) {
LOG(ERROR) << "decode line fail, not a json string: " << line << std::endl;
}
return;
}

Expand Down
8 changes: 6 additions & 2 deletions src/eth/ServerEth.cc
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,9 @@ void UpStratumClientEth::handleStratumMessage(const string &line) {

StratumMessageEth smsg(line);
if (!smsg.isValid()) {
LOG(ERROR) << "decode line fail, not a json string" << std::endl;
if (!strEmpty(line)) {
LOG(ERROR) << "decode line fail, not a json string: " << line << std::endl;
}
return;
}

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

StratumMessageEth smsg(line);
if (!smsg.isValid()) {
LOG(ERROR) << "decode line fail, not a json string" << std::endl;
if (!strEmpty(line)) {
LOG(ERROR) << "decode line fail, not a json string: " << line << std::endl;
}
return;
}

Expand Down

0 comments on commit 0222174

Please sign in to comment.