mirror of
https://github.com/GOSTSec/poolserver
synced 2025-01-14 08:47:53 +00:00
Fixed socket reading
This commit is contained in:
parent
e22760e4db
commit
c06c4edb2a
@ -17,6 +17,7 @@ namespace Stratum
|
||||
_ip = remote_ad.to_v4().to_ulong();
|
||||
|
||||
if (_server->IsBanned(_ip)) {
|
||||
sLog.Warn(LOG_STRATUM, "Blocked banned client from: %s", remote_ad.to_v4().to_string().c_str());
|
||||
Disconnect();
|
||||
return;
|
||||
}
|
||||
@ -349,10 +350,8 @@ namespace Stratum
|
||||
{
|
||||
if (!error) {
|
||||
std::istream is(&_recvBuffer);
|
||||
|
||||
char c;
|
||||
while (is.good()) {
|
||||
is >> c;
|
||||
while (is.get(c)) {
|
||||
if (c == '\n') {
|
||||
try {
|
||||
OnMessage(JSON::FromString(_recvMessage));
|
||||
|
@ -45,10 +45,10 @@ namespace Stratum
|
||||
void StartRead()
|
||||
{
|
||||
// Read until newline
|
||||
boost::asio::async_read_until(
|
||||
asio::async_read(
|
||||
_socket,
|
||||
_recvBuffer,
|
||||
'\n',
|
||||
asio::transfer_at_least(1),
|
||||
boost::bind(&Client::_OnReceive, this, asio::placeholders::error, asio::placeholders::bytes_transferred));
|
||||
}
|
||||
|
||||
@ -117,6 +117,11 @@ namespace Stratum
|
||||
return _id;
|
||||
}
|
||||
|
||||
uint32 GetIP()
|
||||
{
|
||||
return _ip;
|
||||
}
|
||||
|
||||
void Ban(uint32 time);
|
||||
void Disconnect();
|
||||
|
||||
|
@ -100,6 +100,7 @@ namespace Stratum
|
||||
{
|
||||
client->CloseSocket();
|
||||
_clients.erase(client);
|
||||
sLog.Debug(LOG_STRATUM, "Stratum client disconnected from %s. Total clients: %u", asio::ip::address_v4(client->GetIP()).to_string().c_str(), _clients.size());
|
||||
}
|
||||
|
||||
void Ban(uint32 ip, uint64 time)
|
||||
@ -133,9 +134,9 @@ namespace Stratum
|
||||
void _OnAccept(ClientPtr client, const boost::system::error_code& error)
|
||||
{
|
||||
if (!error) {
|
||||
sLog.Debug(LOG_STRATUM, "New stratum client accepted. Total clients: %u", _clients.size());
|
||||
client->Start();
|
||||
_clients.insert(client);
|
||||
sLog.Debug(LOG_STRATUM, "New stratum client accepted from %s. Total clients: %u", asio::ip::address_v4(client->GetIP()).to_string().c_str(), _clients.size());
|
||||
} else {
|
||||
sLog.Debug(LOG_STRATUM, "Failed to accept stratum client");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user