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.
 
 
 
 

476 lines
14 KiB

  1. from libc.stdint cimport uint16_t, uint32_t, uint64_t, int64_t
  2. from posix.types cimport gid_t, uid_t
  3. from . cimport system
  4. cdef extern from "uv.h" nogil:
  5. cdef int UV_TCP_IPV6ONLY
  6. cdef int UV_EACCES
  7. cdef int UV_EAGAIN
  8. cdef int UV_EALREADY
  9. cdef int UV_EBUSY
  10. cdef int UV_ECONNABORTED
  11. cdef int UV_ECONNREFUSED
  12. cdef int UV_ECONNRESET
  13. cdef int UV_ECANCELED
  14. cdef int UV_EEXIST
  15. cdef int UV_EINTR
  16. cdef int UV_EINVAL
  17. cdef int UV_EISDIR
  18. cdef int UV_ENOENT
  19. cdef int UV_EOF
  20. cdef int UV_EPERM
  21. cdef int UV_EPIPE
  22. cdef int UV_ESHUTDOWN
  23. cdef int UV_ESRCH
  24. cdef int UV_ETIMEDOUT
  25. cdef int UV_EBADF
  26. cdef int UV_ENOBUFS
  27. cdef int UV_EAI_ADDRFAMILY
  28. cdef int UV_EAI_AGAIN
  29. cdef int UV_EAI_BADFLAGS
  30. cdef int UV_EAI_BADHINTS
  31. cdef int UV_EAI_CANCELED
  32. cdef int UV_EAI_FAIL
  33. cdef int UV_EAI_FAMILY
  34. cdef int UV_EAI_MEMORY
  35. cdef int UV_EAI_NODATA
  36. cdef int UV_EAI_NONAME
  37. cdef int UV_EAI_OVERFLOW
  38. cdef int UV_EAI_PROTOCOL
  39. cdef int UV_EAI_SERVICE
  40. cdef int UV_EAI_SOCKTYPE
  41. cdef int SOL_SOCKET
  42. cdef int SO_ERROR
  43. cdef int SO_REUSEADDR
  44. cdef int SO_REUSEPORT
  45. cdef int AF_INET
  46. cdef int AF_INET6
  47. cdef int AF_UNIX
  48. cdef int AF_UNSPEC
  49. cdef int AI_PASSIVE
  50. cdef int AI_NUMERICHOST
  51. cdef int INET6_ADDRSTRLEN
  52. cdef int IPPROTO_IPV6
  53. cdef int SOCK_STREAM
  54. cdef int SOCK_DGRAM
  55. cdef int IPPROTO_TCP
  56. cdef int IPPROTO_UDP
  57. cdef int SIGINT
  58. cdef int SIGHUP
  59. cdef int SIGCHLD
  60. cdef int SIGKILL
  61. cdef int SIGTERM
  62. ctypedef int uv_os_sock_t
  63. ctypedef int uv_file
  64. ctypedef int uv_os_fd_t
  65. ctypedef struct uv_buf_t:
  66. char* base
  67. size_t len
  68. ctypedef struct uv_loop_t:
  69. void* data
  70. # ...
  71. ctypedef struct uv_handle_t:
  72. void* data
  73. uv_loop_t* loop
  74. # ...
  75. ctypedef struct uv_idle_t:
  76. void* data
  77. uv_loop_t* loop
  78. # ...
  79. ctypedef struct uv_check_t:
  80. void* data
  81. uv_loop_t* loop
  82. # ...
  83. ctypedef struct uv_signal_t:
  84. void* data
  85. uv_loop_t* loop
  86. # ...
  87. ctypedef struct uv_async_t:
  88. void* data
  89. uv_loop_t* loop
  90. # ...
  91. ctypedef struct uv_timer_t:
  92. void* data
  93. uv_loop_t* loop
  94. # ...
  95. ctypedef struct uv_stream_t:
  96. void* data
  97. size_t write_queue_size
  98. uv_loop_t* loop
  99. # ...
  100. ctypedef struct uv_tcp_t:
  101. void* data
  102. uv_loop_t* loop
  103. # ...
  104. ctypedef struct uv_pipe_t:
  105. void* data
  106. uv_loop_t* loop
  107. # ...
  108. ctypedef struct uv_udp_t:
  109. void* data
  110. uv_loop_t* loop
  111. size_t send_queue_size
  112. size_t send_queue_count
  113. # ...
  114. ctypedef struct uv_udp_send_t:
  115. void* data
  116. uv_udp_t* handle
  117. ctypedef struct uv_poll_t:
  118. void* data
  119. uv_loop_t* loop
  120. # ...
  121. ctypedef struct uv_req_t:
  122. # Only cancellation of uv_fs_t, uv_getaddrinfo_t,
  123. # uv_getnameinfo_t and uv_work_t requests is
  124. # currently supported.
  125. void* data
  126. uv_req_type type
  127. # ...
  128. ctypedef struct uv_connect_t:
  129. void* data
  130. ctypedef struct uv_getaddrinfo_t:
  131. void* data
  132. # ...
  133. ctypedef struct uv_getnameinfo_t:
  134. void* data
  135. # ...
  136. ctypedef struct uv_write_t:
  137. void* data
  138. # ...
  139. ctypedef struct uv_shutdown_t:
  140. void* data
  141. # ...
  142. ctypedef struct uv_process_t:
  143. void* data
  144. int pid
  145. # ...
  146. ctypedef enum uv_req_type:
  147. UV_UNKNOWN_REQ = 0,
  148. UV_REQ,
  149. UV_CONNECT,
  150. UV_WRITE,
  151. UV_SHUTDOWN,
  152. UV_UDP_SEND,
  153. UV_FS,
  154. UV_WORK,
  155. UV_GETADDRINFO,
  156. UV_GETNAMEINFO,
  157. UV_REQ_TYPE_PRIVATE,
  158. UV_REQ_TYPE_MAX
  159. ctypedef enum uv_run_mode:
  160. UV_RUN_DEFAULT = 0,
  161. UV_RUN_ONCE,
  162. UV_RUN_NOWAIT
  163. ctypedef enum uv_poll_event:
  164. UV_READABLE = 1,
  165. UV_WRITABLE = 2,
  166. UV_DISCONNECT = 4
  167. ctypedef enum uv_udp_flags:
  168. UV_UDP_IPV6ONLY = 1,
  169. UV_UDP_PARTIAL = 2,
  170. UV_UDP_REUSEADDR = 4
  171. ctypedef enum uv_membership:
  172. UV_LEAVE_GROUP = 0,
  173. UV_JOIN_GROUP
  174. const char* uv_strerror(int err)
  175. const char* uv_err_name(int err)
  176. ctypedef void (*uv_walk_cb)(uv_handle_t* handle, void* arg) with gil
  177. ctypedef void (*uv_close_cb)(uv_handle_t* handle) with gil
  178. ctypedef void (*uv_idle_cb)(uv_idle_t* handle) with gil
  179. ctypedef void (*uv_check_cb)(uv_check_t* handle) with gil
  180. ctypedef void (*uv_signal_cb)(uv_signal_t* handle, int signum) with gil
  181. ctypedef void (*uv_async_cb)(uv_async_t* handle) with gil
  182. ctypedef void (*uv_timer_cb)(uv_timer_t* handle) with gil
  183. ctypedef void (*uv_connection_cb)(uv_stream_t* server, int status) with gil
  184. ctypedef void (*uv_alloc_cb)(uv_handle_t* handle,
  185. size_t suggested_size,
  186. uv_buf_t* buf) with gil
  187. ctypedef void (*uv_read_cb)(uv_stream_t* stream,
  188. ssize_t nread,
  189. const uv_buf_t* buf) with gil
  190. ctypedef void (*uv_write_cb)(uv_write_t* req, int status) with gil
  191. ctypedef void (*uv_getaddrinfo_cb)(uv_getaddrinfo_t* req,
  192. int status,
  193. system.addrinfo* res) with gil
  194. ctypedef void (*uv_getnameinfo_cb)(uv_getnameinfo_t* req,
  195. int status,
  196. const char* hostname,
  197. const char* service) with gil
  198. ctypedef void (*uv_shutdown_cb)(uv_shutdown_t* req, int status) with gil
  199. ctypedef void (*uv_poll_cb)(uv_poll_t* handle,
  200. int status, int events) with gil
  201. ctypedef void (*uv_connect_cb)(uv_connect_t* req, int status) with gil
  202. ctypedef void (*uv_udp_send_cb)(uv_udp_send_t* req, int status) with gil
  203. ctypedef void (*uv_udp_recv_cb)(uv_udp_t* handle,
  204. ssize_t nread,
  205. const uv_buf_t* buf,
  206. const system.sockaddr* addr,
  207. unsigned flags) with gil
  208. # Generic request functions
  209. int uv_cancel(uv_req_t* req)
  210. # Generic handler functions
  211. int uv_is_active(const uv_handle_t* handle)
  212. void uv_close(uv_handle_t* handle, uv_close_cb close_cb)
  213. int uv_is_closing(const uv_handle_t* handle)
  214. int uv_fileno(const uv_handle_t* handle, uv_os_fd_t* fd)
  215. void uv_walk(uv_loop_t* loop, uv_walk_cb walk_cb, void* arg)
  216. # Loop functions
  217. int uv_loop_init(uv_loop_t* loop)
  218. int uv_loop_close(uv_loop_t* loop)
  219. int uv_loop_alive(uv_loop_t* loop)
  220. int uv_loop_fork(uv_loop_t* loop)
  221. int uv_backend_fd(uv_loop_t* loop)
  222. void uv_update_time(uv_loop_t* loop)
  223. uint64_t uv_now(const uv_loop_t*)
  224. int uv_run(uv_loop_t*, uv_run_mode mode) nogil
  225. void uv_stop(uv_loop_t*)
  226. # Idle handler
  227. int uv_idle_init(uv_loop_t*, uv_idle_t* idle)
  228. int uv_idle_start(uv_idle_t* idle, uv_idle_cb cb)
  229. int uv_idle_stop(uv_idle_t* idle)
  230. # Check handler
  231. int uv_check_init(uv_loop_t*, uv_check_t* idle)
  232. int uv_check_start(uv_check_t* check, uv_check_cb cb)
  233. int uv_check_stop(uv_check_t* check)
  234. # Signal handler
  235. int uv_signal_init(uv_loop_t* loop, uv_signal_t* handle)
  236. int uv_signal_start(uv_signal_t* handle,
  237. uv_signal_cb signal_cb,
  238. int signum)
  239. int uv_signal_stop(uv_signal_t* handle)
  240. # Async handler
  241. int uv_async_init(uv_loop_t*,
  242. uv_async_t* async_,
  243. uv_async_cb async_cb)
  244. int uv_async_send(uv_async_t* async_)
  245. # Timer handler
  246. int uv_timer_init(uv_loop_t*, uv_timer_t* handle)
  247. int uv_timer_start(uv_timer_t* handle,
  248. uv_timer_cb cb,
  249. uint64_t timeout,
  250. uint64_t repeat)
  251. int uv_timer_stop(uv_timer_t* handle)
  252. # DNS
  253. int uv_getaddrinfo(uv_loop_t* loop,
  254. uv_getaddrinfo_t* req,
  255. uv_getaddrinfo_cb getaddrinfo_cb,
  256. const char* node,
  257. const char* service,
  258. const system.addrinfo* hints)
  259. void uv_freeaddrinfo(system.addrinfo* ai)
  260. int uv_getnameinfo(uv_loop_t* loop,
  261. uv_getnameinfo_t* req,
  262. uv_getnameinfo_cb getnameinfo_cb,
  263. const system.sockaddr* addr,
  264. int flags)
  265. int uv_ip4_name(const system.sockaddr_in* src, char* dst, size_t size)
  266. int uv_ip6_name(const system.sockaddr_in6* src, char* dst, size_t size)
  267. # Streams
  268. int uv_listen(uv_stream_t* stream, int backlog, uv_connection_cb cb)
  269. int uv_accept(uv_stream_t* server, uv_stream_t* client)
  270. int uv_read_start(uv_stream_t* stream,
  271. uv_alloc_cb alloc_cb,
  272. uv_read_cb read_cb)
  273. int uv_read_stop(uv_stream_t*)
  274. int uv_write(uv_write_t* req, uv_stream_t* handle,
  275. uv_buf_t bufs[], unsigned int nbufs, uv_write_cb cb)
  276. int uv_try_write(uv_stream_t* handle, uv_buf_t bufs[], unsigned int nbufs)
  277. int uv_shutdown(uv_shutdown_t* req, uv_stream_t* handle, uv_shutdown_cb cb)
  278. int uv_is_readable(const uv_stream_t* handle)
  279. int uv_is_writable(const uv_stream_t* handle)
  280. # TCP
  281. int uv_tcp_init_ex(uv_loop_t*, uv_tcp_t* handle, unsigned int flags)
  282. int uv_tcp_nodelay(uv_tcp_t* handle, int enable)
  283. int uv_tcp_keepalive(uv_tcp_t* handle, int enable, unsigned int delay)
  284. int uv_tcp_open(uv_tcp_t* handle, uv_os_sock_t sock)
  285. int uv_tcp_bind(uv_tcp_t* handle, system.sockaddr* addr,
  286. unsigned int flags)
  287. int uv_tcp_getsockname(const uv_tcp_t* handle, system.sockaddr* name,
  288. int* namelen)
  289. int uv_tcp_getpeername(const uv_tcp_t* handle, system.sockaddr* name,
  290. int* namelen)
  291. int uv_tcp_connect(uv_connect_t* req, uv_tcp_t* handle,
  292. const system.sockaddr* addr, uv_connect_cb cb)
  293. # Pipes
  294. int uv_pipe_init(uv_loop_t* loop, uv_pipe_t* handle, int ipc)
  295. int uv_pipe_open(uv_pipe_t* handle, uv_file file)
  296. int uv_pipe_bind(uv_pipe_t* handle, const char* name)
  297. void uv_pipe_connect(uv_connect_t* req, uv_pipe_t* handle,
  298. const char* name, uv_connect_cb cb)
  299. # UDP
  300. int uv_udp_init_ex(uv_loop_t* loop, uv_udp_t* handle, unsigned int flags)
  301. int uv_udp_connect(uv_udp_t* handle, const system.sockaddr* addr)
  302. int uv_udp_open(uv_udp_t* handle, uv_os_sock_t sock)
  303. int uv_udp_bind(uv_udp_t* handle, const system.sockaddr* addr,
  304. unsigned int flags)
  305. int uv_udp_send(uv_udp_send_t* req, uv_udp_t* handle,
  306. const uv_buf_t bufs[], unsigned int nbufs,
  307. const system.sockaddr* addr, uv_udp_send_cb send_cb)
  308. int uv_udp_try_send(uv_udp_t* handle,
  309. const uv_buf_t bufs[], unsigned int nbufs,
  310. const system.sockaddr* addr)
  311. int uv_udp_recv_start(uv_udp_t* handle, uv_alloc_cb alloc_cb,
  312. uv_udp_recv_cb recv_cb)
  313. int uv_udp_recv_stop(uv_udp_t* handle)
  314. int uv_udp_set_broadcast(uv_udp_t* handle, int on)
  315. # Polling
  316. int uv_poll_init(uv_loop_t* loop, uv_poll_t* handle, int fd)
  317. int uv_poll_init_socket(uv_loop_t* loop, uv_poll_t* handle,
  318. uv_os_sock_t socket)
  319. int uv_poll_start(uv_poll_t* handle, int events, uv_poll_cb cb)
  320. int uv_poll_stop(uv_poll_t* poll)
  321. # Misc
  322. ctypedef struct uv_timeval_t:
  323. long tv_sec
  324. long tv_usec
  325. ctypedef struct uv_rusage_t:
  326. uv_timeval_t ru_utime # user CPU time used
  327. uv_timeval_t ru_stime # system CPU time used
  328. uint64_t ru_maxrss # maximum resident set size
  329. uint64_t ru_ixrss # integral shared memory size
  330. uint64_t ru_idrss # integral unshared data size
  331. uint64_t ru_isrss # integral unshared stack size
  332. uint64_t ru_minflt # page reclaims (soft page faults)
  333. uint64_t ru_majflt # page faults (hard page faults)
  334. uint64_t ru_nswap # swaps
  335. uint64_t ru_inblock # block input operations
  336. uint64_t ru_oublock # block output operations
  337. uint64_t ru_msgsnd # IPC messages sent
  338. uint64_t ru_msgrcv # IPC messages received
  339. uint64_t ru_nsignals # signals received
  340. uint64_t ru_nvcsw # voluntary context switches
  341. uint64_t ru_nivcsw # involuntary context switches
  342. int uv_getrusage(uv_rusage_t* rusage)
  343. int uv_ip4_addr(const char* ip, int port, system.sockaddr_in* addr)
  344. int uv_ip6_addr(const char* ip, int port, system.sockaddr_in6* addr)
  345. # Memory Allocation
  346. ctypedef void* (*uv_malloc_func)(size_t size)
  347. ctypedef void* (*uv_realloc_func)(void* ptr, size_t size)
  348. ctypedef void* (*uv_calloc_func)(size_t count, size_t size)
  349. ctypedef void (*uv_free_func)(void* ptr)
  350. int uv_replace_allocator(uv_malloc_func malloc_func,
  351. uv_realloc_func realloc_func,
  352. uv_calloc_func calloc_func,
  353. uv_free_func free_func)
  354. # Process
  355. ctypedef void (*uv_exit_cb)(uv_process_t*, int64_t exit_status,
  356. int term_signal) with gil
  357. ctypedef enum uv_process_flags:
  358. UV_PROCESS_SETUID = 1,
  359. UV_PROCESS_SETGID = 2,
  360. UV_PROCESS_WINDOWS_VERBATIM_ARGUMENTS = 4,
  361. UV_PROCESS_DETACHED = 8,
  362. UV_PROCESS_WINDOWS_HIDE = 16
  363. ctypedef enum uv_stdio_flags:
  364. UV_IGNORE = 0x00,
  365. UV_CREATE_PIPE = 0x01,
  366. UV_INHERIT_FD = 0x02,
  367. UV_INHERIT_STREAM = 0x04,
  368. UV_READABLE_PIPE = 0x10,
  369. UV_WRITABLE_PIPE = 0x20
  370. ctypedef union uv_stdio_container_data_u:
  371. uv_stream_t* stream
  372. int fd
  373. ctypedef struct uv_stdio_container_t:
  374. uv_stdio_flags flags
  375. uv_stdio_container_data_u data
  376. ctypedef struct uv_process_options_t:
  377. uv_exit_cb exit_cb
  378. char* file
  379. char** args
  380. char** env
  381. char* cwd
  382. unsigned int flags
  383. int stdio_count
  384. uv_stdio_container_t* stdio
  385. uid_t uid
  386. gid_t gid
  387. int uv_spawn(uv_loop_t* loop, uv_process_t* handle,
  388. const uv_process_options_t* options)
  389. int uv_process_kill(uv_process_t* handle, int signum)