-
Notifications
You must be signed in to change notification settings - Fork 708
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
broke io::read/write out into non-buffering and buffering solutions #51
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
Cargo.lock | ||
target | ||
libs | ||
.*.sw* |
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,171 @@ | ||
use std::fmt; | ||
use token::Token; | ||
use handler::{ReadHint, DATAHINT, HUPHINT, ERRORHINT}; | ||
|
||
|
||
bitflags!( | ||
flags IoEventKind: uint { | ||
const IOREADABLE = 0x001, | ||
const IOWRITABLE = 0x002, | ||
const IOERROR = 0x004, | ||
const IOHUPHINT = 0x008, | ||
const IOHINTED = 0x010, | ||
const IOONESHOT = 0x020, | ||
const IOEDGE = 0x040, | ||
const IOLEVEL = 0x080, | ||
const IOALL = 0x001 | 0x002 | 0x004 | 0x008 | ||
} | ||
) | ||
|
||
impl fmt::Show for IoEventKind { | ||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { | ||
let mut one = false; | ||
let flags = [ | ||
(IOREADABLE, "IoReadable"), | ||
(IOWRITABLE, "IoWritable"), | ||
(IOERROR, "IoError"), | ||
(IOHUPHINT, "IoHupHint"), | ||
(IOHINTED, "IoHinted"), | ||
(IOEDGE, "IoEdgeTriggered")]; | ||
|
||
for &(flag, msg) in flags.iter() { | ||
if self.contains(flag) { | ||
if one { try!(write!(fmt, " | ")) } | ||
try!(write!(fmt, "{}", msg)); | ||
|
||
one = true | ||
} | ||
} | ||
|
||
Ok(()) | ||
} | ||
} | ||
|
||
#[deriving(Show)] | ||
pub struct IoEventCtx { | ||
kind: IoEventKind, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There seems to be some spacing issues |
||
token: Token | ||
} | ||
|
||
/// IoEventCtx represents the raw event upon which the OS-specific selector | ||
/// operates. It takes an IoEventCtx when registering and re-registering event | ||
/// interest for Tokens. It also returns IoEventCtx when calling handlers. | ||
/// An event can represent more than one kind (such as readable or writable) at a time. | ||
/// | ||
/// These IoEventCtx objects are created by the OS-specific concrete | ||
/// Selector when they have events to report. | ||
impl IoEventCtx { | ||
/// Create a new IoEvent. | ||
pub fn new(kind: IoEventKind, token: Token) -> IoEventCtx { | ||
IoEventCtx { | ||
kind: kind, | ||
token: token | ||
} | ||
} | ||
|
||
pub fn token(&self) -> Token { | ||
self.token | ||
} | ||
|
||
/// Return an optional hint for a readable IO handle. Currently, | ||
/// this method supports the HupHint, which indicates that the | ||
/// kernel reported that the remote side hung up. This allows a | ||
/// consumer to avoid reading in order to discover the hangup. | ||
pub fn read_hint(&self) -> ReadHint { | ||
let mut hint = ReadHint::empty(); | ||
|
||
// The backend doesn't support hinting | ||
if !self.kind.contains(IOHINTED) { | ||
return hint; | ||
} | ||
|
||
if self.kind.contains(IOHUPHINT) { | ||
hint = hint | HUPHINT | ||
} | ||
|
||
if self.kind.contains(IOREADABLE) { | ||
hint = hint | DATAHINT | ||
} | ||
|
||
if self.kind.contains(IOERROR) { | ||
hint = hint | ERRORHINT | ||
} | ||
|
||
hint | ||
} | ||
|
||
/// This event indicated that the IO handle is now readable | ||
pub fn is_readable(&self) -> bool { | ||
self.kind.contains(IOREADABLE) || self.kind.contains(IOHUPHINT) | ||
} | ||
|
||
/// This event indicated that the IO handle is now writable | ||
pub fn is_writable(&self) -> bool { | ||
self.kind.contains(IOWRITABLE) | ||
} | ||
|
||
/// This event indicated that the IO handle had an error | ||
pub fn is_error(&self) -> bool { | ||
self.kind.contains(IOERROR) | ||
} | ||
|
||
pub fn is_hangup(&self) -> bool { | ||
self.kind.contains(IOHUPHINT) | ||
} | ||
|
||
pub fn is_edge_triggered(&self) -> bool { | ||
self.kind.contains(IOEDGE) | ||
} | ||
|
||
/// This event indicated that the IO handle is now readable | ||
pub fn set_readable(&mut self, flag: bool) -> &IoEventCtx { | ||
match flag { | ||
true => self.kind.insert(IOREADABLE), | ||
false => self.kind.remove(IOREADABLE) | ||
} | ||
return self; | ||
} | ||
|
||
/// This event indicated that the IO handle is now writable | ||
pub fn set_writable(&mut self, flag: bool) -> &IoEventCtx { | ||
match flag { | ||
true => self.kind.insert(IOWRITABLE), | ||
false => self.kind.remove(IOWRITABLE) | ||
} | ||
return self; | ||
} | ||
|
||
/// This event indicated that the IO handle had an error | ||
pub fn set_error(&mut self, flag: bool) -> &IoEventCtx { | ||
match flag { | ||
true => self.kind.insert(IOERROR), | ||
false => self.kind.remove(IOERROR) | ||
} | ||
return self; | ||
} | ||
|
||
pub fn set_hangup(&mut self, flag: bool) -> &IoEventCtx { | ||
match flag { | ||
true => self.kind.insert(IOHUPHINT), | ||
false => self.kind.remove(IOHUPHINT) | ||
} | ||
return self; | ||
} | ||
|
||
pub fn set_edge_triggered(&mut self, flag: bool) -> &IoEventCtx { | ||
match flag { | ||
true => self.kind.insert(IOEDGE), | ||
false => self.kind.remove(IOEDGE) | ||
} | ||
return self; | ||
} | ||
|
||
pub fn set_all(&mut self, flag: bool) -> &IoEventCtx { | ||
match flag { | ||
true => self.kind.insert(IOALL), | ||
false => self.kind.remove(IOALL) | ||
} | ||
return self; | ||
} | ||
} | ||
|
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I pulled this in on master already.