Selaa lähdekoodia

cmUVHandlePtr: Add uv_timer_ptr::stop method

This was missing w.r.t. the pattern established for other handle wrappers.
Brad King 1 vuosi sitten
vanhempi
sitoutus
9dd14b2946
3 muutettua tiedostoa jossa 18 lisäystä ja 0 poistoa
  1. 6 0
      Source/cmUVHandlePtr.cxx
  2. 2 0
      Source/cmUVHandlePtr.h
  3. 10 0
      Tests/CMakeLib/testUVHandlePtr.cxx

+ 6 - 0
Source/cmUVHandlePtr.cxx

@@ -241,6 +241,12 @@ int uv_timer_ptr::start(uv_timer_cb cb, uint64_t timeout, uint64_t repeat)
   return uv_timer_start(*this, cb, timeout, repeat);
 }
 
+void uv_timer_ptr::stop()
+{
+  assert(this->handle);
+  uv_timer_stop(*this);
+}
+
 #ifndef CMAKE_BOOTSTRAP
 uv_tty_ptr::operator uv_stream_t*() const
 {

+ 2 - 0
Source/cmUVHandlePtr.h

@@ -238,6 +238,8 @@ struct uv_timer_ptr : public uv_handle_ptr_<uv_timer_t>
   int init(uv_loop_t& loop, void* data = nullptr);
 
   int start(uv_timer_cb cb, uint64_t timeout, uint64_t repeat);
+
+  void stop();
 };
 
 struct uv_tty_ptr : public uv_handle_ptr_<uv_tty_t>

+ 10 - 0
Tests/CMakeLib/testUVHandlePtr.cxx

@@ -53,6 +53,16 @@ static bool testTimer()
     return false;
   }
 
+  timed = false;
+  timer.start(cb, 10, 0);
+  timer.stop();
+  uv_run(loop, UV_RUN_DEFAULT);
+
+  if (timed) {
+    std::cerr << "uv_timer_ptr::stop did not stop callback" << std::endl;
+    return false;
+  }
+
   return true;
 }