1
This commit is contained in:
parent
b2d8c32b70
commit
c0baee9980
@ -1,6 +1,8 @@
|
|||||||
#ifndef A8_TCPLISTENER_H
|
#ifndef A8_TCPLISTENER_H
|
||||||
#define A8_TCPLISTENER_H
|
#define A8_TCPLISTENER_H
|
||||||
|
|
||||||
|
#include <atomic>
|
||||||
|
|
||||||
namespace a8
|
namespace a8
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -22,6 +24,7 @@ namespace a8
|
|||||||
std::function<void (a8::TcpListener*, a8::TCPLISTENER_E, int)> on_error;
|
std::function<void (a8::TcpListener*, a8::TCPLISTENER_E, int)> on_error;
|
||||||
std::string bind_address;
|
std::string bind_address;
|
||||||
unsigned short bind_port = 0;
|
unsigned short bind_port = 0;
|
||||||
|
std::atomic<long long> send_node_num = {0};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
TcpListener(unsigned short max_client_cnt=0xEFFF);
|
TcpListener(unsigned short max_client_cnt=0xEFFF);
|
||||||
|
@ -136,6 +136,7 @@ namespace a8
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
send_buffer_mutex_.unlock();
|
send_buffer_mutex_.unlock();
|
||||||
|
++master->send_node_num;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -161,6 +162,7 @@ namespace a8
|
|||||||
void TcpSession::Reset()
|
void TcpSession::Reset()
|
||||||
{
|
{
|
||||||
ClearSendBuff();
|
ClearSendBuff();
|
||||||
|
ClearWorkBuff();
|
||||||
socket_ = -1;
|
socket_ = -1;
|
||||||
remote_address = "";
|
remote_address = "";
|
||||||
remote_port = 0;
|
remote_port = 0;
|
||||||
@ -182,6 +184,7 @@ namespace a8
|
|||||||
}
|
}
|
||||||
Close();
|
Close();
|
||||||
ClearSendBuff();
|
ClearSendBuff();
|
||||||
|
ClearWorkBuff();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TcpSession::_ForceClose()
|
void TcpSession::_ForceClose()
|
||||||
@ -299,13 +302,10 @@ namespace a8
|
|||||||
void TcpSession::ClearSendBuff()
|
void TcpSession::ClearSendBuff()
|
||||||
{
|
{
|
||||||
a8::SendQueueNode* p_top_node_ = nullptr;
|
a8::SendQueueNode* p_top_node_ = nullptr;
|
||||||
a8::SendQueueNode* p_work_node_ = nullptr;
|
|
||||||
send_buffer_mutex_.lock();
|
send_buffer_mutex_.lock();
|
||||||
p_top_node_ = top_node_;
|
p_top_node_ = top_node_;
|
||||||
p_work_node_ = work_node_;
|
|
||||||
top_node_ = nullptr;
|
top_node_ = nullptr;
|
||||||
bot_node_ = nullptr;
|
bot_node_ = nullptr;
|
||||||
work_node_ = nullptr;
|
|
||||||
send_buffer_mutex_.unlock();
|
send_buffer_mutex_.unlock();
|
||||||
|
|
||||||
a8::SendQueueNode *pdelnode = nullptr;
|
a8::SendQueueNode *pdelnode = nullptr;
|
||||||
@ -316,14 +316,20 @@ namespace a8
|
|||||||
free(pdelnode->buff);
|
free(pdelnode->buff);
|
||||||
}
|
}
|
||||||
free(pdelnode);
|
free(pdelnode);
|
||||||
|
--master->send_node_num;
|
||||||
}
|
}
|
||||||
while (p_work_node_) {
|
}
|
||||||
pdelnode = p_work_node_;
|
|
||||||
p_work_node_ = p_work_node_->next;
|
void TcpSession::ClearWorkBuff()
|
||||||
|
{
|
||||||
|
while (work_node_) {
|
||||||
|
a8::SendQueueNode *pdelnode = work_node_;
|
||||||
|
work_node_ = work_node_->next;
|
||||||
if (pdelnode->buff) {
|
if (pdelnode->buff) {
|
||||||
free(pdelnode->buff);
|
free(pdelnode->buff);
|
||||||
}
|
}
|
||||||
free(pdelnode);
|
free(pdelnode);
|
||||||
|
--master->send_node_num;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -347,6 +353,7 @@ namespace a8
|
|||||||
if (work_node_->sent_bytes >= work_node_->bufflen) {
|
if (work_node_->sent_bytes >= work_node_->bufflen) {
|
||||||
a8::SendQueueNode *pdelnode = work_node_;
|
a8::SendQueueNode *pdelnode = work_node_;
|
||||||
work_node_ = work_node_->next;
|
work_node_ = work_node_->next;
|
||||||
|
--master->send_node_num;
|
||||||
if (!work_node_) {
|
if (!work_node_) {
|
||||||
send_buffer_mutex_.lock();
|
send_buffer_mutex_.lock();
|
||||||
if (top_node_) {
|
if (top_node_) {
|
||||||
|
@ -52,6 +52,7 @@ namespace a8
|
|||||||
private:
|
private:
|
||||||
|
|
||||||
void ClearSendBuff();
|
void ClearSendBuff();
|
||||||
|
void ClearWorkBuff();
|
||||||
void AsyncSend();
|
void AsyncSend();
|
||||||
void NotifyEpollSend();
|
void NotifyEpollSend();
|
||||||
int DirectSend(a8::SendQueueNode* node);
|
int DirectSend(a8::SendQueueNode* node);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user