1
This commit is contained in:
parent
f8b6660323
commit
60818be648
@ -39,6 +39,10 @@ link_directories(
|
|||||||
/usr/local/lib
|
/usr/local/lib
|
||||||
)
|
)
|
||||||
|
|
||||||
|
aux_source_directory(../../third_party/a8/a8/constant.cc
|
||||||
|
SRC_LIST
|
||||||
|
)
|
||||||
|
|
||||||
aux_source_directory(../../third_party/a8/a8
|
aux_source_directory(../../third_party/a8/a8
|
||||||
SRC_LIST
|
SRC_LIST
|
||||||
)
|
)
|
||||||
|
@ -1,4 +1,8 @@
|
|||||||
|
import a8m.constant;
|
||||||
|
|
||||||
int main(int argc, char* argv[])
|
int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
|
auto a = a8m::INVALID_SOCKET;
|
||||||
|
//a8m::INVALID_SOCKET = 100;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
15
third_party/a8/a8/constant.h
vendored
15
third_party/a8/a8/constant.h
vendored
@ -1,15 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
namespace a8
|
|
||||||
{
|
|
||||||
const int INVALID_FD = -1;
|
|
||||||
const int INVALID_SOCKET = -1;
|
|
||||||
const int INVALID_SOCKET_HANDLE = 0;
|
|
||||||
|
|
||||||
const int TIMER_EXEC_EVENT = 1;
|
|
||||||
const int TIMER_DELETE_EVENT = 2;
|
|
||||||
const int TIMER_DESTORY_EVENT = 3;
|
|
||||||
const int TIMER_USER_EVENT = 66;
|
|
||||||
|
|
||||||
const float A8_PI = 3.1415926f;
|
|
||||||
}
|
|
5
third_party/a8/a8/tcpclient.h
vendored
5
third_party/a8/a8/tcpclient.h
vendored
@ -11,7 +11,8 @@ namespace std
|
|||||||
#include <functional>
|
#include <functional>
|
||||||
|
|
||||||
#include <a8/types.h>
|
#include <a8/types.h>
|
||||||
#include <a8/constant.h>
|
|
||||||
|
import a8m.constant;
|
||||||
|
|
||||||
namespace a8
|
namespace a8
|
||||||
{
|
{
|
||||||
@ -38,7 +39,7 @@ namespace a8
|
|||||||
std::string remote_address_;
|
std::string remote_address_;
|
||||||
int remote_port_ = 0;
|
int remote_port_ = 0;
|
||||||
|
|
||||||
volatile int socket_ = a8::INVALID_SOCKET;
|
volatile int socket_ = a8m::INVALID_SOCKET();
|
||||||
volatile bool connected_ = false;
|
volatile bool connected_ = false;
|
||||||
volatile bool sender_thread_shutdown_ = false;
|
volatile bool sender_thread_shutdown_ = false;
|
||||||
volatile bool worker_thread_shutdown_ = false;
|
volatile bool worker_thread_shutdown_ = false;
|
||||||
|
37
third_party/a8/a8/tcplistener.cc
vendored
37
third_party/a8/a8/tcplistener.cc
vendored
@ -14,7 +14,8 @@
|
|||||||
#include <a8/tcpsession.h>
|
#include <a8/tcpsession.h>
|
||||||
#include <a8/tcpsessionpool.h>
|
#include <a8/tcpsessionpool.h>
|
||||||
#include <a8/types.h>
|
#include <a8/types.h>
|
||||||
#include <a8/constant.h>
|
|
||||||
|
import a8m.constant;
|
||||||
|
|
||||||
namespace a8
|
namespace a8
|
||||||
{
|
{
|
||||||
@ -22,7 +23,7 @@ namespace a8
|
|||||||
struct TcpListenerImpl
|
struct TcpListenerImpl
|
||||||
{
|
{
|
||||||
a8::TcpListener* master = nullptr;
|
a8::TcpListener* master = nullptr;
|
||||||
int listen_socket = a8::INVALID_SOCKET;
|
int listen_socket = a8m::INVALID_SOCKET();
|
||||||
std::thread* accept_thread = nullptr;
|
std::thread* accept_thread = nullptr;
|
||||||
std::thread* worker_thread = nullptr;
|
std::thread* worker_thread = nullptr;
|
||||||
volatile bool accept_thread_shutdown = false;
|
volatile bool accept_thread_shutdown = false;
|
||||||
@ -34,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;
|
||||||
volatile int epoll_fd = a8::INVALID_FD;
|
volatile int epoll_fd = a8m::INVALID_FD();
|
||||||
#if 0
|
#if 0
|
||||||
list_head session_list;
|
list_head session_list;
|
||||||
#endif
|
#endif
|
||||||
@ -44,7 +45,7 @@ namespace a8
|
|||||||
|
|
||||||
bool IsActive()
|
bool IsActive()
|
||||||
{
|
{
|
||||||
return listen_socket != a8::INVALID_SOCKET;
|
return listen_socket != a8m::INVALID_SOCKET();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetActive(bool active)
|
void SetActive(bool active)
|
||||||
@ -67,7 +68,7 @@ namespace a8
|
|||||||
bool ActiveStart()
|
bool ActiveStart()
|
||||||
{
|
{
|
||||||
listen_socket = ::socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
listen_socket = ::socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
||||||
if(listen_socket == a8::INVALID_SOCKET){
|
if(listen_socket == a8m::INVALID_SOCKET()){
|
||||||
if (master->on_error){
|
if (master->on_error){
|
||||||
master->on_error(master, a8::TCPLISTENER_E::TE_CREATE_ERR, errno);
|
master->on_error(master, a8::TCPLISTENER_E::TE_CREATE_ERR, errno);
|
||||||
}
|
}
|
||||||
@ -84,7 +85,7 @@ namespace a8
|
|||||||
master->on_error(master, a8::TCPLISTENER_E::TE_SETSOCKOPT_ERR, errno);
|
master->on_error(master, a8::TCPLISTENER_E::TE_SETSOCKOPT_ERR, errno);
|
||||||
}
|
}
|
||||||
::close(listen_socket);
|
::close(listen_socket);
|
||||||
listen_socket = a8::INVALID_SOCKET;
|
listen_socket = a8m::INVALID_SOCKET();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
sockaddr_in sa;
|
sockaddr_in sa;
|
||||||
@ -99,7 +100,7 @@ namespace a8
|
|||||||
master->on_error(master, a8::TCPLISTENER_E::TE_BIND_ERR, errno);
|
master->on_error(master, a8::TCPLISTENER_E::TE_BIND_ERR, errno);
|
||||||
}
|
}
|
||||||
::close(listen_socket);
|
::close(listen_socket);
|
||||||
listen_socket = a8::INVALID_SOCKET;
|
listen_socket = a8m::INVALID_SOCKET();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (::listen(listen_socket, max_clients) < 0) {
|
if (::listen(listen_socket, max_clients) < 0) {
|
||||||
@ -107,11 +108,11 @@ namespace a8
|
|||||||
master->on_error(master, a8::TCPLISTENER_E::TE_LISTEN_ERR, errno);
|
master->on_error(master, a8::TCPLISTENER_E::TE_LISTEN_ERR, errno);
|
||||||
}
|
}
|
||||||
::close(listen_socket);
|
::close(listen_socket);
|
||||||
listen_socket = a8::INVALID_SOCKET;
|
listen_socket = a8m::INVALID_SOCKET();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
epoll_fd = ::epoll_create(max_clients);
|
epoll_fd = ::epoll_create(max_clients);
|
||||||
assert(epoll_fd != a8::INVALID_FD);
|
assert(epoll_fd != a8m::INVALID_FD());
|
||||||
accept_thread_shutdown = false;
|
accept_thread_shutdown = false;
|
||||||
accept_thread = new std::thread(&a8::TcpListenerImpl::AcceptThreadProc, this);
|
accept_thread = new std::thread(&a8::TcpListenerImpl::AcceptThreadProc, this);
|
||||||
return true;
|
return true;
|
||||||
@ -119,14 +120,14 @@ namespace a8
|
|||||||
|
|
||||||
void ActiveStop()
|
void ActiveStop()
|
||||||
{
|
{
|
||||||
if (listen_socket != a8::INVALID_SOCKET) {
|
if (listen_socket != a8m::INVALID_SOCKET()) {
|
||||||
::shutdown(listen_socket, SHUT_RDWR);
|
::shutdown(listen_socket, SHUT_RDWR);
|
||||||
::close(listen_socket);
|
::close(listen_socket);
|
||||||
listen_socket = a8::INVALID_SOCKET;
|
listen_socket = a8m::INVALID_SOCKET();
|
||||||
}
|
}
|
||||||
if(epoll_fd != a8::INVALID_FD) {
|
if(epoll_fd != a8m::INVALID_FD()) {
|
||||||
::close(epoll_fd);
|
::close(epoll_fd);
|
||||||
epoll_fd = a8::INVALID_FD;
|
epoll_fd = a8m::INVALID_FD();
|
||||||
}
|
}
|
||||||
if (accept_thread) {
|
if (accept_thread) {
|
||||||
accept_thread_shutdown = true;
|
accept_thread_shutdown = true;
|
||||||
@ -304,13 +305,13 @@ namespace a8
|
|||||||
sockaddr_in addr;
|
sockaddr_in addr;
|
||||||
socklen_t addr_len = sizeof(sockaddr_in);
|
socklen_t addr_len = sizeof(sockaddr_in);
|
||||||
while (!accept_thread_shutdown) {
|
while (!accept_thread_shutdown) {
|
||||||
if (listen_socket == a8::INVALID_SOCKET) {
|
if (listen_socket == a8m::INVALID_SOCKET()) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
addr_len = sizeof(sockaddr_in);
|
addr_len = sizeof(sockaddr_in);
|
||||||
memset(&addr, 0, sizeof(addr));
|
memset(&addr, 0, sizeof(addr));
|
||||||
int sock = ::accept(listen_socket, (sockaddr*)&addr, (socklen_t*)&addr_len);
|
int sock = ::accept(listen_socket, (sockaddr*)&addr, (socklen_t*)&addr_len);
|
||||||
if (sock != a8::INVALID_SOCKET) {
|
if (sock != a8m::INVALID_SOCKET()) {
|
||||||
if (accept_thread_shutdown) {
|
if (accept_thread_shutdown) {
|
||||||
::close(sock);
|
::close(sock);
|
||||||
} else {
|
} else {
|
||||||
@ -361,7 +362,7 @@ namespace a8
|
|||||||
list_del_init(&session->session_entry);
|
list_del_init(&session->session_entry);
|
||||||
#endif
|
#endif
|
||||||
client_hash.erase(itr);
|
client_hash.erase(itr);
|
||||||
if (session->Socket() != a8::INVALID_SOCKET) {
|
if (session->Socket() != a8m::INVALID_SOCKET()) {
|
||||||
session->_ForceClose();
|
session->_ForceClose();
|
||||||
}
|
}
|
||||||
client_handle_hash.erase(session->socket_handle);
|
client_handle_hash.erase(session->socket_handle);
|
||||||
@ -427,7 +428,7 @@ namespace a8
|
|||||||
|
|
||||||
bool TcpListener::IsActive()
|
bool TcpListener::IsActive()
|
||||||
{
|
{
|
||||||
return impl_->listen_socket != a8::INVALID_SOCKET;
|
return impl_->listen_socket != a8m::INVALID_SOCKET();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TcpListener::SendClientMsg(unsigned short sockhandle, const char *buff, int buffLen)
|
bool TcpListener::SendClientMsg(unsigned short sockhandle, const char *buff, int buffLen)
|
||||||
@ -457,7 +458,7 @@ namespace a8
|
|||||||
impl_->clients_mutex.lock();
|
impl_->clients_mutex.lock();
|
||||||
a8::TcpSession *p = GetClientSession(sockhandle);
|
a8::TcpSession *p = GetClientSession(sockhandle);
|
||||||
if(p){
|
if(p){
|
||||||
if(p->Socket() != a8::INVALID_SOCKET){
|
if(p->Socket() != a8m::INVALID_SOCKET()){
|
||||||
p->_ForceClose();
|
p->_ForceClose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
5
third_party/a8/a8/udplistener.cc
vendored
5
third_party/a8/a8/udplistener.cc
vendored
@ -12,13 +12,14 @@
|
|||||||
#include <functional>
|
#include <functional>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
|
||||||
#include <a8/constant.h>
|
|
||||||
#include <a8/udplistener.h>
|
#include <a8/udplistener.h>
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
#include <f8/udplog.h>
|
#include <f8/udplog.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
import a8m.constant;
|
||||||
|
|
||||||
namespace a8
|
namespace a8
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -76,7 +77,7 @@ namespace a8
|
|||||||
master->on_error(errno);
|
master->on_error(errno);
|
||||||
}
|
}
|
||||||
::close(listen_socket);
|
::close(listen_socket);
|
||||||
listen_socket = a8::INVALID_SOCKET;
|
listen_socket = a8m::INVALID_SOCKET();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
sockaddr_in sa;
|
sockaddr_in sa;
|
||||||
|
11
third_party/a8/a8/xtimer.cc
vendored
11
third_party/a8/a8/xtimer.cc
vendored
@ -1,8 +1,9 @@
|
|||||||
#include <a8/xtimer.h>
|
#include <a8/xtimer.h>
|
||||||
#include <a8/constant.h>
|
|
||||||
#include <a8/macro.h>
|
#include <a8/macro.h>
|
||||||
#include <a8/timer_attacher.h>
|
#include <a8/timer_attacher.h>
|
||||||
|
|
||||||
|
import a8m.constant;
|
||||||
|
|
||||||
enum TimerType_e
|
enum TimerType_e
|
||||||
{
|
{
|
||||||
kTimeOutTimer = 0,
|
kTimeOutTimer = 0,
|
||||||
@ -144,7 +145,7 @@ namespace a8
|
|||||||
(gc_time_,
|
(gc_time_,
|
||||||
[this] (int event, const a8::Args* args)
|
[this] (int event, const a8::Args* args)
|
||||||
{
|
{
|
||||||
if (a8::TIMER_EXEC_EVENT == event) {
|
if (a8m::TIMER_EXEC_EVENT() == event) {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
while (!list_empty(&base_->free_timer) &&
|
while (!list_empty(&base_->free_timer) &&
|
||||||
base_->free_timer_num > cache_timer_num_ && i < 1000) {
|
base_->free_timer_num > cache_timer_num_ && i < 1000) {
|
||||||
@ -244,11 +245,11 @@ namespace a8
|
|||||||
#endif
|
#endif
|
||||||
if (is_destory) {
|
if (is_destory) {
|
||||||
if (timer->cb) {
|
if (timer->cb) {
|
||||||
timer->cb(TIMER_DESTORY_EVENT, nullptr);
|
timer->cb(a8m::TIMER_DESTORY_EVENT(), nullptr);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (timer->cb) {
|
if (timer->cb) {
|
||||||
timer->cb(TIMER_DELETE_EVENT, nullptr);
|
timer->cb(a8m::TIMER_DELETE_EVENT(), nullptr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
timer->cb = nullptr;
|
timer->cb = nullptr;
|
||||||
@ -343,7 +344,7 @@ namespace a8
|
|||||||
timer = list_first_entry(head, struct xtimer_list,entry);
|
timer = list_first_entry(head, struct xtimer_list,entry);
|
||||||
base->running_timer = timer;
|
base->running_timer = timer;
|
||||||
if (timer->cb) {
|
if (timer->cb) {
|
||||||
timer->cb(TIMER_EXEC_EVENT, nullptr);
|
timer->cb(a8m::TIMER_EXEC_EVENT(), nullptr);
|
||||||
}
|
}
|
||||||
if (base_->running_timer) {
|
if (base_->running_timer) {
|
||||||
switch (timer->timer_type) {
|
switch (timer->timer_type) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user