diff --git a/server/mymangosd/CMakeLists.txt b/server/mymangosd/CMakeLists.txt index a6f9892..773908a 100644 --- a/server/mymangosd/CMakeLists.txt +++ b/server/mymangosd/CMakeLists.txt @@ -39,6 +39,10 @@ link_directories( /usr/local/lib ) +aux_source_directory(../../third_party/a8/a8/constant.cc + SRC_LIST +) + aux_source_directory(../../third_party/a8/a8 SRC_LIST ) diff --git a/server/mymangosd/main.cc b/server/mymangosd/main.cc index 489dfc7..7206870 100644 --- a/server/mymangosd/main.cc +++ b/server/mymangosd/main.cc @@ -1,4 +1,8 @@ +import a8m.constant; + int main(int argc, char* argv[]) { + auto a = a8m::INVALID_SOCKET; + //a8m::INVALID_SOCKET = 100; return 0; } diff --git a/third_party/a8/a8/constant.h b/third_party/a8/a8/constant.h deleted file mode 100644 index dcc44e2..0000000 --- a/third_party/a8/a8/constant.h +++ /dev/null @@ -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; -} diff --git a/third_party/a8/a8/tcpclient.h b/third_party/a8/a8/tcpclient.h index 28c0d48..709b84d 100644 --- a/third_party/a8/a8/tcpclient.h +++ b/third_party/a8/a8/tcpclient.h @@ -11,7 +11,8 @@ namespace std #include #include -#include + +import a8m.constant; namespace a8 { @@ -38,7 +39,7 @@ namespace a8 std::string remote_address_; int remote_port_ = 0; - volatile int socket_ = a8::INVALID_SOCKET; + volatile int socket_ = a8m::INVALID_SOCKET(); volatile bool connected_ = false; volatile bool sender_thread_shutdown_ = false; volatile bool worker_thread_shutdown_ = false; diff --git a/third_party/a8/a8/tcplistener.cc b/third_party/a8/a8/tcplistener.cc index e66d4a3..723d809 100644 --- a/third_party/a8/a8/tcplistener.cc +++ b/third_party/a8/a8/tcplistener.cc @@ -14,7 +14,8 @@ #include #include #include -#include + +import a8m.constant; namespace a8 { @@ -22,7 +23,7 @@ namespace a8 struct TcpListenerImpl { a8::TcpListener* master = nullptr; - int listen_socket = a8::INVALID_SOCKET; + int listen_socket = a8m::INVALID_SOCKET(); std::thread* accept_thread = nullptr; std::thread* worker_thread = nullptr; volatile bool accept_thread_shutdown = false; @@ -34,7 +35,7 @@ namespace a8 unsigned short curr_socket_handle = 1000; unsigned short max_clients = 0xEFFF; a8::TcpSessionPool free_client_pool; - volatile int epoll_fd = a8::INVALID_FD; + volatile int epoll_fd = a8m::INVALID_FD(); #if 0 list_head session_list; #endif @@ -44,7 +45,7 @@ namespace a8 bool IsActive() { - return listen_socket != a8::INVALID_SOCKET; + return listen_socket != a8m::INVALID_SOCKET(); } void SetActive(bool active) @@ -67,7 +68,7 @@ namespace a8 bool ActiveStart() { 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){ 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); } ::close(listen_socket); - listen_socket = a8::INVALID_SOCKET; + listen_socket = a8m::INVALID_SOCKET(); return false; } sockaddr_in sa; @@ -99,7 +100,7 @@ namespace a8 master->on_error(master, a8::TCPLISTENER_E::TE_BIND_ERR, errno); } ::close(listen_socket); - listen_socket = a8::INVALID_SOCKET; + listen_socket = a8m::INVALID_SOCKET(); return false; } if (::listen(listen_socket, max_clients) < 0) { @@ -107,11 +108,11 @@ namespace a8 master->on_error(master, a8::TCPLISTENER_E::TE_LISTEN_ERR, errno); } ::close(listen_socket); - listen_socket = a8::INVALID_SOCKET; + listen_socket = a8m::INVALID_SOCKET(); return false; } epoll_fd = ::epoll_create(max_clients); - assert(epoll_fd != a8::INVALID_FD); + assert(epoll_fd != a8m::INVALID_FD()); accept_thread_shutdown = false; accept_thread = new std::thread(&a8::TcpListenerImpl::AcceptThreadProc, this); return true; @@ -119,14 +120,14 @@ namespace a8 void ActiveStop() { - if (listen_socket != a8::INVALID_SOCKET) { + if (listen_socket != a8m::INVALID_SOCKET()) { ::shutdown(listen_socket, SHUT_RDWR); ::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); - epoll_fd = a8::INVALID_FD; + epoll_fd = a8m::INVALID_FD(); } if (accept_thread) { accept_thread_shutdown = true; @@ -304,13 +305,13 @@ namespace a8 sockaddr_in addr; socklen_t addr_len = sizeof(sockaddr_in); while (!accept_thread_shutdown) { - if (listen_socket == a8::INVALID_SOCKET) { + if (listen_socket == a8m::INVALID_SOCKET()) { break; } addr_len = sizeof(sockaddr_in); memset(&addr, 0, sizeof(addr)); 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) { ::close(sock); } else { @@ -361,7 +362,7 @@ namespace a8 list_del_init(&session->session_entry); #endif client_hash.erase(itr); - if (session->Socket() != a8::INVALID_SOCKET) { + if (session->Socket() != a8m::INVALID_SOCKET()) { session->_ForceClose(); } client_handle_hash.erase(session->socket_handle); @@ -427,7 +428,7 @@ namespace a8 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) @@ -457,7 +458,7 @@ namespace a8 impl_->clients_mutex.lock(); a8::TcpSession *p = GetClientSession(sockhandle); if(p){ - if(p->Socket() != a8::INVALID_SOCKET){ + if(p->Socket() != a8m::INVALID_SOCKET()){ p->_ForceClose(); } } diff --git a/third_party/a8/a8/udplistener.cc b/third_party/a8/a8/udplistener.cc index 2f66180..909ae9d 100644 --- a/third_party/a8/a8/udplistener.cc +++ b/third_party/a8/a8/udplistener.cc @@ -12,13 +12,14 @@ #include #include -#include #include #if 0 #include #endif +import a8m.constant; + namespace a8 { @@ -76,7 +77,7 @@ namespace a8 master->on_error(errno); } ::close(listen_socket); - listen_socket = a8::INVALID_SOCKET; + listen_socket = a8m::INVALID_SOCKET(); return false; } sockaddr_in sa; diff --git a/third_party/a8/a8/xtimer.cc b/third_party/a8/a8/xtimer.cc index 9224fc0..97dad89 100644 --- a/third_party/a8/a8/xtimer.cc +++ b/third_party/a8/a8/xtimer.cc @@ -1,8 +1,9 @@ #include -#include #include #include +import a8m.constant; + enum TimerType_e { kTimeOutTimer = 0, @@ -144,7 +145,7 @@ namespace a8 (gc_time_, [this] (int event, const a8::Args* args) { - if (a8::TIMER_EXEC_EVENT == event) { + if (a8m::TIMER_EXEC_EVENT() == event) { int i = 0; while (!list_empty(&base_->free_timer) && base_->free_timer_num > cache_timer_num_ && i < 1000) { @@ -244,11 +245,11 @@ namespace a8 #endif if (is_destory) { if (timer->cb) { - timer->cb(TIMER_DESTORY_EVENT, nullptr); + timer->cb(a8m::TIMER_DESTORY_EVENT(), nullptr); } } else { if (timer->cb) { - timer->cb(TIMER_DELETE_EVENT, nullptr); + timer->cb(a8m::TIMER_DELETE_EVENT(), nullptr); } } timer->cb = nullptr; @@ -343,7 +344,7 @@ namespace a8 timer = list_first_entry(head, struct xtimer_list,entry); base->running_timer = timer; if (timer->cb) { - timer->cb(TIMER_EXEC_EVENT, nullptr); + timer->cb(a8m::TIMER_EXEC_EVENT(), nullptr); } if (base_->running_timer) { switch (timer->timer_type) {