Browse Source

Fix packet handling

master
Intel 11 years ago
parent
commit
e22760e4db
  1. 25
      src/server/poolserver/Stratum/Client.cpp
  2. 4
      src/server/poolserver/Stratum/Client.h

25
src/server/poolserver/Stratum/Client.cpp

@ -349,29 +349,34 @@ namespace Stratum @@ -349,29 +349,34 @@ 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());
Disconnect();
}
}
}
void Client::_OnSend(const boost::system::error_code& error)
{
if (!error) {
// Party
} else {
if (error) {
// Client disconnected
if ((error == asio::error::eof) || (error == asio::error::connection_reset)) {
Disconnect();

4
src/server/poolserver/Stratum/Client.h

@ -15,7 +15,7 @@ @@ -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 @@ -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 @@ -130,6 +131,7 @@ namespace Stratum
private:
// Networking
asio::streambuf _recvBuffer;
std::string _recvMessage;
tcp::socket _socket;
uint32 _ip;
uint64 _id;

Loading…
Cancel
Save