1
0
mirror of https://github.com/GOSTSec/poolserver synced 2025-01-15 01:00:10 +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) { 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 {
// 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 { } 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)) {
@ -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 <boost/enable_shared_from_this.hpp>
#include <set> #include <set>
#define MAX_PACKET 2048 #define PACKET_ALLOC 128
using namespace boost; using namespace boost;
using namespace boost::asio::ip; using namespace boost::asio::ip;
@ -31,6 +31,7 @@ namespace Stratum
{ {
_diff = sConfig.Get<uint32>("StratumMinDifficulty"); _diff = sConfig.Get<uint32>("StratumMinDifficulty");
_minDiff = _diff; _minDiff = _diff;
_recvMessage.reserve(PACKET_ALLOC);
} }
tcp::socket& GetSocket() tcp::socket& GetSocket()
@ -130,6 +131,7 @@ namespace Stratum
private: private:
// Networking // Networking
asio::streambuf _recvBuffer; asio::streambuf _recvBuffer;
std::string _recvMessage;
tcp::socket _socket; tcp::socket _socket;
uint32 _ip; uint32 _ip;
uint64 _id; uint64 _id;