diff --git a/common/thread/thread.h b/common/thread/thread.h index cbce84b..b19dd76 100644 --- a/common/thread/thread.h +++ b/common/thread/thread.h @@ -22,7 +22,7 @@ public: virtual void Start() { _stop = false; if (!_thread) { - _thread = std::make_shared(std::bind(&Thread::Run, this)); + _thread = std::unique_ptr(new std::thread(std::bind(&Thread::Run, this))); } } @@ -48,7 +48,7 @@ protected: protected: std::atomic_bool _stop; - std::shared_ptr _thread; + std::unique_ptr _thread; }; } diff --git a/common/timer/timer.cpp b/common/timer/timer.cpp index 52d2b43..e3226d2 100644 --- a/common/timer/timer.cpp +++ b/common/timer/timer.cpp @@ -10,23 +10,23 @@ namespace cppnet { -std::shared_ptr MakeTimer50Ms() { - return std::make_shared(); +std::unique_ptr MakeTimer50Ms() { + return std::unique_ptr(new Timer1ms()); } -std::shared_ptr MakeTimer1Sec() { +std::unique_ptr MakeTimer1Sec() { auto sub = MakeTimer50Ms(); - return std::make_shared(sub, TC_50MS, TC_1SEC); + return std::unique_ptr(new TimerContainer(std::move(sub), TC_50MS, TC_1SEC)); } -std::shared_ptr MakeTimer1Min() { +std::unique_ptr MakeTimer1Min() { auto sub = MakeTimer1Sec(); - return std::make_shared(sub, TC_1SEC, TC_1MIN); + return std::unique_ptr(new TimerContainer(std::move(sub), TC_1SEC, TC_1MIN)); } -std::shared_ptr MakeTimer1Hour() { +std::unique_ptr MakeTimer1Hour() { auto sub = MakeTimer1Min(); - return std::make_shared(sub, TC_1MIN, TC_1HOUR); + return std::unique_ptr(new TimerContainer(std::move(sub), TC_1MIN, TC_1HOUR)); } } \ No newline at end of file diff --git a/common/timer/timer.h b/common/timer/timer.h index 7387b06..a2e5860 100644 --- a/common/timer/timer.h +++ b/common/timer/timer.h @@ -11,13 +11,13 @@ namespace cppnet { -std::shared_ptr MakeTimer50Ms(); +std::unique_ptr MakeTimer50Ms(); -std::shared_ptr MakeTimer1Sec(); +std::unique_ptr MakeTimer1Sec(); -std::shared_ptr MakeTimer1Min(); +std::unique_ptr MakeTimer1Min(); -std::shared_ptr MakeTimer1Hour(); +std::unique_ptr MakeTimer1Hour(); } diff --git a/common/timer/timer_container.cpp b/common/timer/timer_container.cpp index a08e768..80953ff 100644 --- a/common/timer/timer_container.cpp +++ b/common/timer/timer_container.cpp @@ -10,12 +10,12 @@ namespace cppnet { -TimerContainer::TimerContainer(std::shared_ptr t, TIMER_CAPACITY accuracy, TIMER_CAPACITY capacity) : - _sub_timer(t), +TimerContainer::TimerContainer(std::unique_ptr t, TIMER_CAPACITY accuracy, TIMER_CAPACITY capacity) : + _sub_timer(std::move(t)), _cur_index(0), _accuracy(accuracy), _capacity(capacity) { - assert(t); + _max_size = capacity/accuracy; _timer_wheel.resize(_max_size); _bitmap.Init(_max_size); diff --git a/common/timer/timer_container.h b/common/timer/timer_container.h index bc4ad25..5960462 100644 --- a/common/timer/timer_container.h +++ b/common/timer/timer_container.h @@ -19,7 +19,7 @@ class TimerContainer: public Timer { public: - TimerContainer(std::shared_ptr t, TIMER_CAPACITY accuracy, TIMER_CAPACITY capacity); + TimerContainer(std::unique_ptr t, TIMER_CAPACITY accuracy, TIMER_CAPACITY capacity); ~TimerContainer(); bool AddTimer(std::weak_ptr t, uint32_t time, bool always = false); @@ -44,7 +44,7 @@ private: private: std::vector>> _timer_wheel; - std::shared_ptr _sub_timer; + std::unique_ptr _sub_timer; uint32_t _cur_index; Bitmap _bitmap; diff --git a/cppnet/cppnet_base.cpp b/cppnet/cppnet_base.cpp index fbe7fc3..f4a7777 100644 --- a/cppnet/cppnet_base.cpp +++ b/cppnet/cppnet_base.cpp @@ -44,7 +44,7 @@ void CppNetBase::Init(uint32_t thread_num) { if (thread_num == 0 || thread_num >= cpus * 2) { thread_num = cpus; } - _random = std::make_shared(0, thread_num - 1); + _random = std::unique_ptr(new RangeRandom(0, thread_num - 1)); #ifndef __win__ //Disable SIGPIPE signal diff --git a/cppnet/cppnet_base.h b/cppnet/cppnet_base.h index 3aa209e..9210340 100644 --- a/cppnet/cppnet_base.h +++ b/cppnet/cppnet_base.h @@ -64,7 +64,7 @@ private: connect_call_back _disconnect_cb; connect_call_back _accept_cb; - std::shared_ptr _random; + std::unique_ptr _random; std::vector> _dispatchers; }; diff --git a/cppnet/dispatcher.h b/cppnet/dispatcher.h index 176d2be..0494729 100644 --- a/cppnet/dispatcher.h +++ b/cppnet/dispatcher.h @@ -63,7 +63,7 @@ private: std::vector _task_list; std::thread::id _local_thread_id; - std::shared_ptr _timer; + std::unique_ptr _timer; std::shared_ptr _event_actions; std::weak_ptr _cppnet_base; diff --git a/cppnet/event/epoll/epoll_action.h b/cppnet/event/epoll/epoll_action.h index 1b6c1cc..a1af141 100644 --- a/cppnet/event/epoll/epoll_action.h +++ b/cppnet/event/epoll/epoll_action.h @@ -3,8 +3,8 @@ // Author: caozhiyi (caozhiyi5@gmail.com) -#ifndef NET_EVENT_LINUX_EPOLL_ACTION -#define NET_EVENT_LINUX_EPOLL_ACTION +#ifndef NET_EVENT_EPOLL_EPOLL_ACTION +#define NET_EVENT_EPOLL_EPOLL_ACTION #include #ifdef __win__ diff --git a/cppnet/event/kqueue/kqueue_action.h b/cppnet/event/kqueue/kqueue_action.h index 96ec81b..a131299 100644 --- a/cppnet/event/kqueue/kqueue_action.h +++ b/cppnet/event/kqueue/kqueue_action.h @@ -3,8 +3,8 @@ // Author: caozhiyi (caozhiyi5@gmail.com) -#ifndef NET_EVENT_MAC_KQUEUE_ACTION -#define NET_EVENT_MAC_KQUEUE_ACTION +#ifndef NET_EVENT_KQUEUE_KQUEUE_ACTION +#define NET_EVENT_KQUEUE_KQUEUE_ACTION #include #include diff --git a/cppnet/socket/connect_socket.cpp b/cppnet/socket/connect_socket.cpp index ce2971a..a954851 100644 --- a/cppnet/socket/connect_socket.cpp +++ b/cppnet/socket/connect_socket.cpp @@ -90,7 +90,7 @@ void ConnectSocket::Accept() { } void ConnectSocket::Close() { - + // TODO } void ConnectSocket::OnAccept() { diff --git a/cppnet/socket/rw_socket.cpp b/cppnet/socket/rw_socket.cpp index 17638c3..d6a249a 100644 --- a/cppnet/socket/rw_socket.cpp +++ b/cppnet/socket/rw_socket.cpp @@ -204,6 +204,7 @@ void RWSocket::OnConnect(uint16_t err) { void RWSocket::OnDisConnect(uint16_t err) { auto sock = shared_from_this(); __all_socket_map.erase(_sock); + LOG_ERROR("socket left num: %d, TheadId: %ld", __all_socket_map.size(), std::this_thread::get_id()); if (!IsShutdown()) { auto cppnet_base = _cppnet_base.lock();