Browse Source

Fix packet handling

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

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

@ -349,29 +349,34 @@ namespace Stratum
{ {
if (!error) { if (!error) {
std::istream is(&_recvBuffer); std::istream is(&_recvBuffer);
std::stringstream iss;
iss << is.rdbuf();
char c;
while (is.good()) {
is >> c;
if (c == '\n') {
try { try {
OnMessage(JSON::FromString(iss.str())); OnMessage(JSON::FromString(_recvMessage));
} catch (std::exception& e) { } catch (std::exception& e) {
sLog.Error(LOG_SERVER, "Exception caught while parsing json: %s", e.what()); 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();

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

@ -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;

Loading…
Cancel
Save