You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

73 lines
1.8 KiB

  1. @cython.no_gc_clear
  2. cdef class UVCheck(UVHandle):
  3. cdef _init(self, Loop loop, Handle h):
  4. cdef int err
  5. self._start_init(loop)
  6. self._handle = <uv.uv_handle_t*>PyMem_RawMalloc(sizeof(uv.uv_check_t))
  7. if self._handle is NULL:
  8. self._abort_init()
  9. raise MemoryError()
  10. err = uv.uv_check_init(self._loop.uvloop, <uv.uv_check_t*>self._handle)
  11. if err < 0:
  12. self._abort_init()
  13. raise convert_error(err)
  14. self._finish_init()
  15. self.h = h
  16. self.running = 0
  17. cdef inline stop(self):
  18. cdef int err
  19. if not self._is_alive():
  20. self.running = 0
  21. return
  22. if self.running == 1:
  23. err = uv.uv_check_stop(<uv.uv_check_t*>self._handle)
  24. self.running = 0
  25. if err < 0:
  26. exc = convert_error(err)
  27. self._fatal_error(exc, True)
  28. return
  29. cdef inline start(self):
  30. cdef int err
  31. self._ensure_alive()
  32. if self.running == 0:
  33. err = uv.uv_check_start(<uv.uv_check_t*>self._handle,
  34. cb_check_callback)
  35. if err < 0:
  36. exc = convert_error(err)
  37. self._fatal_error(exc, True)
  38. return
  39. self.running = 1
  40. @staticmethod
  41. cdef UVCheck new(Loop loop, Handle h):
  42. cdef UVCheck handle
  43. handle = UVCheck.__new__(UVCheck)
  44. handle._init(loop, h)
  45. return handle
  46. cdef void cb_check_callback(
  47. uv.uv_check_t* handle,
  48. ) noexcept with gil:
  49. if __ensure_handle_data(<uv.uv_handle_t*>handle, "UVCheck callback") == 0:
  50. return
  51. cdef:
  52. UVCheck check = <UVCheck> handle.data
  53. Handle h = check.h
  54. try:
  55. h._run()
  56. except BaseException as ex:
  57. check._error(ex, False)