Commit 45fd15cb authored by legoc's avatar legoc
Browse files

(split2) Test with timeout in Server

parent 4f1bee94
......@@ -30,7 +30,7 @@ using namespace std;
namespace cameo {
Server::Server(const std::string& endpoint) :
Server::Server(const std::string& endpoint, int timeoutMs) :
Services() {
Services::init();
......@@ -47,13 +47,26 @@ Server::Server(const std::string& endpoint) :
is >> m_port;
m_serverEndpoint = m_url + ":" + port;
// Set the timeout.
Services::setTimeout(timeoutMs);
// Create the request socket. The server endpoint has been defined.
Services::initRequestSocket();
// Start the event thread.
unique_ptr<EventStreamSocket> socket = openEventStream();
m_eventThread.reset(new EventThread(this, socket));
m_eventThread->start();
// Manage the ConnectionTimeout exception that can occur.
try {
// Start the event thread.
unique_ptr<EventStreamSocket> socket = openEventStream();
m_eventThread.reset(new EventThread(this, socket));
m_eventThread->start();
}
catch (const std::exception& e) {
cout << "event error " << e.what() << endl;
}
catch (...) {
// ...
}
}
Server::~Server() {
......
......@@ -48,7 +48,7 @@ class Server : private Services {
public:
typedef std::function<void (bool)> ConnectionCheckerType;
Server(const std::string& endpoint);
Server(const std::string& endpoint, int timeoutMs = 0);
~Server();
void setTimeout(int timeoutMs);
......
......@@ -406,18 +406,27 @@ std::string ServicesImpl::createOutputRequest(const std::string& name) const {
bool ServicesImpl::isAvailable(RequestSocketImpl * socket, int timeout) {
cout << 1 << endl;
string requestTypePart = createRequestType(PROTO_INIT);
string requestDataPart = createInitRequest();
cout << 2 << endl;
try {
unique_ptr<zmq::message_t> reply = socket->request(requestTypePart, requestDataPart, timeout);
cout << 3 << endl;
if (reply.get() != nullptr) {
return true;
}
} catch (const ConnectionTimeout&) {
// The server is not accessible.
cout << 4 << endl;
} catch (const std::exception& e) {
cout << "error " << e.what() << endl;
}
return false;
......
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