|
| 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