1 // Copyright 2012 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
12 * Low-level bindings to the libuv library.
14 * This module contains a set of direct, 'bare-metal' wrappers around
17 * We're not bothering yet to redefine uv's structs as Rust structs
18 * because they are quite large and change often between versions.
19 * The maintenance burden is just too high. Instead we use the uv's
20 * `uv_handle_size` and `uv_req_size` to find the correct size of the
21 * structs and allocate them on the heap. This can be revisited later.
23 * There are also a collection of helper functions to ease interacting
24 * with the low-level API.
26 * As new functionality, existent in uv.h, is added to the rust stdlib,
27 * the mappings should be added in this module.
30 #[allow(non_camel_case_types)]; // C types
32 use std::libc::{size_t, c_int, c_uint, c_void, c_char, uintptr_t};
33 use std::libc::ssize_t;
34 use std::libc::{malloc, free};
38 pub use self::errors::*;
40 pub static OK: c_int = 0;
41 pub static EOF: c_int = -4095;
42 pub static UNKNOWN: c_int = -4094;
44 // uv-errno.h redefines error codes for windows, but not for unix...
50 pub static EACCES: c_int = -4093;
51 pub static ECONNREFUSED: c_int = -4079;
52 pub static ECONNRESET: c_int = -4078;
53 pub static ENOTCONN: c_int = -4054;
54 pub static EPIPE: c_int = -4048;
55 pub static ECONNABORTED: c_int = -4080;
62 pub static EACCES: c_int = -libc::EACCES;
63 pub static ECONNREFUSED: c_int = -libc::ECONNREFUSED;
64 pub static ECONNRESET: c_int = -libc::ECONNRESET;
65 pub static ENOTCONN: c_int = -libc::ENOTCONN;
66 pub static EPIPE: c_int = -libc::EPIPE;
67 pub static ECONNABORTED: c_int = -libc::ECONNABORTED;
70 pub static PROCESS_SETUID: c_int = 1 << 0;
71 pub static PROCESS_SETGID: c_int = 1 << 1;
72 pub static PROCESS_WINDOWS_VERBATIM_ARGUMENTS: c_int = 1 << 2;
73 pub static PROCESS_DETACHED: c_int = 1 << 3;
74 pub static PROCESS_WINDOWS_HIDE: c_int = 1 << 4;
76 pub static STDIO_IGNORE: c_int = 0x00;
77 pub static STDIO_CREATE_PIPE: c_int = 0x01;
78 pub static STDIO_INHERIT_FD: c_int = 0x02;
79 pub static STDIO_INHERIT_STREAM: c_int = 0x04;
80 pub static STDIO_READABLE_PIPE: c_int = 0x10;
81 pub static STDIO_WRITABLE_PIPE: c_int = 0x20;
84 pub type uv_buf_len_t = libc::size_t;
86 pub type uv_buf_len_t = u32;
88 // see libuv/include/uv-unix.h
95 // see libuv/include/uv-win.h
103 pub enum uv_run_mode {
109 pub struct uv_process_options_t {
112 args: **libc::c_char,
116 stdio_count: libc::c_int,
117 stdio: *uv_stdio_container_t,
122 // These fields are private because they must be interfaced with through the
124 pub struct uv_stdio_container_t {
125 priv flags: libc::c_int,
126 priv stream: *uv_stream_t,
129 pub type uv_handle_t = c_void;
130 pub type uv_loop_t = c_void;
131 pub type uv_idle_t = c_void;
132 pub type uv_tcp_t = c_void;
133 pub type uv_udp_t = c_void;
134 pub type uv_connect_t = c_void;
135 pub type uv_connection_t = c_void;
136 pub type uv_write_t = c_void;
137 pub type uv_async_t = c_void;
138 pub type uv_timer_t = c_void;
139 pub type uv_stream_t = c_void;
140 pub type uv_fs_t = c_void;
141 pub type uv_udp_send_t = c_void;
142 pub type uv_getaddrinfo_t = c_void;
143 pub type uv_process_t = c_void;
144 pub type uv_pipe_t = c_void;
145 pub type uv_tty_t = c_void;
146 pub type uv_signal_t = c_void;
148 pub struct uv_timespec_t {
149 tv_sec: libc::c_long,
150 tv_nsec: libc::c_long
153 pub struct uv_stat_t {
154 st_dev: libc::uint64_t,
155 st_mode: libc::uint64_t,
156 st_nlink: libc::uint64_t,
157 st_uid: libc::uint64_t,
158 st_gid: libc::uint64_t,
159 st_rdev: libc::uint64_t,
160 st_ino: libc::uint64_t,
161 st_size: libc::uint64_t,
162 st_blksize: libc::uint64_t,
163 st_blocks: libc::uint64_t,
164 st_flags: libc::uint64_t,
165 st_gen: libc::uint64_t,
166 st_atim: uv_timespec_t,
167 st_mtim: uv_timespec_t,
168 st_ctim: uv_timespec_t,
169 st_birthtim: uv_timespec_t
173 pub fn new() -> uv_stat_t {
187 st_atim: uv_timespec_t { tv_sec: 0, tv_nsec: 0 },
188 st_mtim: uv_timespec_t { tv_sec: 0, tv_nsec: 0 },
189 st_ctim: uv_timespec_t { tv_sec: 0, tv_nsec: 0 },
190 st_birthtim: uv_timespec_t { tv_sec: 0, tv_nsec: 0 }
193 pub fn is_file(&self) -> bool {
194 ((self.st_mode) & libc::S_IFMT as libc::uint64_t) == libc::S_IFREG as libc::uint64_t
196 pub fn is_dir(&self) -> bool {
197 ((self.st_mode) & libc::S_IFMT as libc::uint64_t) == libc::S_IFDIR as libc::uint64_t
201 pub type uv_idle_cb = extern "C" fn(handle: *uv_idle_t,
203 pub type uv_alloc_cb = extern "C" fn(stream: *uv_stream_t,
204 suggested_size: size_t) -> uv_buf_t;
205 pub type uv_read_cb = extern "C" fn(stream: *uv_stream_t,
208 pub type uv_udp_send_cb = extern "C" fn(req: *uv_udp_send_t,
210 pub type uv_udp_recv_cb = extern "C" fn(handle: *uv_udp_t,
215 pub type uv_close_cb = extern "C" fn(handle: *uv_handle_t);
216 pub type uv_walk_cb = extern "C" fn(handle: *uv_handle_t,
218 pub type uv_async_cb = extern "C" fn(handle: *uv_async_t,
220 pub type uv_connect_cb = extern "C" fn(handle: *uv_connect_t,
222 pub type uv_connection_cb = extern "C" fn(handle: *uv_connection_t,
224 pub type uv_timer_cb = extern "C" fn(handle: *uv_timer_t,
226 pub type uv_write_cb = extern "C" fn(handle: *uv_write_t,
228 pub type uv_getaddrinfo_cb = extern "C" fn(req: *uv_getaddrinfo_t,
231 pub type uv_exit_cb = extern "C" fn(handle: *uv_process_t,
234 pub type uv_signal_cb = extern "C" fn(handle: *uv_signal_t,
236 pub type uv_fs_cb = extern "C" fn(req: *uv_fs_t);
238 pub type sockaddr = c_void;
239 pub type sockaddr_in = c_void;
240 pub type sockaddr_in6 = c_void;
241 pub type sockaddr_storage = c_void;
244 pub type socklen_t = c_int;
246 // XXX: This is a standard C type. Could probably be defined in libc
247 #[cfg(target_os = "android")]
248 #[cfg(target_os = "linux")]
249 pub struct addrinfo {
254 ai_addrlen: socklen_t,
260 #[cfg(target_os = "macos")]
261 #[cfg(target_os = "freebsd")]
262 pub struct addrinfo {
267 ai_addrlen: socklen_t,
274 pub struct addrinfo {
285 #[cfg(unix)] pub type uv_uid_t = libc::types::os::arch::posix88::uid_t;
286 #[cfg(unix)] pub type uv_gid_t = libc::types::os::arch::posix88::gid_t;
287 #[cfg(windows)] pub type uv_uid_t = libc::c_uchar;
288 #[cfg(windows)] pub type uv_gid_t = libc::c_uchar;
292 pub enum uv_handle_type {
317 pub enum uv_req_type {
330 // uv_req_type may have additional fields defined by UV_REQ_TYPE_PRIVATE.
331 // See UV_REQ_TYPE_PRIVATE at libuv/include/uv-win.h
335 pub enum uv_req_type {
358 pub enum uv_membership {
363 pub unsafe fn malloc_handle(handle: uv_handle_type) -> *c_void {
364 #[fixed_stack_segment]; #[inline(never)];
366 assert!(handle != UV_UNKNOWN_HANDLE && handle != UV_HANDLE_TYPE_MAX);
367 let size = uv_handle_size(handle);
368 let p = malloc(size);
369 assert!(p.is_not_null());
373 pub unsafe fn free_handle(v: *c_void) {
374 #[fixed_stack_segment]; #[inline(never)];
379 pub unsafe fn malloc_req(req: uv_req_type) -> *c_void {
380 #[fixed_stack_segment]; #[inline(never)];
382 assert!(req != UV_UNKNOWN_REQ && req != UV_REQ_TYPE_MAX);
383 let size = uv_req_size(req);
384 let p = malloc(size);
385 assert!(p.is_not_null());
389 pub unsafe fn free_req(v: *c_void) {
390 #[fixed_stack_segment]; #[inline(never)];
396 fn handle_sanity_check() {
397 #[fixed_stack_segment]; #[inline(never)];
399 assert_eq!(UV_HANDLE_TYPE_MAX as uint, rust_uv_handle_type_max());
404 fn request_sanity_check() {
405 #[fixed_stack_segment]; #[inline(never)];
407 assert_eq!(UV_REQ_TYPE_MAX as uint, rust_uv_req_type_max());
411 // XXX Event loops ignore SIGPIPE by default.
412 pub unsafe fn loop_new() -> *c_void {
413 #[fixed_stack_segment]; #[inline(never)];
415 return rust_uv_loop_new();
418 pub unsafe fn udp_bind(server: *uv_udp_t, addr: *sockaddr_in, flags: c_uint) -> c_int {
419 #[fixed_stack_segment]; #[inline(never)];
421 return rust_uv_udp_bind(server, addr, flags);
424 pub unsafe fn udp_bind6(server: *uv_udp_t, addr: *sockaddr_in6, flags: c_uint) -> c_int {
425 #[fixed_stack_segment]; #[inline(never)];
427 return rust_uv_udp_bind6(server, addr, flags);
430 pub unsafe fn udp_send<T>(req: *uv_udp_send_t, handle: *T, buf_in: &[uv_buf_t],
431 addr: *sockaddr_in, cb: uv_udp_send_cb) -> c_int {
432 #[fixed_stack_segment]; #[inline(never)];
434 let buf_ptr = vec::raw::to_ptr(buf_in);
435 let buf_cnt = buf_in.len() as i32;
436 return rust_uv_udp_send(req, handle as *c_void, buf_ptr, buf_cnt, addr, cb);
439 pub unsafe fn udp_send6<T>(req: *uv_udp_send_t, handle: *T, buf_in: &[uv_buf_t],
440 addr: *sockaddr_in6, cb: uv_udp_send_cb) -> c_int {
441 #[fixed_stack_segment]; #[inline(never)];
443 let buf_ptr = vec::raw::to_ptr(buf_in);
444 let buf_cnt = buf_in.len() as i32;
445 return rust_uv_udp_send6(req, handle as *c_void, buf_ptr, buf_cnt, addr, cb);
448 pub unsafe fn get_udp_handle_from_send_req(send_req: *uv_udp_send_t) -> *uv_udp_t {
449 #[fixed_stack_segment]; #[inline(never)];
451 return rust_uv_get_udp_handle_from_send_req(send_req);
454 pub unsafe fn udp_getsockname(handle: *uv_udp_t, name: *sockaddr_storage) -> c_int {
455 #[fixed_stack_segment]; #[inline(never)];
457 return rust_uv_udp_getsockname(handle, name);
460 pub unsafe fn tcp_connect(connect_ptr: *uv_connect_t, tcp_handle_ptr: *uv_tcp_t,
461 addr_ptr: *sockaddr_in, after_connect_cb: uv_connect_cb) -> c_int {
462 #[fixed_stack_segment]; #[inline(never)];
464 return rust_uv_tcp_connect(connect_ptr, tcp_handle_ptr, after_connect_cb, addr_ptr);
467 pub unsafe fn tcp_connect6(connect_ptr: *uv_connect_t, tcp_handle_ptr: *uv_tcp_t,
468 addr_ptr: *sockaddr_in6, after_connect_cb: uv_connect_cb) -> c_int {
469 #[fixed_stack_segment]; #[inline(never)];
471 return rust_uv_tcp_connect6(connect_ptr, tcp_handle_ptr, after_connect_cb, addr_ptr);
474 pub unsafe fn tcp_bind(tcp_server_ptr: *uv_tcp_t, addr_ptr: *sockaddr_in) -> c_int {
475 #[fixed_stack_segment]; #[inline(never)];
477 return rust_uv_tcp_bind(tcp_server_ptr, addr_ptr);
480 pub unsafe fn tcp_bind6(tcp_server_ptr: *uv_tcp_t, addr_ptr: *sockaddr_in6) -> c_int {
481 #[fixed_stack_segment]; #[inline(never)];
483 return rust_uv_tcp_bind6(tcp_server_ptr, addr_ptr);
486 pub unsafe fn tcp_getpeername(tcp_handle_ptr: *uv_tcp_t, name: *sockaddr_storage) -> c_int {
487 #[fixed_stack_segment]; #[inline(never)];
489 return rust_uv_tcp_getpeername(tcp_handle_ptr, name);
492 pub unsafe fn tcp_getsockname(handle: *uv_tcp_t, name: *sockaddr_storage) -> c_int {
493 #[fixed_stack_segment]; #[inline(never)];
495 return rust_uv_tcp_getsockname(handle, name);
498 pub unsafe fn uv_write(req: *uv_write_t,
499 stream: *uv_stream_t,
501 cb: uv_write_cb) -> c_int {
502 externfn!(fn uv_write(req: *uv_write_t, stream: *uv_stream_t,
503 buf_in: *uv_buf_t, buf_cnt: c_int,
504 cb: uv_write_cb) -> c_int)
506 let buf_ptr = vec::raw::to_ptr(buf_in);
507 let buf_cnt = buf_in.len() as i32;
508 return uv_write(req, stream, buf_ptr, buf_cnt, cb);
511 pub unsafe fn is_ip4_addr(addr: *sockaddr) -> bool {
512 #[fixed_stack_segment]; #[inline(never)];
514 match rust_uv_is_ipv4_sockaddr(addr) { 0 => false, _ => true }
517 pub unsafe fn is_ip6_addr(addr: *sockaddr) -> bool {
518 #[fixed_stack_segment]; #[inline(never)];
520 match rust_uv_is_ipv6_sockaddr(addr) { 0 => false, _ => true }
523 pub unsafe fn malloc_ip4_addr(ip: &str, port: int) -> *sockaddr_in {
524 #[fixed_stack_segment]; #[inline(never)];
525 do ip.with_c_str |ip_buf| {
526 rust_uv_ip4_addrp(ip_buf as *u8, port as libc::c_int)
529 pub unsafe fn malloc_ip6_addr(ip: &str, port: int) -> *sockaddr_in6 {
530 #[fixed_stack_segment]; #[inline(never)];
531 do ip.with_c_str |ip_buf| {
532 rust_uv_ip6_addrp(ip_buf as *u8, port as libc::c_int)
536 pub unsafe fn malloc_sockaddr_storage() -> *sockaddr_storage {
537 #[fixed_stack_segment]; #[inline(never)];
539 rust_uv_malloc_sockaddr_storage()
542 pub unsafe fn free_sockaddr_storage(ss: *sockaddr_storage) {
543 #[fixed_stack_segment]; #[inline(never)];
545 rust_uv_free_sockaddr_storage(ss);
548 pub unsafe fn free_ip4_addr(addr: *sockaddr_in) {
549 #[fixed_stack_segment]; #[inline(never)];
551 rust_uv_free_ip4_addr(addr);
554 pub unsafe fn free_ip6_addr(addr: *sockaddr_in6) {
555 #[fixed_stack_segment]; #[inline(never)];
557 rust_uv_free_ip6_addr(addr);
560 pub unsafe fn ip4_port(addr: *sockaddr_in) -> c_uint {
561 #[fixed_stack_segment]; #[inline(never)];
563 return rust_uv_ip4_port(addr);
566 pub unsafe fn ip6_port(addr: *sockaddr_in6) -> c_uint {
567 #[fixed_stack_segment]; #[inline(never)];
569 return rust_uv_ip6_port(addr);
572 pub unsafe fn process_pid(p: *uv_process_t) -> c_int {
573 #[fixed_stack_segment]; #[inline(never)];
574 return rust_uv_process_pid(p);
577 pub unsafe fn set_stdio_container_flags(c: *uv_stdio_container_t,
578 flags: libc::c_int) {
579 #[fixed_stack_segment]; #[inline(never)];
580 rust_set_stdio_container_flags(c, flags);
583 pub unsafe fn set_stdio_container_fd(c: *uv_stdio_container_t,
585 #[fixed_stack_segment]; #[inline(never)];
586 rust_set_stdio_container_fd(c, fd);
589 pub unsafe fn set_stdio_container_stream(c: *uv_stdio_container_t,
590 stream: *uv_stream_t) {
591 #[fixed_stack_segment]; #[inline(never)];
592 rust_set_stdio_container_stream(c, stream);
595 // data access helpers
596 pub unsafe fn get_result_from_fs_req(req: *uv_fs_t) -> c_int {
597 #[fixed_stack_segment]; #[inline(never)];
599 rust_uv_get_result_from_fs_req(req)
601 pub unsafe fn get_ptr_from_fs_req(req: *uv_fs_t) -> *libc::c_void {
602 #[fixed_stack_segment]; #[inline(never)];
604 rust_uv_get_ptr_from_fs_req(req)
606 pub unsafe fn get_path_from_fs_req(req: *uv_fs_t) -> *c_char {
607 #[fixed_stack_segment]; #[inline(never)];
609 rust_uv_get_path_from_fs_req(req)
611 pub unsafe fn get_loop_from_fs_req(req: *uv_fs_t) -> *uv_loop_t {
612 #[fixed_stack_segment]; #[inline(never)];
614 rust_uv_get_loop_from_fs_req(req)
616 pub unsafe fn get_loop_from_getaddrinfo_req(req: *uv_getaddrinfo_t) -> *uv_loop_t {
617 #[fixed_stack_segment]; #[inline(never)];
619 rust_uv_get_loop_from_getaddrinfo_req(req)
621 pub unsafe fn get_loop_for_uv_handle<T>(handle: *T) -> *c_void {
622 #[fixed_stack_segment]; #[inline(never)];
624 return rust_uv_get_loop_for_uv_handle(handle as *c_void);
626 pub unsafe fn get_stream_handle_from_connect_req(connect: *uv_connect_t) -> *uv_stream_t {
627 #[fixed_stack_segment]; #[inline(never)];
629 return rust_uv_get_stream_handle_from_connect_req(connect);
631 pub unsafe fn get_stream_handle_from_write_req(write_req: *uv_write_t) -> *uv_stream_t {
632 #[fixed_stack_segment]; #[inline(never)];
634 return rust_uv_get_stream_handle_from_write_req(write_req);
636 pub unsafe fn get_data_for_uv_loop(loop_ptr: *c_void) -> *c_void {
637 #[fixed_stack_segment]; #[inline(never)];
639 rust_uv_get_data_for_uv_loop(loop_ptr)
641 pub unsafe fn set_data_for_uv_loop(loop_ptr: *c_void, data: *c_void) {
642 #[fixed_stack_segment]; #[inline(never)];
644 rust_uv_set_data_for_uv_loop(loop_ptr, data);
646 pub unsafe fn get_data_for_uv_handle<T>(handle: *T) -> *c_void {
647 #[fixed_stack_segment]; #[inline(never)];
649 return rust_uv_get_data_for_uv_handle(handle as *c_void);
651 pub unsafe fn set_data_for_uv_handle<T, U>(handle: *T, data: *U) {
652 #[fixed_stack_segment]; #[inline(never)];
654 rust_uv_set_data_for_uv_handle(handle as *c_void, data as *c_void);
656 pub unsafe fn get_data_for_req<T>(req: *T) -> *c_void {
657 #[fixed_stack_segment]; #[inline(never)];
659 return rust_uv_get_data_for_req(req as *c_void);
661 pub unsafe fn set_data_for_req<T, U>(req: *T, data: *U) {
662 #[fixed_stack_segment]; #[inline(never)];
664 rust_uv_set_data_for_req(req as *c_void, data as *c_void);
666 pub unsafe fn populate_stat(req_in: *uv_fs_t, stat_out: *uv_stat_t) {
667 #[fixed_stack_segment]; #[inline(never)];
669 rust_uv_populate_uv_stat(req_in, stat_out)
673 // uv_support is the result of compiling rust_uv.cpp
674 #[link_args = "-luv_support -luv"]
676 fn rust_uv_loop_new() -> *c_void;
678 fn rust_uv_handle_type_max() -> uintptr_t;
679 fn rust_uv_req_type_max() -> uintptr_t;
680 fn rust_uv_ip4_addrp(ip: *u8, port: c_int) -> *sockaddr_in;
681 fn rust_uv_ip6_addrp(ip: *u8, port: c_int) -> *sockaddr_in6;
682 fn rust_uv_free_ip4_addr(addr: *sockaddr_in);
683 fn rust_uv_free_ip6_addr(addr: *sockaddr_in6);
684 fn rust_uv_ip4_port(src: *sockaddr_in) -> c_uint;
685 fn rust_uv_ip6_port(src: *sockaddr_in6) -> c_uint;
686 fn rust_uv_tcp_connect(req: *uv_connect_t, handle: *uv_tcp_t,
688 addr: *sockaddr_in) -> c_int;
689 fn rust_uv_tcp_bind(tcp_server: *uv_tcp_t, addr: *sockaddr_in) -> c_int;
690 fn rust_uv_tcp_connect6(req: *uv_connect_t, handle: *uv_tcp_t,
692 addr: *sockaddr_in6) -> c_int;
693 fn rust_uv_tcp_bind6(tcp_server: *uv_tcp_t, addr: *sockaddr_in6) -> c_int;
694 fn rust_uv_tcp_getpeername(tcp_handle_ptr: *uv_tcp_t, name: *sockaddr_storage) -> c_int;
695 fn rust_uv_tcp_getsockname(handle: *uv_tcp_t, name: *sockaddr_storage) -> c_int;
696 fn rust_uv_udp_bind(server: *uv_udp_t, addr: *sockaddr_in, flags: c_uint) -> c_int;
697 fn rust_uv_udp_bind6(server: *uv_udp_t, addr: *sockaddr_in6, flags: c_uint) -> c_int;
698 fn rust_uv_udp_send(req: *uv_udp_send_t, handle: *uv_udp_t, buf_in: *uv_buf_t,
699 buf_cnt: c_int, addr: *sockaddr_in, cb: uv_udp_send_cb) -> c_int;
700 fn rust_uv_udp_send6(req: *uv_udp_send_t, handle: *uv_udp_t, buf_in: *uv_buf_t,
701 buf_cnt: c_int, addr: *sockaddr_in6, cb: uv_udp_send_cb) -> c_int;
702 fn rust_uv_get_udp_handle_from_send_req(req: *uv_udp_send_t) -> *uv_udp_t;
703 fn rust_uv_udp_getsockname(handle: *uv_udp_t, name: *sockaddr_storage) -> c_int;
704 fn rust_uv_is_ipv4_sockaddr(addr: *sockaddr) -> c_int;
705 fn rust_uv_is_ipv6_sockaddr(addr: *sockaddr) -> c_int;
706 fn rust_uv_malloc_sockaddr_storage() -> *sockaddr_storage;
707 fn rust_uv_free_sockaddr_storage(ss: *sockaddr_storage);
708 fn rust_uv_populate_uv_stat(req_in: *uv_fs_t, stat_out: *uv_stat_t);
709 fn rust_uv_get_result_from_fs_req(req: *uv_fs_t) -> c_int;
710 fn rust_uv_get_ptr_from_fs_req(req: *uv_fs_t) -> *libc::c_void;
711 fn rust_uv_get_path_from_fs_req(req: *uv_fs_t) -> *c_char;
712 fn rust_uv_get_loop_from_fs_req(req: *uv_fs_t) -> *uv_loop_t;
713 fn rust_uv_get_loop_from_getaddrinfo_req(req: *uv_fs_t) -> *uv_loop_t;
714 fn rust_uv_get_stream_handle_from_connect_req(req: *uv_connect_t) -> *uv_stream_t;
715 fn rust_uv_get_stream_handle_from_write_req(req: *uv_write_t) -> *uv_stream_t;
716 fn rust_uv_get_loop_for_uv_handle(handle: *c_void) -> *c_void;
717 fn rust_uv_get_data_for_uv_loop(loop_ptr: *c_void) -> *c_void;
718 fn rust_uv_set_data_for_uv_loop(loop_ptr: *c_void, data: *c_void);
719 fn rust_uv_get_data_for_uv_handle(handle: *c_void) -> *c_void;
720 fn rust_uv_set_data_for_uv_handle(handle: *c_void, data: *c_void);
721 fn rust_uv_get_data_for_req(req: *c_void) -> *c_void;
722 fn rust_uv_set_data_for_req(req: *c_void, data: *c_void);
723 fn rust_set_stdio_container_flags(c: *uv_stdio_container_t, flags: c_int);
724 fn rust_set_stdio_container_fd(c: *uv_stdio_container_t, fd: c_int);
725 fn rust_set_stdio_container_stream(c: *uv_stdio_container_t,
726 stream: *uv_stream_t);
729 // generic uv functions
730 externfn!(fn uv_loop_delete(l: *uv_loop_t))
731 externfn!(fn uv_handle_size(ty: uv_handle_type) -> size_t)
732 externfn!(fn uv_req_size(ty: uv_req_type) -> size_t)
733 externfn!(fn uv_run(l: *uv_loop_t, mode: uv_run_mode) -> c_int)
734 externfn!(fn uv_close(h: *uv_handle_t, cb: uv_close_cb))
735 externfn!(fn uv_walk(l: *uv_loop_t, cb: uv_walk_cb, arg: *c_void))
736 externfn!(fn uv_buf_init(base: *c_char, len: c_uint) -> uv_buf_t)
737 externfn!(fn uv_strerror(err: c_int) -> *c_char)
738 externfn!(fn uv_err_name(err: c_int) -> *c_char)
739 externfn!(fn uv_listen(s: *uv_stream_t, backlog: c_int,
740 cb: uv_connection_cb) -> c_int)
741 externfn!(fn uv_accept(server: *uv_stream_t, client: *uv_stream_t) -> c_int)
742 externfn!(fn uv_read_start(stream: *uv_stream_t,
743 on_alloc: uv_alloc_cb,
744 on_read: uv_read_cb) -> c_int)
745 externfn!(fn uv_read_stop(stream: *uv_stream_t) -> c_int)
748 externfn!(fn uv_idle_init(l: *uv_loop_t, i: *uv_idle_t) -> c_int)
749 externfn!(fn uv_idle_start(i: *uv_idle_t, cb: uv_idle_cb) -> c_int)
750 externfn!(fn uv_idle_stop(i: *uv_idle_t) -> c_int)
753 externfn!(fn uv_async_init(l: *uv_loop_t, a: *uv_async_t,
754 cb: uv_async_cb) -> c_int)
755 externfn!(fn uv_async_send(a: *uv_async_t))
758 externfn!(fn uv_tcp_init(l: *uv_loop_t, h: *uv_tcp_t) -> c_int)
759 externfn!(fn uv_ip4_name(src: *sockaddr_in, dst: *c_char,
760 size: size_t) -> c_int)
761 externfn!(fn uv_ip6_name(src: *sockaddr_in6, dst: *c_char,
762 size: size_t) -> c_int)
763 externfn!(fn uv_tcp_nodelay(h: *uv_tcp_t, enable: c_int) -> c_int)
764 externfn!(fn uv_tcp_keepalive(h: *uv_tcp_t, enable: c_int,
765 delay: c_uint) -> c_int)
766 externfn!(fn uv_tcp_simultaneous_accepts(h: *uv_tcp_t, enable: c_int) -> c_int)
769 externfn!(fn uv_udp_init(l: *uv_loop_t, h: *uv_udp_t) -> c_int)
770 externfn!(fn uv_udp_recv_start(server: *uv_udp_t,
771 on_alloc: uv_alloc_cb,
772 on_recv: uv_udp_recv_cb) -> c_int)
773 externfn!(fn uv_udp_set_membership(handle: *uv_udp_t, multicast_addr: *c_char,
774 interface_addr: *c_char,
775 membership: uv_membership) -> c_int)
776 externfn!(fn uv_udp_recv_stop(server: *uv_udp_t) -> c_int)
777 externfn!(fn uv_udp_set_multicast_loop(handle: *uv_udp_t, on: c_int) -> c_int)
778 externfn!(fn uv_udp_set_multicast_ttl(handle: *uv_udp_t, ttl: c_int) -> c_int)
779 externfn!(fn uv_udp_set_ttl(handle: *uv_udp_t, ttl: c_int) -> c_int)
780 externfn!(fn uv_udp_set_broadcast(handle: *uv_udp_t, on: c_int) -> c_int)
783 externfn!(fn uv_timer_init(l: *uv_loop_t, t: *uv_timer_t) -> c_int)
784 externfn!(fn uv_timer_start(t: *uv_timer_t, cb: uv_timer_cb,
785 timeout: libc::uint64_t,
786 repeat: libc::uint64_t) -> c_int)
787 externfn!(fn uv_timer_stop(handle: *uv_timer_t) -> c_int)
790 externfn!(fn uv_fs_open(loop_ptr: *uv_loop_t, req: *uv_fs_t, path: *c_char,
791 flags: c_int, mode: c_int, cb: uv_fs_cb) -> c_int)
792 externfn!(fn uv_fs_unlink(loop_ptr: *uv_loop_t, req: *uv_fs_t, path: *c_char,
793 cb: uv_fs_cb) -> c_int)
794 externfn!(fn uv_fs_write(l: *uv_loop_t, req: *uv_fs_t, fd: c_int, buf: *c_void,
795 len: c_uint, offset: i64, cb: uv_fs_cb) -> c_int)
796 externfn!(fn uv_fs_read(l: *uv_loop_t, req: *uv_fs_t, fd: c_int, buf: *c_void,
797 len: c_uint, offset: i64, cb: uv_fs_cb) -> c_int)
798 externfn!(fn uv_fs_close(l: *uv_loop_t, req: *uv_fs_t, fd: c_int,
799 cb: uv_fs_cb) -> c_int)
800 externfn!(fn uv_fs_stat(l: *uv_loop_t, req: *uv_fs_t, path: *c_char,
801 cb: uv_fs_cb) -> c_int)
802 externfn!(fn uv_fs_fstat(l: *uv_loop_t, req: *uv_fs_t, fd: c_int,
803 cb: uv_fs_cb) -> c_int)
804 externfn!(fn uv_fs_mkdir(l: *uv_loop_t, req: *uv_fs_t, path: *c_char,
805 mode: c_int, cb: uv_fs_cb) -> c_int)
806 externfn!(fn uv_fs_rmdir(l: *uv_loop_t, req: *uv_fs_t, path: *c_char,
807 cb: uv_fs_cb) -> c_int)
808 externfn!(fn uv_fs_readdir(l: *uv_loop_t, req: *uv_fs_t, path: *c_char,
809 flags: c_int, cb: uv_fs_cb) -> c_int)
810 externfn!(fn uv_fs_req_cleanup(req: *uv_fs_t))
811 externfn!(fn uv_fs_fsync(handle: *uv_loop_t, req: *uv_fs_t, file: c_int,
813 externfn!(fn uv_fs_fdatasync(handle: *uv_loop_t, req: *uv_fs_t, file: c_int,
815 externfn!(fn uv_fs_ftruncate(handle: *uv_loop_t, req: *uv_fs_t, file: c_int,
816 offset: i64, cb: *u8) -> c_int)
817 externfn!(fn uv_fs_readlink(handle: *uv_loop_t, req: *uv_fs_t, file: *c_char,
819 externfn!(fn uv_fs_symlink(handle: *uv_loop_t, req: *uv_fs_t, src: *c_char,
820 dst: *c_char, flags: c_int, cb: *u8) -> c_int)
821 externfn!(fn uv_fs_link(handle: *uv_loop_t, req: *uv_fs_t, src: *c_char,
822 dst: *c_char, cb: *u8) -> c_int)
823 externfn!(fn uv_fs_chown(handle: *uv_loop_t, req: *uv_fs_t, src: *c_char,
824 uid: uv_uid_t, gid: uv_gid_t, cb: *u8) -> c_int)
825 externfn!(fn uv_fs_lstat(handle: *uv_loop_t, req: *uv_fs_t, file: *c_char,
829 externfn!(fn uv_getaddrinfo(loop_: *uv_loop_t, req: *uv_getaddrinfo_t,
830 getaddrinfo_cb: uv_getaddrinfo_cb,
831 node: *c_char, service: *c_char,
832 hints: *addrinfo) -> c_int)
833 externfn!(fn uv_freeaddrinfo(ai: *addrinfo))
836 externfn!(fn uv_spawn(loop_ptr: *uv_loop_t, outptr: *uv_process_t,
837 options: uv_process_options_t) -> c_int)
838 externfn!(fn uv_process_kill(p: *uv_process_t, signum: c_int) -> c_int)
841 externfn!(fn uv_pipe_init(l: *uv_loop_t, p: *uv_pipe_t, ipc: c_int) -> c_int)
842 externfn!(fn uv_pipe_open(pipe: *uv_pipe_t, file: c_int) -> c_int)
843 externfn!(fn uv_pipe_bind(pipe: *uv_pipe_t, name: *c_char) -> c_int)
844 externfn!(fn uv_pipe_connect(req: *uv_connect_t, handle: *uv_pipe_t,
845 name: *c_char, cb: uv_connect_cb))
848 externfn!(fn uv_tty_init(l: *uv_loop_t, tty: *uv_tty_t, fd: c_int,
849 readable: c_int) -> c_int)
850 externfn!(fn uv_tty_set_mode(tty: *uv_tty_t, mode: c_int) -> c_int)
851 externfn!(fn uv_tty_get_winsize(tty: *uv_tty_t, width: *c_int,
852 height: *c_int) -> c_int)
853 externfn!(fn uv_guess_handle(fd: c_int) -> uv_handle_type)
856 externfn!(fn uv_signal_init(loop_: *uv_loop_t, handle: *uv_signal_t) -> c_int)
857 externfn!(fn uv_signal_start(h: *uv_signal_t, cb: uv_signal_cb,
858 signum: c_int) -> c_int)
859 externfn!(fn uv_signal_stop(handle: *uv_signal_t) -> c_int)
861 // libuv requires various system libraries to successfully link on some
863 #[cfg(target_os = "linux")]
864 #[link_args = "-lpthread"]
867 #[cfg(target_os = "win32")]
868 #[link_args = "-lWs2_32 -lpsapi -liphlpapi"]