Skip to content
This repository has been archived by the owner on Dec 8, 2023. It is now read-only.

Commit

Permalink
Rename async module to aio
Browse files Browse the repository at this point in the history
  • Loading branch information
sbstp committed May 19, 2019
1 parent d988803 commit 40842c6
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 50 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ rust:
script:
- cargo build
- cargo test
- cargo build --features async
- cargo test --features async
- cargo build --features aio
- cargo test --features aio
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ simplelog = "0.5.3"

[features]
default = []
async = ["futures", "tokio", "tokio-retry", "hyper"]
aio = ["futures", "tokio", "tokio-retry", "hyper"]

[[example]]
name = "add_any_port"
Expand All @@ -48,8 +48,8 @@ name = "add_port"
name = "add_remove"

[[example]]
name = "async"
required-features = ["async"]
name = "aio"
required-features = ["aio"]

[[example]]
name = "external_ip"
Expand Down
2 changes: 1 addition & 1 deletion examples/async.rs → examples/aio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ extern crate simplelog;
use std::env;
use std::net::SocketAddrV4;

use igd::async::{search_gateway, SearchOptions};
use igd::aio::{search_gateway, SearchOptions};
use igd::PortMappingProtocol;
use futures::future::Future;
use simplelog::{SimpleLogger, LevelFilter, Config as LogConfig};
Expand Down
File renamed without changes.
File renamed without changes.
12 changes: 6 additions & 6 deletions src/async/search.rs → src/aio/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use tokio::net::UdpSocket;

use bytes::Bytes;

use async::Gateway;
use aio::Gateway;
use common::{messages, parsing};
use errors::SearchError;

Expand Down Expand Up @@ -48,7 +48,7 @@ pub fn search_gateway(options: SearchOptions) -> impl Future<Item=Gateway, Error
let socket = match UdpSocket::bind(&options.bind_addr) {
Ok(s) => s,
Err(e) => return A(err(SearchError::from(e))),
};
};

