Skip to content

Commit a882554

Browse files
committed
core: Refactor uv bindings
I can already see these are going to get massive. Putting them into multiple files.
1 parent 7ef54c7 commit a882554

File tree

7 files changed

+535
-483
lines changed

7 files changed

+535
-483
lines changed

src/libcore/rt/io/file.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,21 @@ use super::Stream;
1616
pub struct FileStream;
1717

1818
pub impl FileStream {
19-
static fn new(path: Path) -> FileStream {
19+
static fn new(_path: Path) -> FileStream {
2020
fail!()
2121
}
2222
}
2323

2424
impl Stream for FileStream {
25-
fn read(&mut self, buf: &mut [u8]) -> uint {
25+
fn read(&mut self, _buf: &mut [u8]) -> uint {
2626
fail!()
2727
}
2828

2929
fn eof(&mut self) -> bool {
3030
fail!()
3131
}
3232

33-
fn write(&mut self, v: &const [u8]) {
33+
fn write(&mut self, _v: &const [u8]) {
3434
fail!()
3535
}
3636
}

src/libcore/rt/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ mod sched;
3333
mod rtio;
3434
pub mod uvll;
3535
mod uvio;
36+
#[path = "uv/mod.rs"]
3637
mod uv;
3738
#[path = "io/mod.rs"]
3839
mod io;

src/libcore/rt/thread.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ use ops::Drop;
1414
#[allow(non_camel_case_types)] // runtime type
1515
type raw_thread = libc::c_void;
1616

17-
struct Thread {
17+
pub struct Thread {
1818
main: ~fn(),
1919
raw_thread: *raw_thread
2020
}
2121

22-
impl Thread {
22+
pub impl Thread {
2323
static fn start(main: ~fn()) -> Thread {
2424
fn substart(main: &fn()) -> *raw_thread {
2525
unsafe { rust_raw_thread_start(&main) }

src/libcore/rt/uv/file.rs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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+
use prelude::*;
12+
use ptr::null;
13+
use libc::c_void;
14+
use super::{UvError, Callback, Request, NativeHandle, Loop};
15+
use super::super::uvll;
16+
use super::super::uvll::*;
17+
18+
pub type FsCallback = ~fn(FsRequest, Option<UvError>);
19+
impl Callback for FsCallback { }
20+
21+
pub struct FsRequest(*uvll::uv_fs_t);
22+
23+
impl Request for FsRequest;
24+
25+
impl FsRequest {
26+
static fn new() -> FsRequest {
27+
let fs_req = unsafe { malloc_req(UV_FS) };
28+
fail_unless!(fs_req.is_not_null());
29+
let fs_req = fs_req as *uvll::uv_write_t;
30+
unsafe { uvll::set_data_for_req(fs_req, null::<()>()); }
31+
NativeHandle::from_native_handle(fs_req)
32+
}
33+
34+
fn delete(self) {
35+
unsafe { free_req(self.native_handle() as *c_void) }
36+
}
37+
38+
fn open(&mut self, _loop_: &Loop, _cb: FsCallback) {
39+
}
40+
41+
fn close(&mut self, _loop_: &Loop, _cb: FsCallback) {
42+
}
43+
}
44+
45+
impl NativeHandle<*uvll::uv_fs_t> for FsRequest {
46+
static fn from_native_handle(handle: *uvll:: uv_fs_t) -> FsRequest {
47+
FsRequest(handle)
48+
}
49+
fn native_handle(&self) -> *uvll::uv_fs_t {
50+
match self { &FsRequest(ptr) => ptr }
51+
}
52+
}

0 commit comments

Comments
 (0)