From 517d5c7434a2804d46582a427d4d7fc1ca732b35 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Tue, 9 Aug 2016 15:05:25 -0700 Subject: [PATCH] Add libcurl bindings --- src/event_loop.rs | 19 +++++++++++++++++++ src/lib.rs | 2 +- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/event_loop.rs b/src/event_loop.rs index fb145e9c3..9e46523db 100644 --- a/src/event_loop.rs +++ b/src/event_loop.rs @@ -95,11 +95,13 @@ enum Message { Shutdown, } +/// Type of I/O objects inserted into the event loop, created by `Source::new`. pub struct Source { readiness: AtomicUsize, io: E, } +/// I/O objects inserted into the event loop pub type IoSource = Arc>; fn register(poll: &mio::Poll, @@ -745,6 +747,11 @@ impl LoopData { pub fn executor(&self) -> Arc { self.handle.tx.clone() } + + /// Returns a reference to the handle that this data is bound to. + pub fn loop_handle(&self) -> &LoopHandle { + &self.handle + } } impl Drop for LoopData { @@ -1000,6 +1007,7 @@ impl TimeoutState { } impl Source { + /// Creates a new `Source` wrapping the provided source of events. pub fn new(e: E) -> Source { Source { readiness: AtomicUsize::new(0), @@ -1009,6 +1017,16 @@ impl Source { } impl Source { + /// Consumes the last readiness notification that this source received. + /// + /// Currently sources receive readiness notifications on an edge-basis. That + /// is, once you receive a notification that an object can be read, you + /// won't receive any more notifications until all of that data has been + /// read. + /// + /// The event loop will fill in this information and then inform futures + /// that they're ready to go with the `schedule` method, and then the `poll` + /// method can use this to figure out what happened. pub fn take_readiness(&self) -> Option { match self.readiness.swap(0, Ordering::SeqCst) { 0 => None, @@ -1019,6 +1037,7 @@ impl Source { } } + /// Gets access to the underlying I/O object. pub fn io(&self) -> &E { &self.io } diff --git a/src/lib.rs b/src/lib.rs index b545ce6a0..066e20c9b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -30,7 +30,7 @@ mod mpsc_queue; mod channel; pub use event_loop::{Loop, LoopHandle, AddSource, AddTimeout}; -pub use event_loop::{LoopData, AddLoopData, TimeoutToken}; +pub use event_loop::{LoopData, AddLoopData, TimeoutToken, IoSource, Source}; pub use readiness_stream::ReadinessStream; pub use tcp::{TcpListener, TcpStream}; pub use timeout::Timeout;