// Create future and issue request
match options.timeout {
Expand Down Expand Up @@ -86,14 +86,14 @@ impl SearchFuture {
// Convert response to text
let text = str::from_utf8(&data)
.map_err(|e| SearchError::from(e))?;

// Parse socket address and path
let (addr, path) = parsing::parse_search_result(text)?;

Ok((SocketAddr::V4(addr), path))
}

// Issue a control URL request over HTTP using the provided
// Issue a control URL request over HTTP using the provided
fn request_control_url(addr: SocketAddr, path: String) -> Result<Box<Future<Item=Bytes, Error=SearchError> + Send>, SearchError> {
let client = Client::new();

Expand All @@ -103,7 +103,7 @@ impl SearchFuture {
};

debug!("requesting control url from: {}", uri);

Ok(Box::new(client.get(uri)
.and_then(|resp| resp.into_body().concat2() )
.map(|chunk| chunk.into_bytes() )
Expand Down Expand Up @@ -177,7 +177,7 @@ impl Future for SearchFuture {
}
_ => warn!("unsupported IPv6 gateway response from addr: {}", addr),
}

} else {
*state = SearchState::Error;
}
Expand Down
File renamed without changes.
62 changes: 31 additions & 31 deletions src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ use std::error;
use std::fmt;
use std::io;
use std::str;
#[cfg(feature = "async")]
#[cfg(feature = "aio")]
use std::string::FromUtf8Error;

use attohttpc;
#[cfg(feature = "async")]
#[cfg(feature = "aio")]
use hyper;

/// Errors that can occur when sending the request to the gateway.
Expand All @@ -21,15 +21,15 @@ pub enum RequestError {
InvalidResponse(String),
/// The gateway returned an unhandled error code and description.
ErrorCode(u16, String),
/// When using the async feature.
#[cfg(feature = "async")]
/// When using the aio feature.
#[cfg(feature = "aio")]
HyperError(hyper::Error),

#[cfg(feature = "async")]
#[cfg(feature = "aio")]
/// http crate error type
HttpError(http::Error),

#[cfg(feature = "async")]
#[cfg(feature = "aio")]
/// Error parsing HTTP body
Utf8Error(FromUtf8Error),
}
Expand All @@ -46,28 +46,28 @@ impl From<io::Error> for RequestError {
}
}

#[cfg(feature = "async")]
#[cfg(feature = "aio")]
impl From<http::Error> for RequestError {
fn from(err: http::Error) -> RequestError {
RequestError::HttpError(err)
}
}

#[cfg(feature = "async")]
#[cfg(feature = "aio")]
impl From<hyper::Error> for RequestError {
fn from(err: hyper::Error) -> RequestError {
RequestError::HyperError(err)
}
}

#[cfg(feature = "async")]
#[cfg(feature = "aio")]
impl From<FromUtf8Error> for RequestError {
fn from(err: FromUtf8Error) -> RequestError {
RequestError::Utf8Error(err)
}
}

#[cfg(feature = "async")]
#[cfg(feature = "aio")]
impl From<tokio::timer::Error> for RequestError {
fn from(_err: tokio::timer::Error) -> RequestError {
RequestError::IoError(io::Error::new(io::ErrorKind::TimedOut, "timer failed"))
Expand All @@ -81,11 +81,11 @@ impl fmt::Display for RequestError {
RequestError::InvalidResponse(ref e) => write!(f, "Invalid response from gateway: {}", e),
RequestError::IoError(ref e) => write!(f, "IO error. {}", e),
RequestError::ErrorCode(n, ref e) => write!(f, "Gateway response error {}: {}", n, e),
#[cfg(feature = "async")]
#[cfg(feature = "aio")]
RequestError::HyperError(ref e) => write!(f, "Hyper Error: {}", e),
#[cfg(feature = "async")]
#[cfg(feature = "aio")]
RequestError::HttpError(ref e) => write!(f, "Http Error: {}", e),
#[cfg(feature = "async")]
#[cfg(feature = "aio")]
RequestError::Utf8Error(ref e) => write!(f, "Utf8Error Error: {}", e),
}
}
Expand All @@ -98,11 +98,11 @@ impl std::error::Error for RequestError {
RequestError::InvalidResponse(..) => None,
RequestError::IoError(ref e) => Some(e),
RequestError::ErrorCode(..) => None,
#[cfg(feature = "async")]
#[cfg(feature = "aio")]
RequestError::HyperError(ref e) => Some(e),
#[cfg(feature = "async")]
#[cfg(feature = "aio")]
RequestError::HttpError(ref e) => Some(e),
#[cfg(feature = "async")]
#[cfg(feature = "aio")]
RequestError::Utf8Error(ref e) => Some(e),
}
}
Expand All @@ -113,11 +113,11 @@ impl std::error::Error for RequestError {
RequestError::InvalidResponse(..) => "Invalid response",
RequestError::IoError(..) => "IO error",
RequestError::ErrorCode(_, ref e) => &e[..],
#[cfg(feature = "async")]
#[cfg(feature = "aio")]
RequestError::HyperError(_) => "Hyper Error",
#[cfg(feature = "async")]
#[cfg(feature = "aio")]
RequestError::HttpError(_) => "Http Error",
#[cfg(feature = "async")]
#[cfg(feature = "aio")]
RequestError::Utf8Error(_) => "UTF8 Error",
}
}
Expand Down Expand Up @@ -374,11 +374,11 @@ pub enum SearchError {
Utf8Error(str::Utf8Error),
/// XML processing error
XmlError(xmltree::ParseError),
/// When using the async feature.
#[cfg(feature = "async")]
/// When using the aio feature.
#[cfg(feature = "aio")]
HyperError(hyper::Error),
/// Error parsing URI
#[cfg(feature = "async")]
#[cfg(feature = "aio")]
InvalidUri(hyper::http::uri::InvalidUri),
}

