-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
📝 restructure unit fs directory (#52)
- Loading branch information
1 parent
76992c9
commit d0710f4
Showing
10 changed files
with
107 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
mod aio_bindings; | ||
mod fs_read; | ||
mod fs_write; | ||
|
||
pub use self::fs_read::FileRead; | ||
pub use self::fs_write::FileWrite; | ||
|
||
use std::fs::File; | ||
use std::io; | ||
use std::os::unix::io::{AsRawFd, RawFd}; | ||
|
||
use self::aio_bindings::EFD_NONBLOCK; | ||
use io::sys::IoData; | ||
|
||
pub struct EventFd(RawFd); | ||
|
||
impl AsRawFd for EventFd { | ||
fn as_raw_fd(&self) -> RawFd { | ||
self.0 | ||
} | ||
} | ||
|
||
pub struct FileIo { | ||
pub fd: EventFd, | ||
pub io: IoData, | ||
} | ||
|
||
impl Drop for FileIo { | ||
// drop the EventFd first | ||
fn drop(&mut self) { | ||
use nix::unistd::close; | ||
if self.fd.0 >= 0 { | ||
close(self.fd.0).ok(); | ||
} | ||
} | ||
} | ||
|
||
impl ::std::ops::Deref for FileIo { | ||
type Target = IoData; | ||
fn deref(&self) -> &IoData { | ||
&self.io | ||
} | ||
} | ||
|
||
pub trait AsFileIo { | ||
fn as_file_io(&self) -> &FileIo; | ||
} | ||
|
||
impl FileIo { | ||
pub fn new(file: Option<&File>) -> io::Result<FileIo> { | ||
use libc::{eventfd, O_CLOEXEC}; | ||
if file.is_some() { | ||
let flags = { O_CLOEXEC | EFD_NONBLOCK as i32 }; | ||
|
||
let fd = unsafe { eventfd(0, flags) }; | ||
|
||
if fd < 0 { | ||
return Err(io::Error::last_os_error()); | ||
} | ||
let ev_fd = EventFd(fd); | ||
let io = crate::io::sys::add_file(&ev_fd)?; | ||
Ok(FileIo { io, fd: ev_fd }) | ||
} else { | ||
// don't close any fd, dummy one | ||
let fd = EventFd(-1); | ||
Ok(FileIo { | ||
io: IoData::new(&fd), | ||
fd, | ||
}) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters