mirror of
https://github.com/SChernykh/p2pool.git
synced 2025-03-12 09:29:51 +00:00
TCPServer: optimized Client struct size
This commit is contained in:
parent
1dd06cc509
commit
d4e362cd76
5 changed files with 16 additions and 14 deletions
|
@ -443,7 +443,7 @@ struct log::Stream::Entry<PadRight<T>>
|
|||
|
||||
const int len = std::min<int>(data.m_len, log::Stream::BUF_SIZE);
|
||||
if (s.m_pos < len) {
|
||||
memset(buf + s.m_pos, ' ', len - s.m_pos);
|
||||
memset(buf + s.m_pos, ' ', static_cast<size_t>(len) - s.m_pos);
|
||||
s.m_pos = len;
|
||||
}
|
||||
|
||||
|
|
|
@ -806,9 +806,9 @@ void StratumServer::on_after_share_found(uv_work_t* req, int /*status*/)
|
|||
|
||||
StratumServer::StratumClient::StratumClient()
|
||||
: m_rpcId(0)
|
||||
, m_perConnectionJobId(0)
|
||||
, m_connectedTime(0)
|
||||
, m_jobs{}
|
||||
, m_perConnectionJobId(0)
|
||||
, m_customDiff{}
|
||||
, m_customUser{}
|
||||
{
|
||||
|
@ -824,9 +824,9 @@ void StratumServer::StratumClient::reset()
|
|||
{
|
||||
Client::reset();
|
||||
m_rpcId = 0;
|
||||
m_perConnectionJobId = 0;
|
||||
m_connectedTime = 0;
|
||||
memset(m_jobs, 0, sizeof(m_jobs));
|
||||
m_perConnectionJobId = 0;
|
||||
m_customDiff = {};
|
||||
memset(m_customUser, 0, sizeof(m_customUser));
|
||||
}
|
||||
|
|
|
@ -52,6 +52,7 @@ public:
|
|||
bool process_submit(rapidjson::Document& doc, uint32_t id);
|
||||
|
||||
uint32_t m_rpcId;
|
||||
uint32_t m_perConnectionJobId;
|
||||
uint64_t m_connectedTime;
|
||||
|
||||
uv_mutex_t m_jobsLock;
|
||||
|
@ -63,7 +64,6 @@ public:
|
|||
uint64_t target;
|
||||
} m_jobs[4];
|
||||
|
||||
uint32_t m_perConnectionJobId;
|
||||
difficulty_type m_customDiff;
|
||||
char m_customUser[32];
|
||||
};
|
||||
|
|
|
@ -70,6 +70,8 @@ public:
|
|||
|
||||
void init_addr_string(bool is_v6, const sockaddr_storage* peer_addr);
|
||||
|
||||
alignas(8) char m_readBuf[READ_BUF_SIZE];
|
||||
|
||||
TCPServer* m_owner;
|
||||
|
||||
// Used to maintain connected clients list
|
||||
|
@ -77,18 +79,16 @@ public:
|
|||
Client* m_next;
|
||||
|
||||
uv_tcp_t m_socket;
|
||||
uv_connect_t m_connectRequest;
|
||||
|
||||
bool m_isV6;
|
||||
bool m_isIncoming;
|
||||
bool m_readBufInUse;
|
||||
uint32_t m_numRead;
|
||||
|
||||
raw_ip m_addr;
|
||||
int m_port;
|
||||
char m_addrString[64];
|
||||
|
||||
bool m_readBufInUse;
|
||||
char m_readBuf[READ_BUF_SIZE];
|
||||
uint32_t m_numRead;
|
||||
|
||||
std::atomic<uint32_t> m_resetCounter{ 0 };
|
||||
};
|
||||
|
||||
|
|
|
@ -376,8 +376,11 @@ bool TCPServer<READ_BUF_SIZE, WRITE_BUF_SIZE>::connect_to_peer_nolock(Client* cl
|
|||
return false;
|
||||
}
|
||||
|
||||
client->m_connectRequest.data = client;
|
||||
err = uv_tcp_connect(&client->m_connectRequest, &client->m_socket, addr, on_connect);
|
||||
uv_connect_t* connect_request = reinterpret_cast<uv_connect_t*>(client->m_readBuf);
|
||||
memset(connect_request, 0, sizeof(uv_connect_t));
|
||||
|
||||
connect_request->data = client;
|
||||
err = uv_tcp_connect(connect_request, &client->m_socket, addr, on_connect);
|
||||
if (err) {
|
||||
LOGERR(1, "failed to initiate tcp connection, error " << uv_err_name(err));
|
||||
m_pendingConnections.erase(client->m_addr);
|
||||
|
@ -831,14 +834,13 @@ void TCPServer<READ_BUF_SIZE, WRITE_BUF_SIZE>::Client::reset()
|
|||
m_prev = nullptr;
|
||||
m_next = nullptr;
|
||||
memset(&m_socket, 0, sizeof(m_socket));
|
||||
memset(&m_connectRequest, 0, sizeof(m_connectRequest));
|
||||
m_isV6 = false;
|
||||
m_isIncoming = false;
|
||||
m_readBufInUse = false;
|
||||
m_numRead = 0;
|
||||
m_addr = {};
|
||||
m_port = -1;
|
||||
m_addrString[0] = '\0';
|
||||
m_readBufInUse = false;
|
||||
m_numRead = 0;
|
||||
}
|
||||
|
||||
template<size_t READ_BUF_SIZE, size_t WRITE_BUF_SIZE>
|
||||
|
|
Loading…
Reference in a new issue