Expand Down Expand Up @@ -406,20 +406,20 @@ impl From<xmltree::ParseError> for SearchError {
}
}

#[cfg(feature = "async")]
#[cfg(feature = "aio")]
impl From<hyper::Error> for SearchError {
fn from(err: hyper::Error) -> SearchError {
SearchError::HyperError(err)
}
}

#[cfg(feature = "async")]
#[cfg(feature = "aio")]
impl From<hyper::http::uri::InvalidUri> for SearchError {
fn from(err: hyper::http::uri::InvalidUri) -> SearchError {
SearchError::InvalidUri(err)
}
}
#[cfg(feature = "async")]
#[cfg(feature = "aio")]
impl From<tokio::timer::timeout::Error<SearchError>> for SearchError {
fn from(err: tokio::timer::timeout::Error<SearchError>) -> SearchError {
if err.is_inner() {
Expand All @@ -438,9 +438,9 @@ impl fmt::Display for SearchError {
SearchError::IoError(ref e) => write!(f, "IO error: {}", e),
SearchError::Utf8Error(ref e) => write!(f, "UTF-8 error: {}", e),
SearchError::XmlError(ref e) => write!(f, "XML error: {}", e),
#[cfg(feature = "async")]
#[cfg(feature = "aio")]
SearchError::HyperError(ref e) => write!(f, "Hyper Error: {}", e),
#[cfg(feature = "async")]
#[cfg(feature = "aio")]
SearchError::InvalidUri(ref e) => write!(f, "InvalidUri Error: {}", e),
}
}
Expand All @@ -454,9 +454,9 @@ impl error::Error for SearchError {
SearchError::IoError(ref e) => Some(e),
SearchError::Utf8Error(ref e) => Some(e),
SearchError::XmlError(ref e) => Some(e),
#[cfg(feature = "async")]
#[cfg(feature = "aio")]
SearchError::HyperError(ref e) => Some(e),
#[cfg(feature = "async")]
#[cfg(feature = "aio")]
SearchError::InvalidUri(ref e) => Some(e),
}
}
Expand All @@ -468,9 +468,9 @@ impl error::Error for SearchError {
SearchError::IoError(..) => "IO error",
SearchError::Utf8Error(..) => "UTF-8 error",
SearchError::XmlError(..) => "XML error",
#[cfg(feature = "async")]
#[cfg(feature = "aio")]
SearchError::HyperError(..) => "Hyper Error",
#[cfg(feature = "async")]
#[cfg(feature = "aio")]
SearchError::InvalidUri(_) => "Invalid URI Error"
}
}
Expand Down
15 changes: 8 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
//! You can then communicate with the device via this object.

extern crate attohttpc;
#[cfg(feature = "aio")]
#[macro_use]
extern crate log;
extern crate bytes;
Expand All @@ -13,15 +14,15 @@ extern crate rand;
extern crate url;
extern crate xmltree;

#[cfg(feature = "async")]
#[cfg(feature = "aio")]
extern crate http;
#[cfg(feature = "async")]
#[cfg(feature = "aio")]
extern crate futures;
#[cfg(feature = "async")]
#[cfg(feature = "aio")]
extern crate hyper;
#[cfg(feature = "async")]
#[cfg(feature = "aio")]
extern crate tokio;
#[cfg(feature = "async")]
#[cfg(feature = "aio")]
extern crate tokio_retry;

// data structures
Expand All @@ -34,8 +35,8 @@ pub use self::search::search_gateway_from;
pub use self::search::search_gateway_from_timeout;
pub use self::search::search_gateway_timeout;

#[cfg(feature = "async")]
pub mod async;
#[cfg(feature = "aio")]
pub mod aio;
mod common;
mod errors;
mod gateway;
Expand Down

0 comments on commit 40842c6

Please sign in to comment.