Browse Source

reusable start

ithewei 3 years ago
parent
commit
f2256e134c
2 changed files with 10 additions and 2 deletions
  1. 5 1
      evpp/TcpClient.h
  2. 5 1
      evpp/UdpClient.h

+ 5 - 1
evpp/TcpClient.h

@@ -234,7 +234,11 @@ public:
 
     // start thread-safe
     void start(bool wait_threads_started = true) {
-        EventLoopThread::start(wait_threads_started, std::bind(&TcpClientTmpl::startConnect, this));
+        if (isRunning()) {
+            TcpClientEventLoopTmpl<TSocketChannel>::start();
+        } else {
+            EventLoopThread::start(wait_threads_started, std::bind(&TcpClientTmpl::startConnect, this));
+        }
     }
 
     // stop thread-safe

+ 5 - 1
evpp/UdpClient.h

@@ -125,7 +125,11 @@ public:
 
     // start thread-safe
     void start(bool wait_threads_started = true) {
-        EventLoopThread::start(wait_threads_started, std::bind(&UdpClientTmpl::startRecv, this));
+        if (isRunning()) {
+            UdpClientEventLoopTmpl<TSocketChannel>::start();
+        } else {
+            EventLoopThread::start(wait_threads_started, std::bind(&UdpClientTmpl::startRecv, this));
+        }
     }
 
     // stop thread-safe