mirror of
https://github.com/fafhrd91/actix-net
synced 2025-08-15 18:03:53 +02:00
Compare commits
19 Commits
utils-v0.4
...
rt-0.2.3
Author | SHA1 | Date | |
---|---|---|---|
|
07708c5e9a | ||
|
1c04ad3238 | ||
|
66aa21740c | ||
|
b183cb3324 | ||
|
158482cd2f | ||
|
9e61f62871 | ||
|
7051888289 | ||
|
0caa47fc47 | ||
|
6d1cbb2d2f | ||
|
ca289ddf7f | ||
|
ad9a197916 | ||
|
c4f05e033f | ||
|
048314913c | ||
|
c1b183e1ce | ||
|
87bc3dacd9 | ||
|
0156f479a0 | ||
|
139fa3b9a2 | ||
|
a14f612382 | ||
|
059e2ad042 |
1
actix-codec/LICENSE-APACHE
Symbolic link
1
actix-codec/LICENSE-APACHE
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
../LICENSE-APACHE
|
1
actix-codec/LICENSE-MIT
Symbolic link
1
actix-codec/LICENSE-MIT
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
../LICENSE-MIT
|
@@ -1,5 +1,9 @@
|
|||||||
# Changes
|
# Changes
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
* Update `derive_more` to 0.15
|
||||||
|
|
||||||
## [0.2.0] - 2019-05-12
|
## [0.2.0] - 2019-05-12
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
@@ -33,7 +33,7 @@ uri = ["http"]
|
|||||||
actix-service = "0.4.0"
|
actix-service = "0.4.0"
|
||||||
actix-codec = "0.1.2"
|
actix-codec = "0.1.2"
|
||||||
actix-utils = "0.4.0"
|
actix-utils = "0.4.0"
|
||||||
derive_more = "0.14.0"
|
derive_more = "0.15"
|
||||||
either = "1.5.2"
|
either = "1.5.2"
|
||||||
futures = "0.1.25"
|
futures = "0.1.25"
|
||||||
http = { version = "0.1.17", optional = true }
|
http = { version = "0.1.17", optional = true }
|
||||||
|
1
actix-connect/LICENSE-APACHE
Symbolic link
1
actix-connect/LICENSE-APACHE
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
../LICENSE-APACHE
|
1
actix-connect/LICENSE-MIT
Symbolic link
1
actix-connect/LICENSE-MIT
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
../LICENSE-MIT
|
@@ -1,11 +1,19 @@
|
|||||||
# Changes
|
# Changes
|
||||||
|
|
||||||
|
## [0.2.3] - 2019-06-22
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
* Allow to start System using exsiting CurrentThread Handle #22
|
||||||
|
|
||||||
|
|
||||||
## [0.2.2] - 2019-03-28
|
## [0.2.2] - 2019-03-28
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
* Moved `blocking` module to `actix-threadpool` crate
|
* Moved `blocking` module to `actix-threadpool` crate
|
||||||
|
|
||||||
|
|
||||||
## [0.2.1] - 2019-03-11
|
## [0.2.1] - 2019-03-11
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
@@ -16,12 +24,14 @@
|
|||||||
|
|
||||||
* Arbiter::exec - execute fn on the arbiter's thread and wait result
|
* Arbiter::exec - execute fn on the arbiter's thread and wait result
|
||||||
|
|
||||||
|
|
||||||
## [0.2.0] - 2019-03-06
|
## [0.2.0] - 2019-03-06
|
||||||
|
|
||||||
* `run` method returns `io::Result<()>`
|
* `run` method returns `io::Result<()>`
|
||||||
|
|
||||||
* Removed `Handle`
|
* Removed `Handle`
|
||||||
|
|
||||||
|
|
||||||
## [0.1.0] - 2018-12-09
|
## [0.1.0] - 2018-12-09
|
||||||
|
|
||||||
* Initial release
|
* Initial release
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "actix-rt"
|
name = "actix-rt"
|
||||||
version = "0.2.2"
|
version = "0.2.3"
|
||||||
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
|
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
|
||||||
description = "Actix runtime"
|
description = "Actix runtime"
|
||||||
keywords = ["network", "framework", "async", "futures"]
|
keywords = ["network", "framework", "async", "futures"]
|
||||||
@@ -18,7 +18,7 @@ name = "actix_rt"
|
|||||||
path = "src/lib.rs"
|
path = "src/lib.rs"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
actix-threadpool = "0.1.0"
|
actix-threadpool = "0.1.1"
|
||||||
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
actix-rt/LICENSE-APACHE
Symbolic link
1
actix-rt/LICENSE-APACHE
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
../LICENSE-APACHE
|
1
actix-rt/LICENSE-MIT
Symbolic link
1
actix-rt/LICENSE-MIT
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
../LICENSE-MIT
|
@@ -1,11 +1,12 @@
|
|||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
use std::io;
|
use std::io;
|
||||||
|
|
||||||
|
use futures::future;
|
||||||
use futures::future::{lazy, Future};
|
use futures::future::{lazy, Future};
|
||||||
use futures::sync::mpsc::unbounded;
|
use futures::sync::mpsc::unbounded;
|
||||||
use futures::sync::oneshot::{channel, Receiver};
|
use futures::sync::oneshot::{channel, Receiver};
|
||||||
|
|
||||||
use tokio_current_thread::CurrentThread;
|
use tokio_current_thread::{CurrentThread, Handle};
|
||||||
use tokio_reactor::Reactor;
|
use tokio_reactor::Reactor;
|
||||||
use tokio_timer::clock::Clock;
|
use tokio_timer::clock::Clock;
|
||||||
use tokio_timer::timer::Timer;
|
use tokio_timer::timer::Timer;
|
||||||
@@ -69,6 +70,13 @@ impl Builder {
|
|||||||
self.create_runtime(|| {})
|
self.create_runtime(|| {})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Create new System that can run asynchronously.
|
||||||
|
///
|
||||||
|
/// This method panics if it cannot start the system arbiter
|
||||||
|
pub(crate) fn build_async(self, executor: Handle) -> AsyncSystemRunner {
|
||||||
|
self.create_async_runtime(executor)
|
||||||
|
}
|
||||||
|
|
||||||
/// This function will start tokio runtime and will finish once the
|
/// This function will start tokio runtime and will finish once the
|
||||||
/// `System::stop()` message get called.
|
/// `System::stop()` message get called.
|
||||||
/// Function `f` get called within tokio runtime context.
|
/// Function `f` get called within tokio runtime context.
|
||||||
@@ -79,6 +87,21 @@ impl Builder {
|
|||||||
self.create_runtime(f).run()
|
self.create_runtime(f).run()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn create_async_runtime(self, executor: Handle) -> AsyncSystemRunner {
|
||||||
|
let (stop_tx, stop) = channel();
|
||||||
|
let (sys_sender, sys_receiver) = unbounded();
|
||||||
|
|
||||||
|
let system = System::construct(sys_sender, Arbiter::new_system(), self.stop_on_panic);
|
||||||
|
|
||||||
|
// system arbiter
|
||||||
|
let arb = SystemArbiter::new(stop_tx, sys_receiver);
|
||||||
|
|
||||||
|
// start the system arbiter
|
||||||
|
executor.spawn(arb).expect("could not start system arbiter");
|
||||||
|
|
||||||
|
AsyncSystemRunner { stop, system }
|
||||||
|
}
|
||||||
|
|
||||||
fn create_runtime<F>(self, f: F) -> SystemRunner
|
fn create_runtime<F>(self, f: F) -> SystemRunner
|
||||||
where
|
where
|
||||||
F: FnOnce() + 'static,
|
F: FnOnce() + 'static,
|
||||||
@@ -127,6 +150,42 @@ impl Builder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub(crate) struct AsyncSystemRunner {
|
||||||
|
stop: Receiver<i32>,
|
||||||
|
system: System,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl AsyncSystemRunner {
|
||||||
|
/// This function will start event loop and returns a future that
|
||||||
|
/// resolves once the `System::stop()` function is called.
|
||||||
|
pub(crate) fn run_nonblocking(self) -> impl Future<Item = (), Error = io::Error> + Send {
|
||||||
|
let AsyncSystemRunner { stop, .. } = self;
|
||||||
|
|
||||||
|
// run loop
|
||||||
|
future::lazy(|| {
|
||||||
|
Arbiter::run_system();
|
||||||
|
stop.then(|res| match res {
|
||||||
|
Ok(code) => {
|
||||||
|
if code != 0 {
|
||||||
|
Err(io::Error::new(
|
||||||
|
io::ErrorKind::Other,
|
||||||
|
format!("Non-zero exit code: {}", code),
|
||||||
|
))
|
||||||
|
} else {
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(e) => Err(io::Error::new(io::ErrorKind::Other, e)),
|
||||||
|
})
|
||||||
|
.then(|result| {
|
||||||
|
Arbiter::stop_system();
|
||||||
|
result
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Helper object that runs System's event loop
|
/// Helper object that runs System's event loop
|
||||||
#[must_use = "SystemRunner must be run"]
|
#[must_use = "SystemRunner must be run"]
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
@@ -3,6 +3,8 @@ use std::io;
|
|||||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||||
|
|
||||||
use futures::sync::mpsc::UnboundedSender;
|
use futures::sync::mpsc::UnboundedSender;
|
||||||
|
use futures::Future;
|
||||||
|
use tokio_current_thread::Handle;
|
||||||
|
|
||||||
use crate::arbiter::{Arbiter, SystemCommand};
|
use crate::arbiter::{Arbiter, SystemCommand};
|
||||||
use crate::builder::{Builder, SystemRunner};
|
use crate::builder::{Builder, SystemRunner};
|
||||||
@@ -55,6 +57,20 @@ impl System {
|
|||||||
Self::builder().name(name).build()
|
Self::builder().name(name).build()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(clippy::new_ret_no_self)]
|
||||||
|
/// Create new system using provided CurrentThread Handle.
|
||||||
|
///
|
||||||
|
/// This method panics if it can not spawn system arbiter
|
||||||
|
pub fn run_in_executor<T: Into<String>>(
|
||||||
|
name: T,
|
||||||
|
executor: Handle,
|
||||||
|
) -> impl Future<Item = (), Error = io::Error> + Send {
|
||||||
|
Self::builder()
|
||||||
|
.name(name)
|
||||||
|
.build_async(executor)
|
||||||
|
.run_nonblocking()
|
||||||
|
}
|
||||||
|
|
||||||
/// Get current running system.
|
/// Get current running system.
|
||||||
pub fn current() -> System {
|
pub fn current() -> System {
|
||||||
CURRENT.with(|cell| match *cell.borrow() {
|
CURRENT.with(|cell| match *cell.borrow() {
|
||||||
|
1
actix-server-config/LICENSE-APACHE
Symbolic link
1
actix-server-config/LICENSE-APACHE
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
../LICENSE-APACHE
|
1
actix-server-config/LICENSE-MIT
Symbolic link
1
actix-server-config/LICENSE-MIT
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
../LICENSE-MIT
|
@@ -1,5 +1,12 @@
|
|||||||
# Changes
|
# Changes
|
||||||
|
|
||||||
|
## [0.5.1] - 2019-05-18
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
* ServerBuilder::shutdown_timeout() accepts u64
|
||||||
|
|
||||||
|
|
||||||
## [0.5.0] - 2019-05-12
|
## [0.5.0] - 2019-05-12
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "actix-server"
|
name = "actix-server"
|
||||||
version = "0.5.0"
|
version = "0.5.1"
|
||||||
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"]
|
||||||
|
1
actix-server/LICENSE-APACHE
Symbolic link
1
actix-server/LICENSE-APACHE
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
../LICENSE-APACHE
|
1
actix-server/LICENSE-MIT
Symbolic link
1
actix-server/LICENSE-MIT
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
../LICENSE-MIT
|
@@ -128,8 +128,8 @@ impl ServerBuilder {
|
|||||||
/// dropped.
|
/// dropped.
|
||||||
///
|
///
|
||||||
/// By default shutdown timeout sets to 30 seconds.
|
/// By default shutdown timeout sets to 30 seconds.
|
||||||
pub fn shutdown_timeout(mut self, sec: u16) -> Self {
|
pub fn shutdown_timeout(mut self, sec: u64) -> Self {
|
||||||
self.shutdown_timeout = Duration::from_secs(u64::from(sec));
|
self.shutdown_timeout = Duration::from_secs(sec);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,5 +1,11 @@
|
|||||||
# Changes
|
# Changes
|
||||||
|
|
||||||
|
## [0.4.1] - 2019-06-06
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
* Add `new_apply_cfg` function
|
||||||
|
|
||||||
## [0.4.0] - 2019-05-12
|
## [0.4.0] - 2019-05-12
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "actix-service"
|
name = "actix-service"
|
||||||
version = "0.4.0"
|
version = "0.4.1"
|
||||||
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
actix-service/LICENSE-APACHE
Symbolic link
1
actix-service/LICENSE-APACHE
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
../LICENSE-APACHE
|
1
actix-service/LICENSE-MIT
Symbolic link
1
actix-service/LICENSE-MIT
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
../LICENSE-MIT
|
@@ -7,7 +7,17 @@ use crate::cell::Cell;
|
|||||||
use crate::{IntoService, NewService, Service};
|
use crate::{IntoService, NewService, Service};
|
||||||
|
|
||||||
/// Convert `Fn(&Config, &mut Service) -> Future<Service>` fn to a NewService
|
/// Convert `Fn(&Config, &mut Service) -> Future<Service>` fn to a NewService
|
||||||
pub fn apply_cfg<F, C, T, R, S>(srv: T, f: F) -> ApplyConfigService<F, C, T, R, S>
|
pub fn apply_cfg<F, C, T, R, S>(
|
||||||
|
srv: T,
|
||||||
|
f: F,
|
||||||
|
) -> impl NewService<
|
||||||
|
Config = C,
|
||||||
|
Request = S::Request,
|
||||||
|
Response = S::Response,
|
||||||
|
Error = S::Error,
|
||||||
|
Service = S,
|
||||||
|
InitError = R::Error,
|
||||||
|
> + Clone
|
||||||
where
|
where
|
||||||
F: FnMut(&C, &mut T) -> R,
|
F: FnMut(&C, &mut T) -> R,
|
||||||
T: Service,
|
T: Service,
|
||||||
@@ -22,8 +32,36 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Convert `Fn(&Config, &mut Service) -> Future<Service>` fn to a NewService
|
||||||
|
/// Service get constructor from NewService.
|
||||||
|
pub fn new_apply_cfg<F, C, T, R, S>(
|
||||||
|
srv: T,
|
||||||
|
f: F,
|
||||||
|
) -> impl NewService<
|
||||||
|
Config = C,
|
||||||
|
Request = S::Request,
|
||||||
|
Response = S::Response,
|
||||||
|
Error = S::Error,
|
||||||
|
Service = S,
|
||||||
|
InitError = T::InitError,
|
||||||
|
> + Clone
|
||||||
|
where
|
||||||
|
C: Clone,
|
||||||
|
F: FnMut(&C, &mut T::Service) -> R,
|
||||||
|
T: NewService<Config = ()>,
|
||||||
|
R: IntoFuture<Error = T::InitError>,
|
||||||
|
R::Item: IntoService<S>,
|
||||||
|
S: Service,
|
||||||
|
{
|
||||||
|
ApplyConfigNewService {
|
||||||
|
f: Cell::new(f),
|
||||||
|
srv: Cell::new(srv),
|
||||||
|
_t: PhantomData,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Convert `Fn(&Config) -> Future<Service>` fn to NewService
|
/// Convert `Fn(&Config) -> Future<Service>` fn to NewService
|
||||||
pub struct ApplyConfigService<F, C, T, R, S>
|
struct ApplyConfigService<F, C, T, R, S>
|
||||||
where
|
where
|
||||||
F: FnMut(&C, &mut T) -> R,
|
F: FnMut(&C, &mut T) -> R,
|
||||||
T: Service,
|
T: Service,
|
||||||
@@ -79,7 +117,7 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct FnNewServiceConfigFut<R, S>
|
struct FnNewServiceConfigFut<R, S>
|
||||||
where
|
where
|
||||||
R: IntoFuture,
|
R: IntoFuture,
|
||||||
R::Item: IntoService<S>,
|
R::Item: IntoService<S>,
|
||||||
@@ -102,3 +140,113 @@ where
|
|||||||
Ok(Async::Ready(try_ready!(self.fut.poll()).into_service()))
|
Ok(Async::Ready(try_ready!(self.fut.poll()).into_service()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Convert `Fn(&Config) -> Future<Service>` fn to NewService
|
||||||
|
struct ApplyConfigNewService<F, C, T, R, S>
|
||||||
|
where
|
||||||
|
C: Clone,
|
||||||
|
F: FnMut(&C, &mut T::Service) -> R,
|
||||||
|
T: NewService<Config = ()>,
|
||||||
|
R: IntoFuture<Error = T::InitError>,
|
||||||
|
R::Item: IntoService<S>,
|
||||||
|
S: Service,
|
||||||
|
{
|
||||||
|
f: Cell<F>,
|
||||||
|
srv: Cell<T>,
|
||||||
|
_t: PhantomData<(C, R, S)>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<F, C, T, R, S> Clone for ApplyConfigNewService<F, C, T, R, S>
|
||||||
|
where
|
||||||
|
C: Clone,
|
||||||
|
F: FnMut(&C, &mut T::Service) -> R,
|
||||||
|
T: NewService<Config = ()>,
|
||||||
|
R: IntoFuture<Error = T::InitError>,
|
||||||
|
R::Item: IntoService<S>,
|
||||||
|
S: Service,
|
||||||
|
{
|
||||||
|
fn clone(&self) -> Self {
|
||||||
|
ApplyConfigNewService {
|
||||||
|
f: self.f.clone(),
|
||||||
|
srv: self.srv.clone(),
|
||||||
|
_t: PhantomData,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<F, C, T, R, S> NewService for ApplyConfigNewService<F, C, T, R, S>
|
||||||
|
where
|
||||||
|
C: Clone,
|
||||||
|
F: FnMut(&C, &mut T::Service) -> R,
|
||||||
|
T: NewService<Config = ()>,
|
||||||
|
R: IntoFuture<Error = T::InitError>,
|
||||||
|
R::Item: IntoService<S>,
|
||||||
|
S: Service,
|
||||||
|
{
|
||||||
|
type Config = C;
|
||||||
|
type Request = S::Request;
|
||||||
|
type Response = S::Response;
|
||||||
|
type Error = S::Error;
|
||||||
|
type Service = S;
|
||||||
|
|
||||||
|
type InitError = R::Error;
|
||||||
|
type Future = ApplyConfigNewServiceFut<F, C, T, R, S>;
|
||||||
|
|
||||||
|
fn new_service(&self, cfg: &C) -> Self::Future {
|
||||||
|
ApplyConfigNewServiceFut {
|
||||||
|
f: self.f.clone(),
|
||||||
|
cfg: cfg.clone(),
|
||||||
|
srv: Some(self.srv.get_ref().new_service(&())),
|
||||||
|
fut: None,
|
||||||
|
_t: PhantomData,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct ApplyConfigNewServiceFut<F, C, T, R, S>
|
||||||
|
where
|
||||||
|
C: Clone,
|
||||||
|
F: FnMut(&C, &mut T::Service) -> R,
|
||||||
|
T: NewService<Config = ()>,
|
||||||
|
R: IntoFuture<Error = T::InitError>,
|
||||||
|
R::Item: IntoService<S>,
|
||||||
|
S: Service,
|
||||||
|
{
|
||||||
|
cfg: C,
|
||||||
|
f: Cell<F>,
|
||||||
|
srv: Option<T::Future>,
|
||||||
|
fut: Option<R::Future>,
|
||||||
|
_t: PhantomData<(S,)>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<F, C, T, R, S> Future for ApplyConfigNewServiceFut<F, C, T, R, S>
|
||||||
|
where
|
||||||
|
C: Clone,
|
||||||
|
F: FnMut(&C, &mut T::Service) -> R,
|
||||||
|
T: NewService<Config = ()>,
|
||||||
|
R: IntoFuture<Error = T::InitError>,
|
||||||
|
R::Item: IntoService<S>,
|
||||||
|
S: Service,
|
||||||
|
{
|
||||||
|
type Item = S;
|
||||||
|
type Error = R::Error;
|
||||||
|
|
||||||
|
fn poll(&mut self) -> Poll<Self::Item, Self::Error> {
|
||||||
|
if let Some(ref mut fut) = self.srv {
|
||||||
|
match fut.poll()? {
|
||||||
|
Async::NotReady => return Ok(Async::NotReady),
|
||||||
|
Async::Ready(mut srv) => {
|
||||||
|
let _ = self.srv.take();
|
||||||
|
self.fut = Some(self.f.get_mut()(&self.cfg, &mut srv).into_future());
|
||||||
|
return self.poll();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(ref mut fut) = self.fut {
|
||||||
|
Ok(Async::Ready(try_ready!(fut.poll()).into_service()))
|
||||||
|
} else {
|
||||||
|
Ok(Async::NotReady)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@@ -26,6 +26,10 @@ impl<T> Cell<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) fn get_ref(&self) -> &T {
|
||||||
|
unsafe { &*self.inner.as_ref().get() }
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) fn get_mut(&mut self) -> &mut T {
|
pub(crate) fn get_mut(&mut self) -> &mut T {
|
||||||
unsafe { &mut *self.inner.as_ref().get() }
|
unsafe { &mut *self.inner.as_ref().get() }
|
||||||
}
|
}
|
||||||
|
@@ -25,7 +25,7 @@ mod transform_err;
|
|||||||
|
|
||||||
pub use self::and_then::{AndThen, AndThenNewService};
|
pub use self::and_then::{AndThen, AndThenNewService};
|
||||||
pub use self::apply::{apply_fn, new_apply_fn, Apply, ApplyNewService};
|
pub use self::apply::{apply_fn, new_apply_fn, Apply, ApplyNewService};
|
||||||
pub use self::apply_cfg::apply_cfg;
|
pub use self::apply_cfg::{apply_cfg, new_apply_cfg};
|
||||||
pub use self::fn_service::{new_service_cfg, new_service_fn, service_fn, ServiceFn};
|
pub use self::fn_service::{new_service_cfg, new_service_fn, service_fn, ServiceFn};
|
||||||
pub use self::fn_transform::transform_fn;
|
pub use self::fn_transform::transform_fn;
|
||||||
pub use self::from_err::{FromErr, FromErrNewService};
|
pub use self::from_err::{FromErr, FromErrNewService};
|
||||||
|
1
actix-test-server/LICENSE-APACHE
Symbolic link
1
actix-test-server/LICENSE-APACHE
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
../LICENSE-APACHE
|
1
actix-test-server/LICENSE-MIT
Symbolic link
1
actix-test-server/LICENSE-MIT
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
../LICENSE-MIT
|
@@ -1,5 +1,13 @@
|
|||||||
# Changes
|
# Changes
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
* Update `derive_more` to 0.15
|
||||||
|
|
||||||
|
## [0.1.1] - 2019-06-05
|
||||||
|
|
||||||
|
* Update parking_lot
|
||||||
|
|
||||||
## [0.1.0] - 2019-03-28
|
## [0.1.0] - 2019-03-28
|
||||||
|
|
||||||
* Move threadpool to separate crate
|
* Move threadpool to separate crate
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "actix-threadpool"
|
name = "actix-threadpool"
|
||||||
version = "0.1.0"
|
version = "0.1.1"
|
||||||
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
|
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
|
||||||
description = "Actix thread pool for sync code"
|
description = "Actix thread pool for sync code"
|
||||||
keywords = ["actix", "network", "framework", "async", "futures"]
|
keywords = ["actix", "network", "framework", "async", "futures"]
|
||||||
@@ -18,9 +18,9 @@ name = "actix_threadpool"
|
|||||||
path = "src/lib.rs"
|
path = "src/lib.rs"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
derive_more = "0.14"
|
derive_more = "0.15"
|
||||||
futures = "0.1.25"
|
futures = "0.1.25"
|
||||||
parking_lot = "0.7"
|
parking_lot = "0.8"
|
||||||
lazy_static = "1.2"
|
lazy_static = "1.2"
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
num_cpus = "1.10"
|
num_cpus = "1.10"
|
||||||
|
1
actix-threadpool/LICENSE-APACHE
Symbolic link
1
actix-threadpool/LICENSE-APACHE
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
../LICENSE-APACHE
|
1
actix-threadpool/LICENSE-MIT
Symbolic link
1
actix-threadpool/LICENSE-MIT
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
../LICENSE-MIT
|
1
actix-tower/LICENSE-APACHE
Symbolic link
1
actix-tower/LICENSE-APACHE
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
../LICENSE-APACHE
|
1
actix-tower/LICENSE-MIT
Symbolic link
1
actix-tower/LICENSE-MIT
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
../LICENSE-MIT
|
1
actix-utils/LICENSE-APACHE
Symbolic link
1
actix-utils/LICENSE-APACHE
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
../LICENSE-APACHE
|
1
actix-utils/LICENSE-MIT
Symbolic link
1
actix-utils/LICENSE-MIT
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
../LICENSE-MIT
|
@@ -1,5 +1,13 @@
|
|||||||
# Changes
|
# Changes
|
||||||
|
|
||||||
|
## [0.1.5] - 2019-05-15
|
||||||
|
|
||||||
|
* Remove debug prints
|
||||||
|
|
||||||
|
## [0.1.4] - 2019-05-15
|
||||||
|
|
||||||
|
* Fix checked resource match
|
||||||
|
|
||||||
## [0.1.3] - 2019-04-22
|
## [0.1.3] - 2019-04-22
|
||||||
|
|
||||||
* Added support for `remainder match` (i.e "/path/{tail}*")
|
* Added support for `remainder match` (i.e "/path/{tail}*")
|
||||||
|
@@ -1,8 +1,8 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "actix-router"
|
name = "actix-router"
|
||||||
version = "0.1.3"
|
version = "0.1.5"
|
||||||
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
|
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
|
||||||
description = "Path table 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"
|
||||||
|
1
router/LICENSE-APACHE
Symbolic link
1
router/LICENSE-APACHE
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
../LICENSE-APACHE
|
1
router/LICENSE-MIT
Symbolic link
1
router/LICENSE-MIT
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
../LICENSE-MIT
|
@@ -5,7 +5,7 @@ use std::rc::Rc;
|
|||||||
use regex::{escape, Regex};
|
use regex::{escape, Regex};
|
||||||
|
|
||||||
use crate::path::{Path, PathItem};
|
use crate::path::{Path, PathItem};
|
||||||
use crate::ResourcePath;
|
use crate::{Resource, ResourcePath};
|
||||||
|
|
||||||
const MAX_DYNAMIC_SEGMENTS: usize = 16;
|
const MAX_DYNAMIC_SEGMENTS: usize = 16;
|
||||||
|
|
||||||
@@ -240,6 +240,90 @@ impl ResourceDef {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Is the given path and parameters a match against this pattern?
|
||||||
|
pub fn match_path_checked<R, T, F, U>(
|
||||||
|
&self,
|
||||||
|
res: &mut R,
|
||||||
|
check: &F,
|
||||||
|
user_data: &Option<U>,
|
||||||
|
) -> bool
|
||||||
|
where
|
||||||
|
T: ResourcePath,
|
||||||
|
R: Resource<T>,
|
||||||
|
F: Fn(&R, &Option<U>) -> bool,
|
||||||
|
{
|
||||||
|
match self.tp {
|
||||||
|
PatternType::Static(ref s) => {
|
||||||
|
if s == res.resource_path().path() && check(res, user_data) {
|
||||||
|
let path = res.resource_path();
|
||||||
|
path.skip(path.len() as u16);
|
||||||
|
true
|
||||||
|
} else {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
PatternType::Dynamic(ref re, ref names, len) => {
|
||||||
|
let mut idx = 0;
|
||||||
|
let mut pos = 0;
|
||||||
|
let mut segments: [PathItem; MAX_DYNAMIC_SEGMENTS] =
|
||||||
|
[PathItem::Static(""); MAX_DYNAMIC_SEGMENTS];
|
||||||
|
|
||||||
|
if let Some(captures) = re.captures(res.resource_path().path()) {
|
||||||
|
for (no, name) in names.iter().enumerate() {
|
||||||
|
if let Some(m) = captures.name(&name) {
|
||||||
|
idx += 1;
|
||||||
|
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 {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if !check(res, user_data) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
let path = res.resource_path();
|
||||||
|
for idx in 0..idx {
|
||||||
|
path.add(names[idx].clone(), segments[idx]);
|
||||||
|
}
|
||||||
|
path.skip((pos + len) as u16);
|
||||||
|
true
|
||||||
|
}
|
||||||
|
PatternType::Prefix(ref s) => {
|
||||||
|
let len = {
|
||||||
|
let rpath = res.resource_path().path();
|
||||||
|
if s == rpath {
|
||||||
|
s.len()
|
||||||
|
} else if rpath.starts_with(s)
|
||||||
|
&& (s.ends_with('/') || rpath.split_at(s.len()).1.starts_with('/'))
|
||||||
|
{
|
||||||
|
if s.ends_with('/') {
|
||||||
|
s.len() - 1
|
||||||
|
} else {
|
||||||
|
s.len()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
if !check(res, user_data) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
let path = res.resource_path();
|
||||||
|
path.skip(min(path.path().len(), len) as u16);
|
||||||
|
true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Build resource path from elements. Returns `true` on success.
|
/// Build resource path from elements. Returns `true` on success.
|
||||||
pub fn resource_path<U, I>(&self, path: &mut String, elements: &mut U) -> bool
|
pub fn resource_path<U, I>(&self, path: &mut String, elements: &mut U) -> bool
|
||||||
where
|
where
|
||||||
|
@@ -19,26 +19,26 @@ impl<T, U> Router<T, U> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn recognize<R, P>(&self, path: &mut R) -> Option<(&T, ResourceId)>
|
pub fn recognize<R, P>(&self, resource: &mut R) -> Option<(&T, ResourceId)>
|
||||||
where
|
where
|
||||||
R: Resource<P>,
|
R: Resource<P>,
|
||||||
P: ResourcePath,
|
P: ResourcePath,
|
||||||
{
|
{
|
||||||
for item in self.0.iter() {
|
for item in self.0.iter() {
|
||||||
if item.0.match_path(path.resource_path()) {
|
if item.0.match_path(resource.resource_path()) {
|
||||||
return Some((&item.1, ResourceId(item.0.id())));
|
return Some((&item.1, ResourceId(item.0.id())));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn recognize_mut<R, P>(&mut self, res: &mut R) -> Option<(&mut T, ResourceId)>
|
pub fn recognize_mut<R, P>(&mut self, resource: &mut R) -> Option<(&mut T, ResourceId)>
|
||||||
where
|
where
|
||||||
R: Resource<P>,
|
R: Resource<P>,
|
||||||
P: ResourcePath,
|
P: ResourcePath,
|
||||||
{
|
{
|
||||||
for item in self.0.iter_mut() {
|
for item in self.0.iter_mut() {
|
||||||
if item.0.match_path(res.resource_path()) {
|
if item.0.match_path(resource.resource_path()) {
|
||||||
return Some((&mut item.1, ResourceId(item.0.id())));
|
return Some((&mut item.1, ResourceId(item.0.id())));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -47,7 +47,7 @@ impl<T, U> Router<T, U> {
|
|||||||
|
|
||||||
pub fn recognize_mut_checked<R, P, F>(
|
pub fn recognize_mut_checked<R, P, F>(
|
||||||
&mut self,
|
&mut self,
|
||||||
res: &mut R,
|
resource: &mut R,
|
||||||
check: F,
|
check: F,
|
||||||
) -> Option<(&mut T, ResourceId)>
|
) -> Option<(&mut T, ResourceId)>
|
||||||
where
|
where
|
||||||
@@ -56,7 +56,7 @@ impl<T, U> Router<T, U> {
|
|||||||
P: ResourcePath,
|
P: ResourcePath,
|
||||||
{
|
{
|
||||||
for item in self.0.iter_mut() {
|
for item in self.0.iter_mut() {
|
||||||
if item.0.match_path(res.resource_path()) && check(res, &item.2) {
|
if item.0.match_path_checked(resource, &check, &item.2) {
|
||||||
return Some((&mut item.1, ResourceId(item.0.id())));
|
return Some((&mut item.1, ResourceId(item.0.id())));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user