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 branches found
No related tags found
No related merge requests found
...@@ -76,6 +76,7 @@ RequestManager::exec() ...@@ -76,6 +76,7 @@ RequestManager::exec()
{ // session mutex block { // session mutex block
_debug("Closing TCP Session... \n"); _debug("Closing TCP Session... \n");
_sessionMutex.enterMutex(); _sessionMutex.enterMutex();
if (_sessionIO) _sessionIO->sendLast();
delete _sessionIO; _sessionIO = NULL; delete _sessionIO; _sessionIO = NULL;
_sessionMutex.leaveMutex(); _sessionMutex.leaveMutex();
_debug("TCP Session has closed\n"); _debug("TCP Session has closed\n");
......
...@@ -32,6 +32,7 @@ public: ...@@ -32,6 +32,7 @@ public:
virtual ~SessionIO(); virtual ~SessionIO();
virtual void send(const std::string& response) = 0; virtual void send(const std::string& response) = 0;
virtual void sendLast() = 0;
virtual bool receive(std::string& request) = 0; virtual bool receive(std::string& request) = 0;
virtual bool good() = 0; virtual bool good() = 0;
virtual void init() = 0; virtual void init() = 0;
......
...@@ -61,6 +61,13 @@ TCPSessionIO::send(const std::string& response) ...@@ -61,6 +61,13 @@ TCPSessionIO::send(const std::string& response)
_clientStream->send(response); _clientStream->send(response);
} }
} }
void
TCPSessionIO::sendLast()
{
if (_clientStream) {
_clientStream->sendLast();
}
}
bool bool
TCPSessionIO::receive(std::string& request) TCPSessionIO::receive(std::string& request)
......
...@@ -33,6 +33,7 @@ public: ...@@ -33,6 +33,7 @@ public:
~TCPSessionIO(); ~TCPSessionIO();
void send(const std::string& response); void send(const std::string& response);
void sendLast();
bool receive(std::string& request); bool receive(std::string& request);
bool good(); bool good();
void init(); void init();
......
...@@ -26,15 +26,8 @@ TCPStreamPool::~TCPStreamPool() ...@@ -26,15 +26,8 @@ TCPStreamPool::~TCPStreamPool()
_debug("TCPStreamPool terminate\n"); _debug("TCPStreamPool terminate\n");
terminate(); terminate();
_debug("terminate done\n"); _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 void
TCPStreamPool::run() { TCPStreamPool::run() {
std::string output; std::string output;
...@@ -45,15 +38,15 @@ TCPStreamPool::run() { ...@@ -45,15 +38,15 @@ TCPStreamPool::run() {
while(!testCancel() && good()) { while(!testCancel() && good()) {
while (isPending(ost::TCPSocket::pendingInput, WAITING_TIME)) { while (isPending(ost::TCPSocket::pendingInput, WAITING_TIME)) {
std::getline(*this, input); 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) { if (input != null && input[0]!=cr13) {
_inputPool.push(input); _inputPool.push(input);
} }
// security check, since we are inside a loop // security check, since we are inside a loop
if (testCancel() || !good()) {break;} if (testCancel() || !good()) {break;}
} }
if (good() && _outputPool.pop(output, WAITING_TIME)) { if (_outputPool.pop(output, WAITING_TIME)) {
_debug("TCPStreamPool send %s\n", output.c_str()); //_debug("TCPStreamPool send %s\n", output.c_str());
*this << output << std::endl; *this << output << std::endl;
} }
} }
...@@ -62,9 +55,16 @@ TCPStreamPool::run() { ...@@ -62,9 +55,16 @@ TCPStreamPool::run() {
void void
TCPStreamPool::send(const std::string& response) 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 bool
......
...@@ -47,6 +47,7 @@ public: ...@@ -47,6 +47,7 @@ public:
void run(); void run();
void send(const std::string& response); void send(const std::string& response);
void sendLast();
bool receive(std::string& request); bool receive(std::string& request);
private: 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