ithewei преди 2 години
родител
ревизия
6675a3d62f
променени са 4 файла, в които са добавени 28 реда и са изтрити 4 реда
  1. 7 1
      evpp/TcpClient.h
  2. 7 1
      evpp/TcpServer.h
  3. 7 1
      evpp/UdpClient.h
  4. 7 1
      evpp/UdpServer.h

+ 7 - 1
evpp/TcpClient.h

@@ -260,6 +260,7 @@ public:
     TcpClientTmpl(EventLoopPtr loop = NULL)
         : EventLoopThread(loop)
         , TcpClientEventLoopTmpl<TSocketChannel>(EventLoopThread::loop())
+        , is_loop_owner(loop == NULL)
     {}
     virtual ~TcpClientTmpl() {
         stop(true);
@@ -281,8 +282,13 @@ public:
     // stop thread-safe
     void stop(bool wait_threads_stopped = true) {
         TcpClientEventLoopTmpl<TSocketChannel>::closesocket();
-        EventLoopThread::stop(wait_threads_stopped);
+        if (is_loop_owner) {
+            EventLoopThread::stop(wait_threads_stopped);
+        }
     }
+
+private:
+    bool is_loop_owner;
 };
 
 typedef TcpClientTmpl<SocketChannel> TcpClient;

+ 7 - 1
evpp/TcpServer.h

@@ -281,6 +281,7 @@ public:
     TcpServerTmpl(EventLoopPtr loop = NULL)
         : EventLoopThread(loop)
         , TcpServerEventLoopTmpl<TSocketChannel>(EventLoopThread::loop())
+        , is_loop_owner(loop == NULL)
     {}
     virtual ~TcpServerTmpl() {
         stop(true);
@@ -298,9 +299,14 @@ public:
 
     // stop thread-safe
     void stop(bool wait_threads_stopped = true) {
-        EventLoopThread::stop(wait_threads_stopped);
+        if (is_loop_owner) {
+            EventLoopThread::stop(wait_threads_stopped);
+        }
         TcpServerEventLoopTmpl<TSocketChannel>::stop(wait_threads_stopped);
     }
+
+private:
+    bool is_loop_owner;
 };
 
 typedef TcpServerTmpl<SocketChannel> TcpServer;

+ 7 - 1
evpp/UdpClient.h

@@ -153,6 +153,7 @@ public:
     UdpClientTmpl(EventLoopPtr loop = NULL)
         : EventLoopThread(loop)
         , UdpClientEventLoopTmpl<TSocketChannel>(EventLoopThread::loop())
+        , is_loop_owner(loop == NULL)
     {}
     virtual ~UdpClientTmpl() {
         stop(true);
@@ -174,8 +175,13 @@ public:
     // stop thread-safe
     void stop(bool wait_threads_stopped = true) {
         UdpClientEventLoopTmpl<TSocketChannel>::closesocket();
-        EventLoopThread::stop(wait_threads_stopped);
+        if (is_loop_owner) {
+            EventLoopThread::stop(wait_threads_stopped);
+        }
     }
+
+private:
+    bool is_loop_owner;
 };
 
 typedef UdpClientTmpl<SocketChannel> UdpClient;

+ 7 - 1
evpp/UdpServer.h

@@ -132,6 +132,7 @@ public:
     UdpServerTmpl(EventLoopPtr loop = NULL)
         : EventLoopThread(loop)
         , UdpServerEventLoopTmpl<TSocketChannel>(EventLoopThread::loop())
+        , is_loop_owner(loop == NULL)
     {}
     virtual ~UdpServerTmpl() {
         stop(true);
@@ -153,8 +154,13 @@ public:
     // stop thread-safe
     void stop(bool wait_threads_stopped = true) {
         UdpServerEventLoopTmpl<TSocketChannel>::closesocket();
-        EventLoopThread::stop(wait_threads_stopped);
+        if (is_loop_owner) {
+            EventLoopThread::stop(wait_threads_stopped);
+        }
     }
+
+private:
+    bool is_loop_owner;
 };
 
 typedef UdpServerTmpl<SocketChannel> UdpServer;