mirror of
https://github.com/servo/servo.git
synced 2025-08-04 13:10:20 +01:00
Document async networking interfaces.
This commit is contained in:
parent
1ca9ff56c8
commit
1b9684634f
2 changed files with 16 additions and 0 deletions
|
@ -35,6 +35,7 @@ use std::thunk::Invoke;
|
||||||
static mut HOST_TABLE: Option<*mut HashMap<String, String>> = None;
|
static mut HOST_TABLE: Option<*mut HashMap<String, String>> = None;
|
||||||
|
|
||||||
pub fn global_init() {
|
pub fn global_init() {
|
||||||
|
<<<<<<< HEAD
|
||||||
//TODO: handle bad file path
|
//TODO: handle bad file path
|
||||||
let path = match env::var("HOST_FILE") {
|
let path = match env::var("HOST_FILE") {
|
||||||
Ok(host_file_path) => host_file_path,
|
Ok(host_file_path) => host_file_path,
|
||||||
|
|
|
@ -66,19 +66,31 @@ impl LoadData {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A listener for asynchronous network events. Cancelling the underlying request is unsupported.
|
||||||
pub trait AsyncResponseListener {
|
pub trait AsyncResponseListener {
|
||||||
|
/// The response headers for a request have been received.
|
||||||
fn headers_available(&self, metadata: Metadata);
|
fn headers_available(&self, metadata: Metadata);
|
||||||
|
/// A portion of the response body has been received. This data is unavailable after
|
||||||
|
/// this method returned, and must be stored accordingly.
|
||||||
fn data_available(&self, payload: Vec<u8>);
|
fn data_available(&self, payload: Vec<u8>);
|
||||||
|
/// The response is complete. If the provided status is an Err value, there is no guarantee
|
||||||
|
/// that the response body was completely read.
|
||||||
fn response_complete(&self, status: Result<(), String>);
|
fn response_complete(&self, status: Result<(), String>);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Data for passing between threads/processes to indicate a particular action to
|
||||||
|
/// take on a provided network listener.
|
||||||
pub enum ResponseAction {
|
pub enum ResponseAction {
|
||||||
|
/// Invoke headers_available
|
||||||
HeadersAvailable(Metadata),
|
HeadersAvailable(Metadata),
|
||||||
|
/// Invoke data_available
|
||||||
DataAvailable(Vec<u8>),
|
DataAvailable(Vec<u8>),
|
||||||
|
/// Invoke response_complete
|
||||||
ResponseComplete(Result<(), String>)
|
ResponseComplete(Result<(), String>)
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ResponseAction {
|
impl ResponseAction {
|
||||||
|
/// Execute the default action on a provided listener.
|
||||||
pub fn process(self, listener: &AsyncResponseListener) {
|
pub fn process(self, listener: &AsyncResponseListener) {
|
||||||
match self {
|
match self {
|
||||||
ResponseAction::HeadersAvailable(m) => listener.headers_available(m),
|
ResponseAction::HeadersAvailable(m) => listener.headers_available(m),
|
||||||
|
@ -88,10 +100,13 @@ impl ResponseAction {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A target for async networking events. Commonly used to dispatch a runnable event to another
|
||||||
|
/// thread storing the wrapped closure for later execution.
|
||||||
pub trait AsyncResponseTarget {
|
pub trait AsyncResponseTarget {
|
||||||
fn invoke_with_listener(&self, action: ResponseAction);
|
fn invoke_with_listener(&self, action: ResponseAction);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A wrapper for a network load that can either be channel or event-based.
|
||||||
pub enum LoadConsumer {
|
pub enum LoadConsumer {
|
||||||
Channel(Sender<LoadResponse>),
|
Channel(Sender<LoadResponse>),
|
||||||
Listener(Box<AsyncResponseTarget + Send>),
|
Listener(Box<AsyncResponseTarget + Send>),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue