git-svn-id: svn://elaine/murooma/trunk@283 d8a302eb-03bc-478d-80e4-98257eca68ef
This commit is contained in:
(no author) 2014-09-21 08:23:44 +00:00
parent 001bfa6aba
commit 7467141a14
3 changed files with 47 additions and 2 deletions

View file

@ -15,6 +15,12 @@ ServerSession::ServerSession(MessageReceiver* _receiver, std::shared_ptr<tcp::so
}
ServerSession::~ServerSession()
{
stop();
}
void ServerSession::start()
{
active_ = true;
@ -24,13 +30,49 @@ void ServerSession::start()
}
void ServerSession::stop()
{
active_ = false;
try
{
boost::system::error_code ec;
if (socket)
{
socket->shutdown(boost::asio::ip::tcp::socket::shutdown_both, ec);
if (ec) cout << "Error in socket shutdown: " << ec << "\n";
socket->close(ec);
if (ec) cout << "Error in socket close: " << ec << "\n";
}
if (readerThread)
{
cout << "joining readerThread\n";
readerThread->join();
delete readerThread;
}
if (writerThread)
{
cout << "joining readerThread\n";
writerThread->join();
delete writerThread;
}
}
catch(...)
{
}
readerThread = NULL;
writerThread = NULL;
cout << "ServerSession stopped\n";
}
void ServerSession::socketRead(void* _to, size_t _bytes)
{
size_t read = 0;
do
{
boost::system::error_code error;
read += socket->read_some(boost::asio::buffer((char*)_to + read, _bytes - read), error);
read += socket->read_some(boost::asio::buffer((char*)_to + read, _bytes - read));
}
while (read < _bytes);
}