1
0
mirror of https://github.com/GOSTSec/poolserver synced 2025-01-14 08:47:53 +00:00

Fix packet handling

This commit is contained in:
Intel 2014-05-05 09:25:17 -04:00
parent e9c5b31f13
commit e22760e4db
2 changed files with 26 additions and 19 deletions

View File

@ -349,28 +349,23 @@ namespace Stratum
{
if (!error) {
std::istream is(&_recvBuffer);
std::stringstream iss;
iss << is.rdbuf();
try {
OnMessage(JSON::FromString(iss.str()));
} catch (std::exception& e) {
sLog.Error(LOG_SERVER, "Exception caught while parsing json: %s", e.what());
char c;
while (is.good()) {
is >> c;
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();
} else {
// Client disconnected
if ((error == asio::error::eof) || (error == asio::error::connection_reset)) {
_server->Disconnect(shared_from_this());
}
}
}
void Client::_OnSend(const boost::system::error_code& error)
{
if (!error) {
// Party
} else {
// Client disconnected
if ((error == asio::error::eof) || (error == asio::error::connection_reset)) {
@ -378,4 +373,14 @@ namespace Stratum
}
}
}
void Client::_OnSend(const boost::system::error_code& error)
{
if (error) {
// Client disconnected
if ((error == asio::error::eof) || (error == asio::error::connection_reset)) {
Disconnect();
}
}
}
}

View File

@ -15,7 +15,7 @@
#include <boost/enable_shared_from_this.hpp>
#include <set>
#define MAX_PACKET 2048
#define PACKET_ALLOC 128
using namespace boost;
using namespace boost::asio::ip;
@ -31,6 +31,7 @@ namespace Stratum
{
_diff = sConfig.Get<uint32>("StratumMinDifficulty");
_minDiff = _diff;
_recvMessage.reserve(PACKET_ALLOC);
}
tcp::socket& GetSocket()
@ -130,6 +131,7 @@ namespace Stratum
private:
// Networking
asio::streambuf _recvBuffer;
std::string _recvMessage;
tcp::socket _socket;
uint32 _ip;
uint64 _id;