Commit 08288c2a authored by legoc's avatar legoc
Browse files

Removed ContextZmq::isAvailable()

parent 5f44f900
......@@ -131,7 +131,16 @@ std::array<int, 3> Server::getVersion() const {
}
bool Server::isAvailable(int timeout) const {
return m_contextImpl->isAvailable(m_requestSocket.get(), timeout);
try {
m_requestSocket->requestJSON(createSyncRequest(), timeout);
return true;
}
catch (const ConnectionTimeout&) {
// The server is not accessible.
}
return false;
}
bool Server::isAvailable() const {
......
......@@ -117,20 +117,4 @@ zmq::socket_t * ContextZmq::createRequestSocket(const std::string& endpoint) {
return socket;
}
bool ContextZmq::isAvailable(RequestSocket * socket, int timeout) {
try {
socket->requestJSON(createSyncRequest(), timeout);
return true;
}
catch (const ConnectionTimeout&) {
// The server is not accessible.
}
catch (...) {
// Should not happen.
}
return false;
}
}
......@@ -47,8 +47,6 @@ public:
zmq::socket_t * createCancelPublisher(const std::string& endpoint);
zmq::socket_t * createRequestSocket(const std::string& endpoint);
bool isAvailable(RequestSocket * socket, int timeout);
private:
std::unique_ptr<zmq::context_t> m_context;
int m_timeout;
......
......@@ -85,7 +85,14 @@ void SubscriberImpl::init() {
items[0].revents = 0;
while (true) {
contextImpl->isAvailable(requestSocket.get(), 100);
// The subscriber sends SYNC messages to the publisher that returns SYNC message.
try {
requestSocket->requestJSON(createSyncRequest());
}
catch (const ConnectionTimeout&) {
// The server is not accessible.
}
// Wait for 100ms.
int rc = zmq::poll(items, 1, 100);
......
......@@ -83,7 +83,7 @@ public class SubscriberZmq implements SubscriberImpl {
boolean ready = false;
while (!ready) {
// The subscriber sends init messages to the publisher that returns SYNC message
// The subscriber sends SYNC messages to the publisher that returns SYNC message.
try {
requestSocket.requestJSON(Messages.createSyncRequest());
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment