(index<- ) ./libstd/rt/uv/mod.rs
1 // Copyright 2013 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.
4 //
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.
10
11 /*!
12
13 Bindings to libuv, along with the default implementation of `std::rt::rtio`.
14
15 UV types consist of the event loop (Loop), Watchers, Requests and
16 Callbacks.
17
18 Watchers and Requests encapsulate pointers to uv *handles*, which have
19 subtyping relationships with each other. This subtyping is reflected
20 in the bindings with explicit or implicit coercions. For example, an
21 upcast from TcpWatcher to StreamWatcher is done with
22 `tcp_watcher.as_stream()`. In other cases a callback on a specific
23 type of watcher will be passed a watcher of a supertype.
24
25 Currently all use of Request types (connect/write requests) are
26 encapsulated in the bindings and don't need to be dealt with by the
27 caller.
28
29 # Safety note
30
31 Due to the complex lifecycle of uv handles, as well as compiler bugs,
32 this module is not memory safe and requires explicit memory management,
33 via `close` and `delete` methods.
34
35 */
36
37 use container::Container;
38 use option::*;
39 use str::raw::from_c_str;
40 use to_str::ToStr;
41 use ptr::RawPtr;
42 use vec;
43 use vec::ImmutableVector;
44 use ptr;
45 use str;
46 use libc::{c_void, c_int, size_t, malloc, free};
47 use cast::transmute;
48 use ptr::null;
49 use unstable::finally::Finally;
50 use rt::io::net::ip::SocketAddr;
51
52 use rt::io::IoError;
53
54 //#[cfg(test)] use unstable::run_in_bare_thread;
55
56 pub use self::file::{FsRequest};
57 pub use self::net::{StreamWatcher, TcpWatcher, UdpWatcher};
58 pub use self::idle::IdleWatcher;
59 pub use self::timer::TimerWatcher;
60 pub use self::async::AsyncWatcher;
61 pub use self::process::Process;
62 pub use self::pipe::Pipe;
63
64 /// The implementation of `rtio` for libuv
65 pub mod uvio;
66
67 /// C bindings to libuv
68 pub mod uvll;
69
70 pub mod file;
71 pub mod net;
72 pub mod idle;
73 pub mod timer;
74 pub mod async;
75 pub mod addrinfo;
76 pub mod process;
77 pub mod pipe;
78
79 /// XXX: Loop(*handle) is buggy with destructors. Normal structs
80 /// with dtors may not be destructured, but tuple structs can,
81 /// but the results are not correct.
82 pub struct Loop {
83 handle: *uvll::uv_loop_t
84 }
85
86 /// The trait implemented by uv 'watchers' (handles). Watchers are
87 /// non-owning wrappers around the uv handles and are not completely
88 /// safe - there may be multiple instances for a single underlying
89 /// handle. Watchers are generally created, then `start`ed, `stop`ed
90 /// and `close`ed, but due to their complex life cycle may not be
91 /// entirely memory safe if used in unanticipated patterns.
92 pub trait Watcher { }
93
94 pub trait Request { }
95
96 /// A type that wraps a native handle
97 pub trait NativeHandle<T> {
98 fn from_native_handle(T) -> Self;
99 fn native_handle(&self) -> T;
100 }
101
102 impl Loop {
103 pub fn new() -> Loop {
104 let handle = unsafe { uvll::loop_new() };
105 assert!(handle.is_not_null());
106 NativeHandle::from_native_handle(handle)
107 }
108
109 pub fn run(&mut self) {
110 unsafe { uvll::run(self.native_handle()) };
111 }
112
113 pub fn close(&mut self) {
114 unsafe { uvll::loop_delete(self.native_handle()) };
115 }
116 }
117
118 impl NativeHandle<*uvll::uv_loop_t> for Loop {
119 fn from_native_handle(handle: *uvll::uv_loop_t) -> Loop {
120 Loop { handle: handle }
121 }
122 fn native_handle(&self) -> *uvll::uv_loop_t {
123 self.handle
124 }
125 }
126
127 // XXX: The uv alloc callback also has a *uv_handle_t arg
128 pub type AllocCallback = ~fn(uint) -> Buf;
129 pub type ReadCallback = ~fn(StreamWatcher, int, Buf, Option<UvError>);
130 pub type NullCallback = ~fn();
131 pub type IdleCallback = ~fn(IdleWatcher, Option<UvError>);
132 pub type ConnectionCallback = ~fn(StreamWatcher, Option<UvError>);
133 pub type FsCallback = ~fn(&mut FsRequest, Option<UvError>);
134 // first int is exit_status, second is term_signal
135 pub type ExitCallback = ~fn(Process, int, int, Option<UvError>);
136 pub type TimerCallback = ~fn(TimerWatcher, Option<UvError>);
137 pub type AsyncCallback = ~fn(AsyncWatcher, Option<UvError>);
138 pub type UdpReceiveCallback = ~fn(UdpWatcher, int, Buf, SocketAddr, uint, Option<UvError>);
139 pub type UdpSendCallback = ~fn(UdpWatcher, Option<UvError>);
140
141
142 /// Callbacks used by StreamWatchers, set as custom data on the foreign handle.
143 /// XXX: Would be better not to have all watchers allocate room for all callback types.
144 struct WatcherData {
145 read_cb: Option<ReadCallback>,
146 write_cb: Option<ConnectionCallback>,
147 connect_cb: Option<ConnectionCallback>,
148 close_cb: Option<NullCallback>,
149 alloc_cb: Option<AllocCallback>,
150 idle_cb: Option<IdleCallback>,
151 timer_cb: Option<TimerCallback>,
152 async_cb: Option<AsyncCallback>,
153 udp_recv_cb: Option<UdpReceiveCallback>,
154 udp_send_cb: Option<UdpSendCallback>,
155 exit_cb: Option<ExitCallback>,
156 }
157
158 pub trait WatcherInterop {
159 fn event_loop(&self) -> Loop;
160 fn install_watcher_data(&mut self);
161 fn get_watcher_data<'r>(&'r mut self) -> &'r mut WatcherData;
162 fn drop_watcher_data(&mut self);
163 }
164
165 impl<H, W: Watcher + NativeHandle<*H>> WatcherInterop for W {
166 /// Get the uv event loop from a Watcher
167 fn event_loop(&self) -> Loop {
168 unsafe {
169 let handle = self.native_handle();
170 let loop_ = uvll::get_loop_for_uv_handle(handle);
171 NativeHandle::from_native_handle(loop_)
172 }
173 }
174
175 fn install_watcher_data(&mut self) {
176 unsafe {
177 let data = ~WatcherData {
178 read_cb: None,
179 write_cb: None,
180 connect_cb: None,
181 close_cb: None,
182 alloc_cb: None,
183 idle_cb: None,
184 timer_cb: None,
185 async_cb: None,
186 udp_recv_cb: None,
187 udp_send_cb: None,
188 exit_cb: None,
189 };
190 let data = transmute::<~WatcherData, *c_void>(data);
191 uvll::set_data_for_uv_handle(self.native_handle(), data);
192 }
193 }
194
195 fn get_watcher_data<'r>(&'r mut self) -> &'r mut WatcherData {
196 unsafe {
197 let data = uvll::get_data_for_uv_handle(self.native_handle());
198 let data = transmute::<&*c_void, &mut ~WatcherData>(&data);
199 return &mut **data;
200 }
201 }
202
203 fn drop_watcher_data(&mut self) {
204 unsafe {
205 let data = uvll::get_data_for_uv_handle(self.native_handle());
206 let _data = transmute::<*c_void, ~WatcherData>(data);
207 uvll::set_data_for_uv_handle(self.native_handle(), null::<()>());
208 }
209 }
210 }
211
212 // XXX: Need to define the error constants like EOF so they can be
213 // compared to the UvError type
214
215 pub struct UvError(c_int);
216
217 impl UvError {
218 pub fn name(&self) -> ~str {
219 unsafe {
220 let inner = match self { &UvError(a) => a };
221 let name_str = uvll::err_name(inner);
222 assert!(name_str.is_not_null());
223 from_c_str(name_str)
224 }
225 }
226
227 pub fn desc(&self) -> ~str {
228 unsafe {
229 let inner = match self { &UvError(a) => a };
230 let desc_str = uvll::strerror(inner);
231 assert!(desc_str.is_not_null());
232 from_c_str(desc_str)
233 }
234 }
235
236 pub fn is_eof(&self) -> bool {
237 **self == uvll::EOF
238 }
239 }
240
241 impl ToStr for UvError {
242 fn to_str(&self) -> ~str {
243 format!("{}: {}", self.name(), self.desc())
244 }
245 }
246
247 #[test]
248 fn error_smoke_test() {
249 let err: UvError = UvError(uvll::EOF);
250 assert_eq!(err.to_str(), ~"EOF: end of file");
251 }
252
253 pub fn uv_error_to_io_error(uverr: UvError) -> IoError {
254 unsafe {
255 // Importing error constants
256 use rt::uv::uvll::*;
257 use rt::io::*;
258
259 // uv error descriptions are static
260 let c_desc = uvll::strerror(*uverr);
261 let desc = str::raw::c_str_to_static_slice(c_desc);
262
263 let kind = match *uverr {
264 UNKNOWN => OtherIoError,
265 OK => OtherIoError,
266 EOF => EndOfFile,
267 EACCES => PermissionDenied,
268 ECONNREFUSED => ConnectionRefused,
269 ECONNRESET => ConnectionReset,
270 ENOTCONN => NotConnected,
271 EPIPE => BrokenPipe,
272 err => {
273 rtdebug!("uverr.code {}", err as int);
274 // XXX: Need to map remaining uv error types
275 OtherIoError
276 }
277 };
278
279 IoError {
280 kind: kind,
281 desc: desc,
282 detail: None
283 }
284 }
285 }
286
287 /// Given a uv handle, convert a callback status to a UvError
288 pub fn status_to_maybe_uv_error(status: c_int) -> Option<UvError>
289 {
290 if status >= 0 {
291 None
292 } else {
293 Some(UvError(status))
294 }
295 }
296
297 /// The uv buffer type
298 pub type Buf = uvll::uv_buf_t;
299
300 /// Borrow a slice to a Buf
301 pub fn slice_to_uv_buf(v: &[u8]) -> Buf {
302 let data = vec::raw::to_ptr(v);
303 unsafe { uvll::buf_init(data, v.len()) }
304 }
305
306 // XXX: Do these conversions without copying
307
308 /// Transmute an owned vector to a Buf
309 pub fn vec_to_uv_buf(v: ~[u8]) -> Buf {
310 #[fixed_stack_segment]; #[inline(never)];
311
312 unsafe {
313 let data = malloc(v.len() as size_t) as *u8;
314 assert!(data.is_not_null());
315 do v.as_imm_buf |b, l| {
316 let data = data as *mut u8;
317 ptr::copy_memory(data, b, l)
318 }
319 uvll::buf_init(data, v.len())
320 }
321 }
322
323 /// Transmute a Buf that was once a ~[u8] back to ~[u8]
324 pub fn vec_from_uv_buf(buf: Buf) -> Option<~[u8]> {
325 #[fixed_stack_segment]; #[inline(never)];
326
327 if !(buf.len == 0 && buf.base.is_null()) {
328 let v = unsafe { vec::from_buf(buf.base, buf.len as uint) };
329 unsafe { free(buf.base as *c_void) };
330 return Some(v);
331 } else {
332 // No buffer
333 rtdebug!("No buffer!");
334 return None;
335 }
336 }
337 /*
338 #[test]
339 fn test_slice_to_uv_buf() {
340 let slice = [0, .. 20];
341 let buf = slice_to_uv_buf(slice);
342
343 assert!(buf.len == 20);
344
345 unsafe {
346 let base = transmute::<*u8, *mut u8>(buf.base);
347 (*base) = 1;
348 (*ptr::mut_offset(base, 1)) = 2;
349 }
350
351 assert!(slice[0] == 1);
352 assert!(slice[1] == 2);
353 }
354
355
356 #[test]
357 fn loop_smoke_test() {
358 do run_in_bare_thread {
359 let mut loop_ = Loop::new();
360 loop_.run();
361 loop_.close();
362 }
363 }
364 */
libstd/rt/uv/mod.rs:300:28-300:28 -fn- definition:
/// Borrow a slice to a Buf
pub fn slice_to_uv_buf(v: &[u8]) -> Buf {
references:-libstd/rt/uv/uvio.rs:
1182: let alloc: AllocCallback = |_| unsafe { slice_to_uv_buf(*buf_ptr) };
1426: let buf = unsafe { slice_to_uv_buf(*buf_ptr) };
934: slice_to_uv_buf(*buf_ptr)
970: let buf = unsafe { slice_to_uv_buf(*buf_ptr) };
1448: let buf = unsafe { slice_to_uv_buf(*buf_ptr) };
1215: let buf = unsafe { slice_to_uv_buf(*buf_ptr) };
libstd/rt/uv/mod.rs:93:1-93:1 -trait- definition:
pub trait Request { }
references:-libstd/rt/uv/file.rs:
25: impl Request for FsRequest {}
libstd/rt/uv/net.rs:
501: impl Request for WriteRequest { }
468: impl Request for ConnectRequest { }
532: impl Request for UdpSendRequest { }
libstd/rt/uv/mod.rs:130:31-130:31 -ty- definition:
pub type NullCallback = ~fn();
pub type IdleCallback = ~fn(IdleWatcher, Option<UvError>);
references:-150: idle_cb: Option<IdleCallback>,
libstd/rt/uv/idle.rs:
59: let cb: &IdleCallback = data.idle_cb.get_ref();
45: let cb: &IdleCallback = data.idle_cb.get_ref();
32: pub fn start(&mut self, cb: IdleCallback) {
libstd/rt/uv/mod.rs:143:88-143:88 -struct- definition:
/// XXX: Would be better not to have all watchers allocate room for all callback types.
struct WatcherData {
references:-177: let data = ~WatcherData {
198: let data = transmute::<&*c_void, &mut ~WatcherData>(&data);
195: fn get_watcher_data<'r>(&'r mut self) -> &'r mut WatcherData {
206: let _data = transmute::<*c_void, ~WatcherData>(data);
190: let data = transmute::<~WatcherData, *c_void>(data);
161: fn get_watcher_data<'r>(&'r mut self) -> &'r mut WatcherData;
libstd/rt/uv/mod.rs:214:1-214:1 -struct- definition:
pub struct UvError(c_int);
references:-288: pub fn status_to_maybe_uv_error(status: c_int) -> Option<UvError>
129: pub type ReadCallback = ~fn(StreamWatcher, int, Buf, Option<UvError>);
139: pub type UdpSendCallback = ~fn(UdpWatcher, Option<UvError>);
138: pub type UdpReceiveCallback = ~fn(UdpWatcher, int, Buf, SocketAddr, uint, Option<UvError>);
136: pub type TimerCallback = ~fn(TimerWatcher, Option<UvError>);
131: pub type IdleCallback = ~fn(IdleWatcher, Option<UvError>);
132: pub type ConnectionCallback = ~fn(StreamWatcher, Option<UvError>);
217: impl UvError {
135: pub type ExitCallback = ~fn(Process, int, int, Option<UvError>);
241: impl ToStr for UvError {
253: pub fn uv_error_to_io_error(uverr: UvError) -> IoError {
133: pub type FsCallback = ~fn(&mut FsRequest, Option<UvError>);
137: pub type AsyncCallback = ~fn(AsyncWatcher, Option<UvError>);
libstd/rt/uv/uvio.rs:
1542: priv exit_error: Option<UvError>,
419: ~fn(&FsRequest, Option<UvError>)))
libstd/rt/uv/file.rs:
231: -> Result<c_int, UvError> {
177: pub fn close_sync(self, loop_: &Loop, fd: c_int) -> Result<c_int, UvError> {
54: flags: int, mode: int) -> Result<c_int, UvError> {
334: -> Result<int, UvError> {
152: -> Result<c_int, UvError> {
123: -> Result<c_int, UvError> {
82: -> Result<c_int, UvError> {
libstd/rt/uv/net.rs:
354: pub fn bind(&mut self, address: SocketAddr) -> Result<(), UvError> {
259: pub fn bind(&mut self, address: SocketAddr) -> Result<(), UvError> {
libstd/rt/uv/addrinfo.rs:
23: type GetAddrInfoCallback = ~fn(GetAddrInfoRequest, &UvAddrInfo, Option<UvError>);
libstd/rt/uv/process.rs:
47: -> Result<~[Option<UvPipeStream>], uv::UvError>
112: pub fn kill(&self, signum: int) -> Result<(), uv::UvError> {
libstd/rt/uv/mod.rs:135:65-135:65 -ty- definition:
pub type ExitCallback = ~fn(Process, int, int, Option<UvError>);
pub type TimerCallback = ~fn(TimerWatcher, Option<UvError>);
references:-151: timer_cb: Option<TimerCallback>,
libstd/rt/uv/timer.rs:
32: pub fn start(&mut self, timeout: u64, repeat: u64, cb: TimerCallback) {
libstd/rt/uv/mod.rs:137:61-137:61 -ty- definition:
pub type AsyncCallback = ~fn(AsyncWatcher, Option<UvError>);
pub type UdpReceiveCallback = ~fn(UdpWatcher, int, Buf, SocketAddr, uint, Option<UvError>);
references:-153: udp_recv_cb: Option<UdpReceiveCallback>,
libstd/rt/uv/net.rs:
369: pub fn recv_start(&mut self, alloc: AllocCallback, cb: UdpReceiveCallback) {
libstd/rt/uv/mod.rs:91:60-91:60 -trait- definition:
/// entirely memory safe if used in unanticipated patterns.
pub trait Watcher { }
references:-165: impl<H, W: Watcher + NativeHandle<*H>> WatcherInterop for W {
libstd/rt/uv/uvio.rs:
146: fn socket_name<T, U: Watcher + NativeHandle<*T>>(sk: SocketNameKind,
libstd/rt/uv/net.rs:
340: impl Watcher for UdpWatcher { }
245: impl Watcher for TcpWatcher { }
140: impl Watcher for StreamWatcher { }
libstd/rt/uv/idle.rs:
18: impl Watcher for IdleWatcher { }
libstd/rt/uv/timer.rs:
18: impl Watcher for TimerWatcher { }
libstd/rt/uv/async.rs:
20: impl Watcher for AsyncWatcher { }
libstd/rt/uv/process.rs:
26: impl uv::Watcher for Process {}
libstd/rt/uv/pipe.rs:
20: impl uv::Watcher for Pipe {}
libstd/rt/uv/mod.rs:134:51-134:51 -ty- definition:
// first int is exit_status, second is term_signal
pub type ExitCallback = ~fn(Process, int, int, Option<UvError>);
references:-155: exit_cb: Option<ExitCallback>,
libstd/rt/uv/uvio.rs:
772: let exit_cb: ExitCallback = |_, exit_status, term_signal, error| {
libstd/rt/uv/process.rs:
46: exit_cb: uv::ExitCallback)
libstd/rt/uv/mod.rs:136:61-136:61 -ty- definition:
pub type TimerCallback = ~fn(TimerWatcher, Option<UvError>);
pub type AsyncCallback = ~fn(AsyncWatcher, Option<UvError>);
references:-152: async_cb: Option<AsyncCallback>,
libstd/rt/uv/async.rs:
23: pub fn new(loop_: &mut Loop, cb: AsyncCallback) -> AsyncWatcher {
libstd/rt/uv/mod.rs:252:1-252:1 -fn- definition:
pub fn uv_error_to_io_error(uverr: UvError) -> IoError {
references:-libstd/rt/uv/uvio.rs:
1303: Some(err) => Err(uv_error_to_io_error(err)),
975: Err(uv_error_to_io_error(status.unwrap()))
1245: Some(err) => Err(uv_error_to_io_error(err)),
915: Some(err) => Err(uv_error_to_io_error(err)),
1261: Some(err) => Err(uv_error_to_io_error(err)),
481: let res = Err(uv_error_to_io_error(status.unwrap()));
1097: Some(err) => Err(uv_error_to_io_error(err)),
1432: Some(err) => Err(uv_error_to_io_error(err))
1193: Some(err) => Err(uv_error_to_io_error(err)),
902: Some(err) => Err(uv_error_to_io_error(err)),
645: Err(uv_error_to_io_error(e))
1220: Some(err) => Err(uv_error_to_io_error(err)),
1331: Some(err) => Err(uv_error_to_io_error(err)),
1584: Err(uverr) => Err(uv_error_to_io_error(uverr))
164: return Err(uv_error_to_io_error(status.unwrap()));
597: let res = Err(uv_error_to_io_error(err.unwrap()));
513: Err(uv_error_to_io_error(uverr))
1275: Some(err) => Err(uv_error_to_io_error(err)),
948: Err(uv_error_to_io_error(status.unwrap()))
731: Err(uv_error_to_io_error(e))
797: Err(uv_error_to_io_error(uverr))
1108: Some(err) => Err(uv_error_to_io_error(err)),
1135: Some(err) => Err(uv_error_to_io_error(err)),
1122: Some(err) => Err(uv_error_to_io_error(err)),
433: Some(err) => Err(uv_error_to_io_error(err))
675: Some(err) => Err(uv_error_to_io_error(err))
536: Err(uv_error_to_io_error(uverr))
1317: Some(err) => Err(uv_error_to_io_error(err)),
1289: Some(err) => Err(uv_error_to_io_error(err)),
1454: Some(err) => Err(uv_error_to_io_error(err))
(1345)libstd/rt/uv/mod.rs:131:59-131:59 -ty- definition:
pub type IdleCallback = ~fn(IdleWatcher, Option<UvError>);
pub type ConnectionCallback = ~fn(StreamWatcher, Option<UvError>);
references:-146: write_cb: Option<ConnectionCallback>,
147: connect_cb: Option<ConnectionCallback>,
libstd/rt/uv/net.rs:
187: pub fn write(&mut self, buf: Buf, cb: ConnectionCallback) {
303: pub fn listen(&mut self, cb: ConnectionCallback) {
274: pub fn connect(&mut self, address: SocketAddr, cb: ConnectionCallback) {
libstd/rt/uv/mod.rs:308:39-308:39 -fn- definition:
/// Transmute an owned vector to a Buf
pub fn vec_to_uv_buf(v: ~[u8]) -> Buf {
references:-libstd/rt/uv/net.rs:
160: read_cb(stream, errno, vec_to_uv_buf(~[]));
libstd/rt/uv/mod.rs:287:62-287:62 -fn- definition:
/// Given a uv handle, convert a callback status to a UvError
pub fn status_to_maybe_uv_error(status: c_int) -> Option<UvError>
references:-libstd/rt/uv/uvio.rs:
1107: match status_to_maybe_uv_error(r) {
1288: match status_to_maybe_uv_error(r) {
1274: match status_to_maybe_uv_error(r) {
1344: match status_to_maybe_uv_error(r) {
1134: match status_to_maybe_uv_error(r) {
1302: match status_to_maybe_uv_error(r) {
1096: match status_to_maybe_uv_error(r) {
1260: match status_to_maybe_uv_error(r) {
1244: match status_to_maybe_uv_error(r) {
1330: match status_to_maybe_uv_error(r) {
163: let status = status_to_maybe_uv_error(r);
1316: match status_to_maybe_uv_error(r) {
901: match status_to_maybe_uv_error(r) {
914: match status_to_maybe_uv_error(r) {
1121: match status_to_maybe_uv_error(r) {
libstd/rt/uv/file.rs:
353: let status = status_to_maybe_uv_error(result);
335: match status_to_maybe_uv_error(result as i32) {
233: match status_to_maybe_uv_error(result as i32) {
libstd/rt/uv/net.rs:
397: let status = status_to_maybe_uv_error(nread as c_int);
297: let status = status_to_maybe_uv_error(status);
174: let status = status_to_maybe_uv_error(nread as c_int);
204: let status = status_to_maybe_uv_error(status);
320: let status = status_to_maybe_uv_error(status);
432: let status = status_to_maybe_uv_error(status);
libstd/rt/uv/idle.rs:
60: let status = status_to_maybe_uv_error(status);
46: let status = status_to_maybe_uv_error(status);
libstd/rt/uv/timer.rs:
46: let status = status_to_maybe_uv_error(status);
libstd/rt/uv/async.rs:
37: let status = status_to_maybe_uv_error(status);
libstd/rt/uv/addrinfo.rs:
93: let err = status_to_maybe_uv_error(status);
libstd/rt/uv/process.rs:
57: _ => uv::status_to_maybe_uv_error(-1)
libstd/rt/uv/mod.rs:297:23-297:23 -ty- definition:
/// The uv buffer type
pub type Buf = uvll::uv_buf_t;
references:-301: pub fn slice_to_uv_buf(v: &[u8]) -> Buf {
309: pub fn vec_to_uv_buf(v: ~[u8]) -> Buf {
138: pub type UdpReceiveCallback = ~fn(UdpWatcher, int, Buf, SocketAddr, uint, Option<UvError>);
128: pub type AllocCallback = ~fn(uint) -> Buf;
324: pub fn vec_from_uv_buf(buf: Buf) -> Option<~[u8]> {
129: pub type ReadCallback = ~fn(StreamWatcher, int, Buf, Option<UvError>);
libstd/rt/uv/file.rs:
122: pub fn write_sync(self, loop_: &Loop, fd: c_int, buf: Buf, offset: i64)
138: pub fn read(self, loop_: &Loop, fd: c_int, buf: Buf, offset: i64, cb: FsCallback) {
151: pub fn read_sync(self, loop_: &Loop, fd: c_int, buf: Buf, offset: i64)
109: pub fn write(self, loop_: &Loop, fd: c_int, buf: Buf, offset: i64, cb: FsCallback) {
libstd/rt/uv/net.rs:
187: pub fn write(&mut self, buf: Buf, cb: ConnectionCallback) {
378: extern fn alloc_cb(handle: *uvll::uv_udp_t, suggested_size: size_t) -> Buf {
169: extern fn read_cb(stream: *uvll::uv_stream_t, nread: ssize_t, buf: Buf) {
163: extern fn alloc_cb(stream: *uvll::uv_stream_t, suggested_size: size_t) -> Buf {
384: extern fn recv_cb(handle: *uvll::uv_udp_t, nread: ssize_t, buf: Buf,
407: pub fn send(&mut self, buf: Buf, address: SocketAddr, cb: UdpSendCallback) {
libstd/rt/uv/mod.rs:138:92-138:92 -ty- definition:
pub type UdpReceiveCallback = ~fn(UdpWatcher, int, Buf, SocketAddr, uint, Option<UvError>);
pub type UdpSendCallback = ~fn(UdpWatcher, Option<UvError>);
references:-154: udp_send_cb: Option<UdpSendCallback>,
libstd/rt/uv/net.rs:
407: pub fn send(&mut self, buf: Buf, address: SocketAddr, cb: UdpSendCallback) {
libstd/rt/uv/mod.rs:132:67-132:67 -ty- definition:
pub type ConnectionCallback = ~fn(StreamWatcher, Option<UvError>);
pub type FsCallback = ~fn(&mut FsRequest, Option<UvError>);
references:-libstd/rt/uv/file.rs:
238: fn req_boilerplate(&mut self, cb: Option<FsCallback>) -> *u8 {
216: flags: c_int, cb: FsCallback) {
40: cb: FsCallback) {
28: complete_cb: Option<FsCallback>
189: pub fn mkdir<P: PathLike>(self, loop_: &Loop, path: &P, mode: int, cb: FsCallback) {
248: pub fn install_req_data(&mut self, cb: Option<FsCallback>) {
202: pub fn rmdir<P: PathLike>(self, loop_: &Loop, path: &P, cb: FsCallback) {
96: pub fn stat<P: PathLike>(self, loop_: &Loop, path: &P, cb: FsCallback) {
109: pub fn write(self, loop_: &Loop, fd: c_int, buf: Buf, offset: i64, cb: FsCallback) {
138: pub fn read(self, loop_: &Loop, fd: c_int, buf: Buf, offset: i64, cb: FsCallback) {
167: pub fn close(self, loop_: &Loop, fd: c_int, cb: FsCallback) {
68: pub fn unlink<P: PathLike>(self, loop_: &Loop, path: &P, cb: FsCallback) {
libstd/rt/uv/mod.rs:96:38-96:38 -trait- definition:
/// A type that wraps a native handle
pub trait NativeHandle<T> {
references:-165: impl<H, W: Watcher + NativeHandle<*H>> WatcherInterop for W {
98: fn from_native_handle(T) -> Self;
118: impl NativeHandle<*uvll::uv_loop_t> for Loop {
libstd/rt/uv/uvio.rs:
146: fn socket_name<T, U: Watcher + NativeHandle<*T>>(sk: SocketNameKind,
libstd/rt/uv/file.rs:
324: impl NativeHandle<*uvll::uv_fs_t> for FsRequest {
libstd/rt/uv/net.rs:
457: impl NativeHandle<*uvll::uv_udp_t> for UdpWatcher {
522: impl NativeHandle<*uvll::uv_write_t> for WriteRequest {
330: impl NativeHandle<*uvll::uv_tcp_t> for TcpWatcher {
235: impl NativeHandle<*uvll::uv_stream_t> for StreamWatcher {
553: impl NativeHandle<*uvll::uv_udp_send_t> for UdpSendRequest {
490: impl NativeHandle<*uvll::uv_connect_t> for ConnectRequest {
libstd/rt/uv/idle.rs:
99: impl NativeHandle<*uvll::uv_idle_t> for IdleWatcher {
libstd/rt/uv/timer.rs:
83: impl NativeHandle<*uvll::uv_timer_t> for TimerWatcher {
libstd/rt/uv/async.rs:
73: impl NativeHandle<*uvll::uv_async_t> for AsyncWatcher {
libstd/rt/uv/addrinfo.rs:
140: impl NativeHandle<*uvll::uv_getaddrinfo_t> for GetAddrInfoRequest {
libstd/rt/uv/process.rs:
212: impl uv::NativeHandle<*uvll::uv_process_t> for Process {
libstd/rt/uv/pipe.rs:
59: impl uv::NativeHandle<*uvll::uv_pipe_t> for Pipe {
libstd/rt/uv/mod.rs:81:37-81:37 -struct- definition:
/// but the results are not correct.
pub struct Loop {
references:-102: impl Loop {
119: fn from_native_handle(handle: *uvll::uv_loop_t) -> Loop {
103: pub fn new() -> Loop {
120: Loop { handle: handle }
118: impl NativeHandle<*uvll::uv_loop_t> for Loop {
167: fn event_loop(&self) -> Loop {
159: fn event_loop(&self) -> Loop;
libstd/rt/uv/uvio.rs:
410: pub fn uv_loop<'a>(&'a mut self) -> &'a mut Loop {
1411: fn new(loop_: Loop, fd: c_int, close_on_drop: bool,
417: fn uv_fs_helper<P: PathLike>(loop_: &mut Loop, path: &P,
304: pub fn new(loop_: &mut Loop, f: ~fn()) -> UvRemoteCallback {
587: let loop_ = Loop {handle: req.get_loop().native_handle()};
549: let loop_ = Loop {handle: self.uv_loop().native_handle()};
418: cb: ~fn(&mut FsRequest, &mut Loop, &P,
1400: loop_: Loop,
407: pub struct UvIoFactory(Loop);
libstd/rt/uv/file.rs:
215: pub fn readdir<P: PathLike>(self, loop_: &Loop, path: &P,
96: pub fn stat<P: PathLike>(self, loop_: &Loop, path: &P, cb: FsCallback) {
53: pub fn open_sync<P: PathLike>(self, loop_: &Loop, path: &P,
167: pub fn close(self, loop_: &Loop, fd: c_int, cb: FsCallback) {
122: pub fn write_sync(self, loop_: &Loop, fd: c_int, buf: Buf, offset: i64)
109: pub fn write(self, loop_: &Loop, fd: c_int, buf: Buf, offset: i64, cb: FsCallback) {
68: pub fn unlink<P: PathLike>(self, loop_: &Loop, path: &P, cb: FsCallback) {
274: unsafe { Loop{handle:uvll::get_loop_from_fs_req(self.native_handle())} }
138: pub fn read(self, loop_: &Loop, fd: c_int, buf: Buf, offset: i64, cb: FsCallback) {
273: pub fn get_loop(&self) -> Loop {
189: pub fn mkdir<P: PathLike>(self, loop_: &Loop, path: &P, mode: int, cb: FsCallback) {
202: pub fn rmdir<P: PathLike>(self, loop_: &Loop, path: &P, cb: FsCallback) {
177: pub fn close_sync(self, loop_: &Loop, fd: c_int) -> Result<c_int, UvError> {
81: pub fn unlink_sync<P: PathLike>(self, loop_: &Loop, path: &P)
(39)(151)libstd/rt/uv/net.rs:
(343)(248)libstd/rt/uv/idle.rs:
(21)libstd/rt/uv/timer.rs:
(21)libstd/rt/uv/async.rs:
(23)libstd/rt/uv/addrinfo.rs:
(105)(40)(103)libstd/rt/uv/process.rs:
(45)libstd/rt/uv/pipe.rs:
(23)libstd/rt/uv/mod.rs:157:1-157:1 -trait- definition:
pub trait WatcherInterop {
references:-165: impl<H, W: Watcher + NativeHandle<*H>> WatcherInterop for W {
libstd/rt/uv/mod.rs:128:43-128:43 -ty- definition:
pub type AllocCallback = ~fn(uint) -> Buf;
pub type ReadCallback = ~fn(StreamWatcher, int, Buf, Option<UvError>);
references:-145: read_cb: Option<ReadCallback>,
libstd/rt/uv/net.rs:
143: pub fn read_start(&mut self, alloc: AllocCallback, cb: ReadCallback) {
libstd/rt/uv/mod.rs:129:71-129:71 -ty- definition:
pub type ReadCallback = ~fn(StreamWatcher, int, Buf, Option<UvError>);
pub type NullCallback = ~fn();
references:-148: close_cb: Option<NullCallback>,
libstd/rt/uv/net.rs:
437: pub fn close(self, cb: NullCallback) {
215: pub fn close(self, cb: NullCallback) {
libstd/rt/uv/idle.rs:
75: pub fn close(self, cb: NullCallback) {
libstd/rt/uv/timer.rs:
57: pub fn close(self, cb: NullCallback) {
libstd/rt/uv/async.rs:
51: pub fn close(self, cb: NullCallback) {
libstd/rt/uv/process.rs:
127: pub fn close(self, cb: uv::NullCallback) {
libstd/rt/uv/pipe.rs:
40: pub fn close(self, cb: uv::NullCallback) {
libstd/rt/uv/mod.rs:127:58-127:58 -ty- definition:
// XXX: The uv alloc callback also has a *uv_handle_t arg
pub type AllocCallback = ~fn(uint) -> Buf;
references:-149: alloc_cb: Option<AllocCallback>,
libstd/rt/uv/uvio.rs:
1182: let alloc: AllocCallback = |_| unsafe { slice_to_uv_buf(*buf_ptr) };
933: let alloc: AllocCallback = |_| unsafe {
libstd/rt/uv/net.rs:
369: pub fn recv_start(&mut self, alloc: AllocCallback, cb: UdpReceiveCallback) {
143: pub fn read_start(&mut self, alloc: AllocCallback, cb: ReadCallback) {