Skip to content

Commit

Permalink
SKALE-5014 change exit to exception on bad socket
Browse files Browse the repository at this point in the history
  • Loading branch information
olehnikolaiev committed Feb 28, 2022
1 parent 188bf20 commit 683be22
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions zmq_src/ZMQServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,25 +211,27 @@ pair <string, shared_ptr<zmq::message_t>> ZMQServer::receiveMessage() {

if (!socket->recv(identity.get())) {
checkForExit();
// something terrible happened
spdlog::error("Fatal error: socket->recv(&identity) returned false. Exiting.");
exit(-11);
// bad socket type
spdlog::error("Error: socket->recv(&identity) returned false.");
throw SGXException(ZMQ_SERVER_ERROR, "Error: socket->recv(&identity) returned false.");
}

if (!identity->more()) {
checkForExit();
// something terrible happened
spdlog::error("Fatal error: zmq_msg_more(identity) returned false. Exiting.");
exit(-12);
// bad socket type
spdlog::error("Error: zmq_msg_more(identity) returned false.");
throw SGXException(ZMQ_SERVER_ERROR, "Error: zmq_msg_more(identity) returned false.");
}
auto id = string((char *) identity->data(), identity->size());
spdlog::debug("Received identity via ZMQ server: {}", id);

auto reqMsg = make_shared<zmq::message_t>();

if (!socket->recv(reqMsg.get(), 0)) {
checkForExit();
// something terrible happened
spdlog::error("Fatal error: socket.recv(&reqMsg, 0) returned false. Exiting");
exit(-13);
// bad socket type
spdlog::error("Error: socket.recv(&reqMsg, 0) returned false.");
throw SGXException(ZMQ_SERVER_ERROR, "Error: socket.recv(&reqMsg, 0) returned false.");
}

auto result = string((char *) reqMsg->data(), reqMsg->size());
Expand Down

0 comments on commit 683be22

Please sign in to comment.