性能优化改为lt模式
This commit is contained in:
parent
f6748a84c8
commit
0765079661
@ -35,7 +35,7 @@ namespace a8
|
|||||||
unsigned short curr_socket_handle = 1000;
|
unsigned short curr_socket_handle = 1000;
|
||||||
unsigned short max_clients = 0xEFFF;
|
unsigned short max_clients = 0xEFFF;
|
||||||
a8::TcpSessionPool free_client_pool;
|
a8::TcpSessionPool free_client_pool;
|
||||||
int epoll_fd = a8::INVALID_FD;
|
volatile int epoll_fd = a8::INVALID_FD;
|
||||||
#if 0
|
#if 0
|
||||||
list_head session_list;
|
list_head session_list;
|
||||||
#endif
|
#endif
|
||||||
@ -121,9 +121,14 @@ namespace a8
|
|||||||
void ActiveStop()
|
void ActiveStop()
|
||||||
{
|
{
|
||||||
if (listen_socket != a8::INVALID_SOCKET) {
|
if (listen_socket != a8::INVALID_SOCKET) {
|
||||||
|
::shutdown(listen_socket, SHUT_RDWR);
|
||||||
::close(listen_socket);
|
::close(listen_socket);
|
||||||
listen_socket = a8::INVALID_SOCKET;
|
listen_socket = a8::INVALID_SOCKET;
|
||||||
}
|
}
|
||||||
|
if(epoll_fd != a8::INVALID_FD) {
|
||||||
|
::close(epoll_fd);
|
||||||
|
epoll_fd = a8::INVALID_FD;
|
||||||
|
}
|
||||||
if (accept_thread) {
|
if (accept_thread) {
|
||||||
accept_thread_shutdown = true;
|
accept_thread_shutdown = true;
|
||||||
accept_thread->join();
|
accept_thread->join();
|
||||||
@ -136,9 +141,17 @@ namespace a8
|
|||||||
delete worker_thread;
|
delete worker_thread;
|
||||||
worker_thread = nullptr;
|
worker_thread = nullptr;
|
||||||
}
|
}
|
||||||
if(epoll_fd != a8::INVALID_FD) {
|
{
|
||||||
::close(epoll_fd);
|
clients_mutex.lock();
|
||||||
epoll_fd = a8::INVALID_FD;
|
std::vector<a8::TcpSession*> del_sessions;
|
||||||
|
for (auto& pair : client_hash) {
|
||||||
|
del_sessions.push_back(pair.second);
|
||||||
|
}
|
||||||
|
for (a8::TcpSession* session : del_sessions) {
|
||||||
|
session->_ForceClose();
|
||||||
|
}
|
||||||
|
client_hash.clear();
|
||||||
|
clients_mutex.unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -274,6 +287,9 @@ namespace a8
|
|||||||
ev.events = EPOLLIN | EPOLLET | EPOLLRDHUP;
|
ev.events = EPOLLIN | EPOLLET | EPOLLRDHUP;
|
||||||
#else
|
#else
|
||||||
ev.events = EPOLLIN | EPOLLOUT | EPOLLET | EPOLLRDHUP;
|
ev.events = EPOLLIN | EPOLLOUT | EPOLLET | EPOLLRDHUP;
|
||||||
|
#endif
|
||||||
|
#ifdef A8_TCP_SESSION2
|
||||||
|
ev.events = EPOLLIN | EPOLLRDHUP;
|
||||||
#endif
|
#endif
|
||||||
ev.data.ptr = p;
|
ev.data.ptr = p;
|
||||||
int n = ::epoll_ctl(epoll_fd, EPOLL_CTL_ADD, sock, &ev);
|
int n = ::epoll_ctl(epoll_fd, EPOLL_CTL_ADD, sock, &ev);
|
||||||
@ -350,6 +366,7 @@ namespace a8
|
|||||||
session->_ForceClose();
|
session->_ForceClose();
|
||||||
}
|
}
|
||||||
client_handle_hash.erase(session->socket_handle);
|
client_handle_hash.erase(session->socket_handle);
|
||||||
|
session->ClearSendBuff();
|
||||||
session->OnDisConnect();
|
session->OnDisConnect();
|
||||||
free_client_pool.Add(session);
|
free_client_pool.Add(session);
|
||||||
client_count--;
|
client_count--;
|
||||||
|
@ -81,6 +81,18 @@ namespace a8
|
|||||||
memmove(p->buff, buff, bufflen);
|
memmove(p->buff, buff, bufflen);
|
||||||
p->bufflen = bufflen;
|
p->bufflen = bufflen;
|
||||||
send_buffer_mutex_.lock();
|
send_buffer_mutex_.lock();
|
||||||
|
#if 1
|
||||||
|
if (bot_node_) {
|
||||||
|
bot_node_->next = p;
|
||||||
|
bot_node_ = p;
|
||||||
|
} else {
|
||||||
|
top_node_ = p;
|
||||||
|
bot_node_ = p;
|
||||||
|
}
|
||||||
|
if (!sending_) {
|
||||||
|
NotifyEpollSend();
|
||||||
|
}
|
||||||
|
#else
|
||||||
if (sending_) {
|
if (sending_) {
|
||||||
if (bot_node_) {
|
if (bot_node_) {
|
||||||
bot_node_->next = p;
|
bot_node_->next = p;
|
||||||
@ -123,6 +135,7 @@ namespace a8
|
|||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
send_buffer_mutex_.unlock();
|
send_buffer_mutex_.unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -344,6 +357,11 @@ namespace a8
|
|||||||
}
|
}
|
||||||
if (!work_node_) {
|
if (!work_node_) {
|
||||||
sending_ = false;
|
sending_ = false;
|
||||||
|
struct epoll_event ev;
|
||||||
|
ev.data.fd = socket_;
|
||||||
|
ev.events = EPOLLIN | EPOLLRDHUP;
|
||||||
|
ev.data.ptr = this;
|
||||||
|
::epoll_ctl(epoll_fd, EPOLL_CTL_MOD, socket_, &ev);
|
||||||
}
|
}
|
||||||
send_buffer_mutex_.unlock();
|
send_buffer_mutex_.unlock();
|
||||||
}
|
}
|
||||||
@ -360,7 +378,7 @@ namespace a8
|
|||||||
sending_ = true;
|
sending_ = true;
|
||||||
struct epoll_event ev;
|
struct epoll_event ev;
|
||||||
ev.data.fd = socket_;
|
ev.data.fd = socket_;
|
||||||
ev.events = EPOLLIN | EPOLLET | EPOLLOUT | EPOLLRDHUP;
|
ev.events = EPOLLIN | EPOLLOUT | EPOLLRDHUP;
|
||||||
ev.data.ptr = this;
|
ev.data.ptr = this;
|
||||||
::epoll_ctl(epoll_fd, EPOLL_CTL_MOD, socket_, &ev);
|
::epoll_ctl(epoll_fd, EPOLL_CTL_MOD, socket_, &ev);
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,11 @@
|
|||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
#include <a8/a8.h>
|
#include <a8/a8.h>
|
||||||
|
#ifdef A8_TCP_SESSION2
|
||||||
|
#include <a8/tcpsession2.h>
|
||||||
|
#else
|
||||||
#include <a8/tcpsession.h>
|
#include <a8/tcpsession.h>
|
||||||
|
#endif
|
||||||
#include <a8/tcpsessionpool.h>
|
#include <a8/tcpsessionpool.h>
|
||||||
|
|
||||||
namespace a8
|
namespace a8
|
||||||
|
17
a8/udplog.cc
17
a8/udplog.cc
@ -66,6 +66,23 @@ namespace a8
|
|||||||
impl_->save_thread->join();
|
impl_->save_thread->join();
|
||||||
delete impl_->save_thread;
|
delete impl_->save_thread;
|
||||||
impl_->save_thread = nullptr;
|
impl_->save_thread = nullptr;
|
||||||
|
impl_->msg_mutex.lock();
|
||||||
|
if (impl_->work_node) {
|
||||||
|
impl_->work_node = impl_->top_node;
|
||||||
|
impl_->top_node = nullptr;
|
||||||
|
impl_->bot_node = nullptr;
|
||||||
|
}
|
||||||
|
while (impl_->work_node) {
|
||||||
|
UdpLogMsgNode* pdelnode = impl_->work_node;
|
||||||
|
impl_->work_node = impl_->work_node->next;
|
||||||
|
if (!impl_->work_node) {
|
||||||
|
impl_->work_node = impl_->top_node;
|
||||||
|
impl_->top_node = nullptr;
|
||||||
|
impl_->bot_node = nullptr;
|
||||||
|
}
|
||||||
|
delete pdelnode;
|
||||||
|
}
|
||||||
|
impl_->msg_mutex.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
void UdpLog::SetLogFileName(const std::string& filename)
|
void UdpLog::SetLogFileName(const std::string& filename)
|
||||||
|
10
a8/xvalue.cc
10
a8/xvalue.cc
@ -172,6 +172,11 @@ namespace a8
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void XValue::Set(const std::string& v)
|
||||||
|
{
|
||||||
|
SetDynData(v.data(), v.size());
|
||||||
|
}
|
||||||
|
|
||||||
void XValue::Set(const wchar_t* v)
|
void XValue::Set(const wchar_t* v)
|
||||||
{
|
{
|
||||||
OnReset();
|
OnReset();
|
||||||
@ -462,6 +467,11 @@ namespace a8
|
|||||||
|
|
||||||
const a8::XValue& XValue::operator=(const a8::XValue& xv)
|
const a8::XValue& XValue::operator=(const a8::XValue& xv)
|
||||||
{
|
{
|
||||||
|
if (type_ == XVT_STRING && value_.str_value){
|
||||||
|
free(value_.str_value);
|
||||||
|
}else if (type_ == XVT_WSTRING && value_.wstr_value){
|
||||||
|
free(value_.wstr_value);
|
||||||
|
}
|
||||||
type_ = XVT_INT;
|
type_ = XVT_INT;
|
||||||
value_.int_value = 0;
|
value_.int_value = 0;
|
||||||
data_size_ = 0;
|
data_size_ = 0;
|
||||||
|
@ -41,6 +41,7 @@ namespace a8
|
|||||||
void Set(long long v);
|
void Set(long long v);
|
||||||
void Set(unsigned long long v);
|
void Set(unsigned long long v);
|
||||||
void Set(const char* v);
|
void Set(const char* v);
|
||||||
|
void Set(const std::string& v);
|
||||||
void Set(const wchar_t* v);
|
void Set(const wchar_t* v);
|
||||||
void SetDynData(const char* v, unsigned int len);
|
void SetDynData(const char* v, unsigned int len);
|
||||||
void SetUserData(void *userdata, int datasize);
|
void SetUserData(void *userdata, int datasize);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user