Skip to content
Snippets Groups Projects
Commit b02e54b4 authored by yanmorin's avatar yanmorin
Browse files

Try a new method to handle last message, should test at job..
parent 316a2e50
No related tags found
No related merge requests found
......@@ -76,6 +76,7 @@ RequestManager::exec()
{ // session mutex block
_debug("Closing TCP Session... \n");
_sessionMutex.enterMutex();
if (_sessionIO) _sessionIO->sendLast();
delete _sessionIO; _sessionIO = NULL;
_sessionMutex.leaveMutex();
_debug("TCP Session has closed\n");
......
......@@ -32,6 +32,7 @@ public:
virtual ~SessionIO();
virtual void send(const std::string& response) = 0;
virtual void sendLast() = 0;
virtual bool receive(std::string& request) = 0;
virtual bool good() = 0;
virtual void init() = 0;
......
......@@ -61,6 +61,13 @@ TCPSessionIO::send(const std::string& response)
_clientStream->send(response);
}
}
void
TCPSessionIO::sendLast()
{
if (_clientStream) {
_clientStream->sendLast();
}
}
bool
TCPSessionIO::receive(std::string& request)
......
......@@ -33,6 +33,7 @@ public:
~TCPSessionIO();
void send(const std::string& response);
void sendLast();
bool receive(std::string& request);
bool good();
void init();
......
......@@ -26,15 +26,8 @@ TCPStreamPool::~TCPStreamPool()
_debug("TCPStreamPool terminate\n");
terminate();
_debug("terminate done\n");
std::string output;
while (_outputPool.pop(output, WAITING_TIME)) {
_debug("TCPStreamPool send %s\n", output.c_str());
//_debug("sending last message...\n");
*this << output << std::endl;
}
}
void
TCPStreamPool::run() {
std::string output;
......@@ -45,15 +38,15 @@ TCPStreamPool::run() {
while(!testCancel() && good()) {
while (isPending(ost::TCPSocket::pendingInput, WAITING_TIME)) {
std::getline(*this, input);
_debug("TCPStreamPool getline %s\n", input.c_str());
//_debug("TCPStreamPool getline %s\n", input.c_str());
if (input != null && input[0]!=cr13) {
_inputPool.push(input);
}
// security check, since we are inside a loop
if (testCancel() || !good()) {break;}
}
if (good() && _outputPool.pop(output, WAITING_TIME)) {
_debug("TCPStreamPool send %s\n", output.c_str());
if (_outputPool.pop(output, WAITING_TIME)) {
//_debug("TCPStreamPool send %s\n", output.c_str());
*this << output << std::endl;
}
}
......@@ -62,9 +55,16 @@ TCPStreamPool::run() {
void
TCPStreamPool::send(const std::string& response)
{
if (!testCancel()) {
_outputPool.push(response);
}
_outputPool.push(response);
}
void
TCPStreamPool::sendLast() {
std::string output;
while (good() && _outputPool.pop(output, WAITING_TIME)) {
_debug("TCPStreamPool send last %s\n", output.c_str());
//_debug("sending last message...\n");
*this << output << std::endl;
}
}
bool
......
......@@ -47,6 +47,7 @@ public:
void run();
void send(const std::string& response);
void sendLast();
bool receive(std::string& request);
private:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment