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