mirror of
https://github.com/fafhrd91/actix-net
synced 2025-08-14 10:00:31 +02:00
Compare commits
6 Commits
rt-0.2.2
...
router-v0.
Author | SHA1 | Date | |
---|---|---|---|
|
629ed05f82 | ||
|
5e8ae210f7 | ||
|
3add90628f | ||
|
02ab804e0b | ||
|
feac0b43d9 | ||
|
1441355d4f |
@@ -1,5 +1,12 @@
|
|||||||
# Changes
|
# Changes
|
||||||
|
|
||||||
|
## [0.1.2] - 2019-04-xx
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
* Rename connect Connector to TcpConnector #10
|
||||||
|
|
||||||
|
|
||||||
## [0.1.1] - 2019-03-15
|
## [0.1.1] - 2019-03-15
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "actix-connect"
|
name = "actix-connect"
|
||||||
version = "0.1.1"
|
version = "0.1.2"
|
||||||
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
|
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
|
||||||
description = "Actix Connector - tcp connector service"
|
description = "Actix Connector - tcp connector service"
|
||||||
keywords = ["network", "framework", "async", "futures"]
|
keywords = ["network", "framework", "async", "futures"]
|
||||||
|
@@ -12,54 +12,54 @@ use super::error::ConnectError;
|
|||||||
|
|
||||||
/// Tcp connector service factory
|
/// Tcp connector service factory
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct ConnectorFactory<T>(PhantomData<T>);
|
pub struct TcpConnectorFactory<T>(PhantomData<T>);
|
||||||
|
|
||||||
impl<T> ConnectorFactory<T> {
|
impl<T> TcpConnectorFactory<T> {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
ConnectorFactory(PhantomData)
|
TcpConnectorFactory(PhantomData)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> Clone for ConnectorFactory<T> {
|
impl<T> Clone for TcpConnectorFactory<T> {
|
||||||
fn clone(&self) -> Self {
|
fn clone(&self) -> Self {
|
||||||
ConnectorFactory(PhantomData)
|
TcpConnectorFactory(PhantomData)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Address> NewService for ConnectorFactory<T> {
|
impl<T: Address> NewService for TcpConnectorFactory<T> {
|
||||||
type Request = Connect<T>;
|
type Request = Connect<T>;
|
||||||
type Response = Connection<T, TcpStream>;
|
type Response = Connection<T, TcpStream>;
|
||||||
type Error = ConnectError;
|
type Error = ConnectError;
|
||||||
type Service = Connector<T>;
|
type Service = TcpConnector<T>;
|
||||||
type InitError = ();
|
type InitError = ();
|
||||||
type Future = FutureResult<Self::Service, Self::InitError>;
|
type Future = FutureResult<Self::Service, Self::InitError>;
|
||||||
|
|
||||||
fn new_service(&self, _: &()) -> Self::Future {
|
fn new_service(&self, _: &()) -> Self::Future {
|
||||||
ok(Connector(PhantomData))
|
ok(TcpConnector(PhantomData))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Tcp connector service
|
/// Tcp connector service
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Connector<T>(PhantomData<T>);
|
pub struct TcpConnector<T>(PhantomData<T>);
|
||||||
|
|
||||||
impl<T> Connector<T> {
|
impl<T> TcpConnector<T> {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Connector(PhantomData)
|
TcpConnector(PhantomData)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> Clone for Connector<T> {
|
impl<T> Clone for TcpConnector<T> {
|
||||||
fn clone(&self) -> Self {
|
fn clone(&self) -> Self {
|
||||||
Connector(PhantomData)
|
TcpConnector(PhantomData)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Address> Service for Connector<T> {
|
impl<T: Address> Service for TcpConnector<T> {
|
||||||
type Request = Connect<T>;
|
type Request = Connect<T>;
|
||||||
type Response = Connection<T, TcpStream>;
|
type Response = Connection<T, TcpStream>;
|
||||||
type Error = ConnectError;
|
type Error = ConnectError;
|
||||||
type Future = Either<ConnectorResponse<T>, FutureResult<Self::Response, Self::Error>>;
|
type Future = Either<TcpConnectorResponse<T>, FutureResult<Self::Response, Self::Error>>;
|
||||||
|
|
||||||
fn poll_ready(&mut self) -> Poll<(), Self::Error> {
|
fn poll_ready(&mut self) -> Poll<(), Self::Error> {
|
||||||
Ok(Async::Ready(()))
|
Ok(Async::Ready(()))
|
||||||
@@ -70,7 +70,7 @@ impl<T: Address> Service for Connector<T> {
|
|||||||
let Connect { req, addr, .. } = req;
|
let Connect { req, addr, .. } = req;
|
||||||
|
|
||||||
if let Some(addr) = addr {
|
if let Some(addr) = addr {
|
||||||
Either::A(ConnectorResponse::new(req, port, addr))
|
Either::A(TcpConnectorResponse::new(req, port, addr))
|
||||||
} else {
|
} else {
|
||||||
error!("TCP connector: got unresolved address");
|
error!("TCP connector: got unresolved address");
|
||||||
Either::B(err(ConnectError::Unresolverd))
|
Either::B(err(ConnectError::Unresolverd))
|
||||||
@@ -80,19 +80,19 @@ impl<T: Address> Service for Connector<T> {
|
|||||||
|
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
/// Tcp stream connector response future
|
/// Tcp stream connector response future
|
||||||
pub struct ConnectorResponse<T> {
|
pub struct TcpConnectorResponse<T> {
|
||||||
req: Option<T>,
|
req: Option<T>,
|
||||||
port: u16,
|
port: u16,
|
||||||
addrs: Option<VecDeque<SocketAddr>>,
|
addrs: Option<VecDeque<SocketAddr>>,
|
||||||
stream: Option<ConnectFuture>,
|
stream: Option<ConnectFuture>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Address> ConnectorResponse<T> {
|
impl<T: Address> TcpConnectorResponse<T> {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
req: T,
|
req: T,
|
||||||
port: u16,
|
port: u16,
|
||||||
addr: either::Either<SocketAddr, VecDeque<SocketAddr>>,
|
addr: either::Either<SocketAddr, VecDeque<SocketAddr>>,
|
||||||
) -> ConnectorResponse<T> {
|
) -> TcpConnectorResponse<T> {
|
||||||
trace!(
|
trace!(
|
||||||
"TCP connector - connecting to {:?} port:{}",
|
"TCP connector - connecting to {:?} port:{}",
|
||||||
req.host(),
|
req.host(),
|
||||||
@@ -100,13 +100,13 @@ impl<T: Address> ConnectorResponse<T> {
|
|||||||
);
|
);
|
||||||
|
|
||||||
match addr {
|
match addr {
|
||||||
either::Either::Left(addr) => ConnectorResponse {
|
either::Either::Left(addr) => TcpConnectorResponse {
|
||||||
req: Some(req),
|
req: Some(req),
|
||||||
port,
|
port,
|
||||||
addrs: None,
|
addrs: None,
|
||||||
stream: Some(TcpStream::connect(&addr)),
|
stream: Some(TcpStream::connect(&addr)),
|
||||||
},
|
},
|
||||||
either::Either::Right(addrs) => ConnectorResponse {
|
either::Either::Right(addrs) => TcpConnectorResponse {
|
||||||
req: Some(req),
|
req: Some(req),
|
||||||
port,
|
port,
|
||||||
addrs: Some(addrs),
|
addrs: Some(addrs),
|
||||||
@@ -116,7 +116,7 @@ impl<T: Address> ConnectorResponse<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Address> Future for ConnectorResponse<T> {
|
impl<T: Address> Future for TcpConnectorResponse<T> {
|
||||||
type Item = Connection<T, TcpStream>;
|
type Item = Connection<T, TcpStream>;
|
||||||
type Error = ConnectError;
|
type Error = ConnectError;
|
||||||
|
|
||||||
|
@@ -20,7 +20,7 @@ mod uri;
|
|||||||
pub use trust_dns_resolver::{error::ResolveError, AsyncResolver};
|
pub use trust_dns_resolver::{error::ResolveError, AsyncResolver};
|
||||||
|
|
||||||
pub use self::connect::{Address, Connect, Connection};
|
pub use self::connect::{Address, Connect, Connection};
|
||||||
pub use self::connector::{Connector, ConnectorFactory};
|
pub use self::connector::{TcpConnector, TcpConnectorFactory};
|
||||||
pub use self::error::ConnectError;
|
pub use self::error::ConnectError;
|
||||||
pub use self::resolver::{Resolver, ResolverFactory};
|
pub use self::resolver::{Resolver, ResolverFactory};
|
||||||
|
|
||||||
@@ -29,6 +29,17 @@ use tokio_tcp::TcpStream;
|
|||||||
use trust_dns_resolver::config::{ResolverConfig, ResolverOpts};
|
use trust_dns_resolver::config::{ResolverConfig, ResolverOpts};
|
||||||
use trust_dns_resolver::system_conf::read_system_conf;
|
use trust_dns_resolver::system_conf::read_system_conf;
|
||||||
|
|
||||||
|
#[doc(hidden)]
|
||||||
|
#[deprecated(since = "0.1.2", note = "please use `actix_connect::TcpConnector`")]
|
||||||
|
pub type Connector<T> = TcpConnector<T>;
|
||||||
|
|
||||||
|
#[doc(hidden)]
|
||||||
|
#[deprecated(
|
||||||
|
since = "0.1.2",
|
||||||
|
note = "please use `actix_connect::TcpConnectorFactory`"
|
||||||
|
)]
|
||||||
|
pub type ConnectorFactory<T> = TcpConnectorFactory<T>;
|
||||||
|
|
||||||
pub fn start_resolver(cfg: ResolverConfig, opts: ResolverOpts) -> AsyncResolver {
|
pub fn start_resolver(cfg: ResolverConfig, opts: ResolverOpts) -> AsyncResolver {
|
||||||
let (resolver, bg) = AsyncResolver::new(cfg, opts);
|
let (resolver, bg) = AsyncResolver::new(cfg, opts);
|
||||||
tokio_current_thread::spawn(bg);
|
tokio_current_thread::spawn(bg);
|
||||||
@@ -52,7 +63,7 @@ pub fn new_connector<T: Address>(
|
|||||||
resolver: AsyncResolver,
|
resolver: AsyncResolver,
|
||||||
) -> impl Service<Request = Connect<T>, Response = Connection<T, TcpStream>, Error = ConnectError>
|
) -> impl Service<Request = Connect<T>, Response = Connection<T, TcpStream>, Error = ConnectError>
|
||||||
+ Clone {
|
+ Clone {
|
||||||
Resolver::new(resolver).and_then(Connector::new())
|
Resolver::new(resolver).and_then(TcpConnector::new())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create tcp connector service
|
/// Create tcp connector service
|
||||||
@@ -64,14 +75,14 @@ pub fn new_connector_factory<T: Address>(
|
|||||||
Error = ConnectError,
|
Error = ConnectError,
|
||||||
InitError = (),
|
InitError = (),
|
||||||
> + Clone {
|
> + Clone {
|
||||||
ResolverFactory::new(resolver).and_then(ConnectorFactory::new())
|
ResolverFactory::new(resolver).and_then(TcpConnectorFactory::new())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create connector service with default parameters
|
/// Create connector service with default parameters
|
||||||
pub fn default_connector<T: Address>(
|
pub fn default_connector<T: Address>(
|
||||||
) -> impl Service<Request = Connect<T>, Response = Connection<T, TcpStream>, Error = ConnectError>
|
) -> impl Service<Request = Connect<T>, Response = Connection<T, TcpStream>, Error = ConnectError>
|
||||||
+ Clone {
|
+ Clone {
|
||||||
Resolver::new(start_default_resolver()).and_then(Connector::new())
|
Resolver::new(start_default_resolver()).and_then(TcpConnector::new())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create connector service factory with default parameters
|
/// Create connector service factory with default parameters
|
||||||
@@ -81,5 +92,5 @@ pub fn default_connector_factory<T: Address>() -> impl NewService<
|
|||||||
Error = ConnectError,
|
Error = ConnectError,
|
||||||
InitError = (),
|
InitError = (),
|
||||||
> + Clone {
|
> + Clone {
|
||||||
ResolverFactory::new(start_default_resolver()).and_then(ConnectorFactory::new())
|
ResolverFactory::new(start_default_resolver()).and_then(TcpConnectorFactory::new())
|
||||||
}
|
}
|
||||||
|
@@ -18,7 +18,7 @@ name = "actix_rt"
|
|||||||
path = "src/lib.rs"
|
path = "src/lib.rs"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
actix-threadpool = { path="../actix-threadpool" }
|
actix-threadpool = "0.1.0"
|
||||||
futures = "0.1.25"
|
futures = "0.1.25"
|
||||||
tokio-current-thread = "0.1"
|
tokio-current-thread = "0.1"
|
||||||
tokio-executor = "0.1.5"
|
tokio-executor = "0.1.5"
|
||||||
|
@@ -1,5 +1,12 @@
|
|||||||
# Changes
|
# Changes
|
||||||
|
|
||||||
|
## [0.4.2] - 2019-03-30
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
* Fix SIGINT force shutdown
|
||||||
|
|
||||||
|
|
||||||
## [0.4.1] - 2019-03-14
|
## [0.4.1] - 2019-03-14
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "actix-server"
|
name = "actix-server"
|
||||||
version = "0.4.1"
|
version = "0.4.2"
|
||||||
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
|
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
|
||||||
description = "Actix server - General purpose tcp server"
|
description = "Actix server - General purpose tcp server"
|
||||||
keywords = ["network", "framework", "async", "futures"]
|
keywords = ["network", "framework", "async", "futures"]
|
||||||
|
@@ -328,7 +328,7 @@ impl ServerBuilder {
|
|||||||
self.accept.send(Command::Stop);
|
self.accept.send(Command::Stop);
|
||||||
|
|
||||||
// stop workers
|
// stop workers
|
||||||
if !self.workers.is_empty() {
|
if !self.workers.is_empty() && graceful {
|
||||||
spawn(
|
spawn(
|
||||||
futures_unordered(
|
futures_unordered(
|
||||||
self.workers
|
self.workers
|
||||||
|
@@ -1,5 +1,12 @@
|
|||||||
# Changes
|
# Changes
|
||||||
|
|
||||||
|
## [0.3.5] - 2019-03-29
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
* Add `impl<S: Service> Service for Rc<RefCell<S>>`
|
||||||
|
|
||||||
|
|
||||||
## [0.3.4] - 2019-03-12
|
## [0.3.4] - 2019-03-12
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "actix-service"
|
name = "actix-service"
|
||||||
version = "0.3.4"
|
version = "0.3.5"
|
||||||
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
|
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
|
||||||
description = "Actix Service"
|
description = "Actix Service"
|
||||||
keywords = ["network", "framework", "async", "futures"]
|
keywords = ["network", "framework", "async", "futures"]
|
||||||
|
@@ -1,3 +1,4 @@
|
|||||||
|
use std::cell::RefCell;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
@@ -391,6 +392,24 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<S> Service for Rc<RefCell<S>>
|
||||||
|
where
|
||||||
|
S: Service,
|
||||||
|
{
|
||||||
|
type Request = S::Request;
|
||||||
|
type Response = S::Response;
|
||||||
|
type Error = S::Error;
|
||||||
|
type Future = S::Future;
|
||||||
|
|
||||||
|
fn poll_ready(&mut self) -> Poll<(), S::Error> {
|
||||||
|
self.borrow_mut().poll_ready()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn call(&mut self, request: Self::Request) -> S::Future {
|
||||||
|
self.borrow_mut().call(request)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<S, C> NewService<C> for Rc<S>
|
impl<S, C> NewService<C> for Rc<S>
|
||||||
where
|
where
|
||||||
S: NewService<C>,
|
S: NewService<C>,
|
||||||
|
@@ -1,5 +1,9 @@
|
|||||||
# Changes
|
# Changes
|
||||||
|
|
||||||
|
## [0.1.1] - 2019-04-03
|
||||||
|
|
||||||
|
* Get dynamic segment by name instead of iterator.
|
||||||
|
|
||||||
## [0.1.0] - 2019-03-09
|
## [0.1.0] - 2019-03-09
|
||||||
|
|
||||||
* Initial release
|
* Initial release
|
||||||
|
@@ -1,16 +1,16 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "actix-router"
|
name = "actix-router"
|
||||||
version = "0.1.0"
|
version = "0.1.1"
|
||||||
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
|
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
|
||||||
description = "Path router"
|
description = "Path router"
|
||||||
keywords = ["actix"]
|
keywords = ["actix"]
|
||||||
homepage = "https://actix.rs"
|
homepage = "https://actix.rs"
|
||||||
repository = "https://github.com/actix/actix-net.git"
|
repository = "https://github.com/actix/actix-net.git"
|
||||||
documentation = "https://actix.rs/api/actix-net/stable/actix_router/"
|
documentation = "https://docs.rs/actix-router/"
|
||||||
license = "MIT/Apache-2.0"
|
license = "MIT/Apache-2.0"
|
||||||
exclude = [".gitignore", ".travis.yml", ".cargo/config", "appveyor.yml"]
|
exclude = [".gitignore", ".travis.yml", ".cargo/config", "appveyor.yml"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
workspace = "../"
|
workspace = ".."
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
name = "actix_router"
|
name = "actix_router"
|
||||||
@@ -23,7 +23,8 @@ default = ["http"]
|
|||||||
bytes = "0.4"
|
bytes = "0.4"
|
||||||
regex = "1.0"
|
regex = "1.0"
|
||||||
serde = "1.0.80"
|
serde = "1.0.80"
|
||||||
string = "0.1.3"
|
string = "0.2.0"
|
||||||
|
log = "0.4"
|
||||||
http = { version="0.1.14", optional=true }
|
http = { version="0.1.14", optional=true }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
|
@@ -196,18 +196,17 @@ impl ResourceDef {
|
|||||||
[PathItem::Static(""); MAX_DYNAMIC_SEGMENTS];
|
[PathItem::Static(""); MAX_DYNAMIC_SEGMENTS];
|
||||||
|
|
||||||
if let Some(captures) = re.captures(path.path()) {
|
if let Some(captures) = re.captures(path.path()) {
|
||||||
let mut passed = false;
|
for (no, name) in names.iter().enumerate() {
|
||||||
|
if let Some(m) = captures.name(&name) {
|
||||||
for capture in captures.iter() {
|
|
||||||
if let Some(ref m) = capture {
|
|
||||||
if !passed {
|
|
||||||
passed = true;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
segments[idx] = PathItem::Segment(m.start() as u16, m.end() as u16);
|
|
||||||
idx += 1;
|
idx += 1;
|
||||||
pos = m.end();
|
pos = m.end();
|
||||||
|
segments[no] = PathItem::Segment(m.start() as u16, m.end() as u16);
|
||||||
|
} else {
|
||||||
|
log::error!(
|
||||||
|
"Dynamic path match but not all segments found: {}",
|
||||||
|
name
|
||||||
|
);
|
||||||
|
false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
Reference in New Issue
Block a user