|
|
@ -349,29 +349,34 @@ namespace Stratum |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (!error) { |
|
|
|
if (!error) { |
|
|
|
std::istream is(&_recvBuffer); |
|
|
|
std::istream is(&_recvBuffer); |
|
|
|
std::stringstream iss; |
|
|
|
|
|
|
|
iss << is.rdbuf(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
char c; |
|
|
|
OnMessage(JSON::FromString(iss.str())); |
|
|
|
while (is.good()) { |
|
|
|
} catch (std::exception& e) { |
|
|
|
is >> c; |
|
|
|
sLog.Error(LOG_SERVER, "Exception caught while parsing json: %s", e.what()); |
|
|
|
if (c == '\n') { |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
OnMessage(JSON::FromString(_recvMessage)); |
|
|
|
|
|
|
|
} catch (std::exception& e) { |
|
|
|
|
|
|
|
sLog.Error(LOG_SERVER, "Exception caught while parsing json: %s", e.what()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
_recvMessage.clear(); |
|
|
|
|
|
|
|
_recvMessage.reserve(PACKET_ALLOC); |
|
|
|
|
|
|
|
} else |
|
|
|
|
|
|
|
_recvMessage += c; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
StartRead(); |
|
|
|
StartRead(); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
// Client disconnected
|
|
|
|
// Client disconnected
|
|
|
|
if ((error == asio::error::eof) || (error == asio::error::connection_reset)) { |
|
|
|
if ((error == asio::error::eof) || (error == asio::error::connection_reset)) { |
|
|
|
_server->Disconnect(shared_from_this()); |
|
|
|
Disconnect(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void Client::_OnSend(const boost::system::error_code& error) |
|
|
|
void Client::_OnSend(const boost::system::error_code& error) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (!error) { |
|
|
|
if (error) { |
|
|
|
// Party
|
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
// Client disconnected
|
|
|
|
// Client disconnected
|
|
|
|
if ((error == asio::error::eof) || (error == asio::error::connection_reset)) { |
|
|
|
if ((error == asio::error::eof) || (error == asio::error::connection_reset)) { |
|
|
|
Disconnect(); |
|
|
|
Disconnect(); |
|
|
|