Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 
 

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