Skip to content

Commit a134503

Browse files
committed
core::rt: Move all the uv callback definitions to one place
1 parent dbf8966 commit a134503

File tree

4 files changed

+23
-42
lines changed

4 files changed

+23
-42
lines changed

src/libcore/rt/uv/file.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,11 @@
1111
use prelude::*;
1212
use ptr::null;
1313
use libc::c_void;
14-
use super::{UvError, Callback, Request, NativeHandle, Loop};
14+
use rt::uv::{Request, NativeHandle, Loop, FsCallback};
1515
use rt::uv::uvll;
1616
use rt::uv::uvll::*;
1717

18-
pub type FsCallback = ~fn(FsRequest, Option<UvError>);
19-
impl Callback for FsCallback { }
20-
2118
pub struct FsRequest(*uvll::uv_fs_t);
22-
2319
impl Request for FsRequest;
2420

2521
impl FsRequest {

src/libcore/rt/uv/idle.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,14 @@
99
// except according to those terms.
1010

1111
use libc::c_int;
12-
use option::{Option, Some, None};
12+
use option::{Some, None};
1313
use rt::uv::uvll;
14-
use rt::uv::{Watcher, Callback, Loop, UvError, NativeHandle};
14+
use rt::uv::{Watcher, Loop, NativeHandle, IdleCallback};
1515
use rt::uv::status_to_maybe_uv_error;
1616

1717
pub struct IdleWatcher(*uvll::uv_idle_t);
1818
impl Watcher for IdleWatcher { }
1919

20-
pub type IdleCallback = ~fn(IdleWatcher, Option<UvError>);
21-
impl Callback for IdleCallback { }
22-
2320
pub impl IdleWatcher {
2421
fn new(loop_: &mut Loop) -> IdleWatcher {
2522
unsafe {

src/libcore/rt/uv/mod.rs

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,9 @@ use rt::io::IoError;
5151

5252
#[cfg(test)] use unstable::run_in_bare_thread;
5353

54-
pub use self::file::{FsRequest, FsCallback};
54+
pub use self::file::FsRequest;
5555
pub use self::net::{StreamWatcher, TcpWatcher};
56-
pub use self::net::{ReadCallback, AllocCallback, ConnectionCallback, ConnectCallback};
57-
pub use self::idle::{IdleWatcher, IdleCallback};
56+
pub use self::idle::IdleWatcher;
5857

5958
/// The implementation of `rtio` for libuv
6059
pub mod uvio;
@@ -66,11 +65,12 @@ pub mod file;
6665
pub mod net;
6766
pub mod idle;
6867

69-
/// A trait for callbacks to implement. Provides a little extra type safety
70-
/// for generic, unsafe interop functions like `set_watcher_callback`.
71-
pub trait Callback { }
72-
73-
pub trait Request { }
68+
/// XXX: Loop(*handle) is buggy with destructors. Normal structs
69+
/// with dtors may not be destructured, but tuple structs can,
70+
/// but the results are not correct.
71+
pub struct Loop {
72+
handle: *uvll::uv_loop_t
73+
}
7474

7575
/// The trait implemented by uv 'watchers' (handles). Watchers are
7676
/// non-owning wrappers around the uv handles and are not completely
@@ -80,22 +80,14 @@ pub trait Request { }
8080
/// entirely memory safe if used in unanticipated patterns.
8181
pub trait Watcher { }
8282

83-
pub type NullCallback = ~fn();
84-
impl Callback for NullCallback { }
83+
pub trait Request { }
8584

8685
/// A type that wraps a native handle
8786
pub trait NativeHandle<T> {
8887
pub fn from_native_handle(T) -> Self;
8988
pub fn native_handle(&self) -> T;
9089
}
9190

92-
/// XXX: Loop(*handle) is buggy with destructors. Normal structs
93-
/// with dtors may not be destructured, but tuple structs can,
94-
/// but the results are not correct.
95-
pub struct Loop {
96-
handle: *uvll::uv_loop_t
97-
}
98-
9991
pub impl Loop {
10092
fn new() -> Loop {
10193
let handle = unsafe { uvll::loop_new() };
@@ -121,6 +113,15 @@ impl NativeHandle<*uvll::uv_loop_t> for Loop {
121113
}
122114
}
123115

116+
// XXX: The uv alloc callback also has a *uv_handle_t arg
117+
pub type AllocCallback = ~fn(uint) -> Buf;
118+
pub type ReadCallback = ~fn(StreamWatcher, int, Buf, Option<UvError>);
119+
pub type NullCallback = ~fn();
120+
pub type IdleCallback = ~fn(IdleWatcher, Option<UvError>);
121+
pub type ConnectionCallback = ~fn(StreamWatcher, Option<UvError>);
122+
pub type FsCallback = ~fn(FsRequest, Option<UvError>);
123+
124+
124125
/// Callbacks used by StreamWatchers, set as custom data on the foreign handle
125126
struct WatcherData {
126127
read_cb: Option<ReadCallback>,

src/libcore/rt/uv/net.rs

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ use libc::{size_t, ssize_t, c_int, c_void};
1313
use util::ignore;
1414
use rt::uv::uvll;
1515
use rt::uv::uvll::*;
16-
use super::{Loop, Watcher, Request, UvError, Buf, Callback, NativeHandle, NullCallback,
16+
use rt::uv::{AllocCallback, ConnectionCallback, ReadCallback};
17+
use super::{Loop, Watcher, Request, UvError, Buf, NativeHandle, NullCallback,
1718
status_to_maybe_uv_error, vec_to_uv_buf, vec_from_uv_buf, slice_to_uv_buf};
1819
use super::super::io::net::ip::{IpAddr, Ipv4, Ipv6};
1920
use rt::uv::last_uv_error;
@@ -48,13 +49,6 @@ fn ip4_as_uv_ip4<T>(addr: IpAddr, f: &fn(*sockaddr_in) -> T) -> T {
4849
pub struct StreamWatcher(*uvll::uv_stream_t);
4950
impl Watcher for StreamWatcher { }
5051

51-
pub type ReadCallback = ~fn(StreamWatcher, int, Buf, Option<UvError>);
52-
impl Callback for ReadCallback { }
53-
54-
// XXX: The uv alloc callback also has a *uv_handle_t arg
55-
pub type AllocCallback = ~fn(uint) -> Buf;
56-
impl Callback for AllocCallback { }
57-
5852
pub impl StreamWatcher {
5953

6054
fn read_start(&mut self, alloc: AllocCallback, cb: ReadCallback) {
@@ -165,9 +159,6 @@ impl NativeHandle<*uvll::uv_stream_t> for StreamWatcher {
165159
pub struct TcpWatcher(*uvll::uv_tcp_t);
166160
impl Watcher for TcpWatcher { }
167161

168-
pub type ConnectionCallback = ~fn(StreamWatcher, Option<UvError>);
169-
impl Callback for ConnectionCallback { }
170-
171162
pub impl TcpWatcher {
172163
fn new(loop_: &mut Loop) -> TcpWatcher {
173164
unsafe {
@@ -268,12 +259,8 @@ impl NativeHandle<*uvll::uv_tcp_t> for TcpWatcher {
268259
}
269260
}
270261

271-
pub type ConnectCallback = ~fn(ConnectRequest, Option<UvError>);
272-
impl Callback for ConnectCallback { }
273-
274262
// uv_connect_t is a subclass of uv_req_t
275263
struct ConnectRequest(*uvll::uv_connect_t);
276-
277264
impl Request for ConnectRequest { }
278265

279266
impl ConnectRequest {

0 commit comments

Comments
 (0)