Commit a587197c authored by legoc's avatar legoc
Browse files

Request implementation without linger

parent fc6e576d
......@@ -968,8 +968,19 @@ Request::Request(std::unique_ptr<RequestImpl> & impl) :
Request::~Request() {
}
void Request::setTimeout(int value, bool linger) {
m_impl->setTimeout(value, linger);
std::string Request::getObjectId() const {
// Local id is missing.
return "request:"
+ m_impl->m_requesterApplicationName
+ "."
+ to_string(m_impl->m_requesterApplicationId)
+ "@"
+ m_impl->m_requesterServerEndpoint;
}
void Request::setTimeout(int value) {
m_impl->setTimeout(value);
}
const std::string& Request::getBinary() const {
......@@ -988,12 +999,12 @@ const std::string& Request::getSecondBinaryPart() const {
return m_impl->m_message2;
}
void Request::replyBinary(const std::string& response) {
m_impl->replyBinary(response);
bool Request::replyBinary(const std::string& response) {
return m_impl->replyBinary(response);
}
void Request::reply(const std::string& response) {
m_impl->reply(response);
bool Request::reply(const std::string& response) {
return m_impl->reply(response);
}
std::unique_ptr<Instance> Request::connectToRequester() {
......
......@@ -392,14 +392,16 @@ class Request {
public:
~Request();
std::string getObjectId() const;
const std::string& getBinary() const;
std::string get() const;
const std::string& getSecondBinaryPart() const;
void setTimeout(int value, bool linger = true);
void setTimeout(int value);
void replyBinary(const std::string& response);
void reply(const std::string& response);
bool replyBinary(const std::string& response);
bool reply(const std::string& response);
std::unique_ptr<Instance> connectToRequester();
......
......@@ -31,8 +31,7 @@ RequestImpl::RequestImpl(application::This * application, const std::string & re
m_message(message),
m_requesterApplicationName(requesterApplicationName),
m_requesterApplicationId(requesterApplicationId),
m_timeout(0),
m_linger(true) {
m_timeout(0) {
stringstream requesterEndpoint;
requesterEndpoint << serverUrl << ":" << requesterPort;
......@@ -46,32 +45,32 @@ RequestImpl::RequestImpl(application::This * application, const std::string & re
RequestImpl::~RequestImpl() {
}
void RequestImpl::setTimeout(int value, bool linger) {
void RequestImpl::setTimeout(int value) {
m_timeout = value;
m_linger = linger;
}
void RequestImpl::replyBinary(const std::string& response) {
bool RequestImpl::replyBinary(const std::string& response) {
// Create a request socket. It is created for each request that could be optimized.
unique_ptr<RequestSocketImpl> requestSocket = m_application->createRequestSocket(m_requesterEndpoint, m_timeout);
requestSocket->setLinger(m_linger);
try {
requestSocket->request(m_application->m_impl->createRequestType(PROTO_RESPONSE), response);
}
catch (const ConnectionTimeout&) {
cout << "timeout while replying" << endl;
return false;
}
return true;
}
void RequestImpl::reply(const std::string& response) {
bool RequestImpl::reply(const std::string& response) {
// Encode the data.
string result;
serialize(response, result);
replyBinary(result);
return replyBinary(result);
}
}
......
......@@ -33,10 +33,10 @@ public:
RequestImpl(application::This * application, const std::string & requesterApplicationName, int requesterApplicationId, const std::string& message, const std::string& serverUrl, int serverPort, int requesterPort);
~RequestImpl();
void setTimeout(int value, bool linger);
void setTimeout(int value);
void replyBinary(const std::string& response);
void reply(const std::string& response);
bool replyBinary(const std::string& response);
bool reply(const std::string& response);
application::This * m_application;
std::string m_requesterEndpoint;
......@@ -46,7 +46,6 @@ public:
int m_requesterApplicationId;
std::string m_requesterServerEndpoint;
int m_timeout;
bool m_linger;
};
}
......
......@@ -74,11 +74,6 @@ std::unique_ptr<zmq::message_t> RequestSocketImpl::request(const std::string& re
int rc = zmq::poll(items, 1, timeout);
if (rc == 0) {
int lingerValue = 0;
m_socket->setsockopt(ZMQ_LINGER, &lingerValue, sizeof(int));
cout << "linger 0" << endl;
// Timeout occurred.
throw ConnectionTimeout();
}
......
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