mirror of
https://github.com/fafhrd91/actix-net
synced 2024-11-24 04:52:58 +01:00
rename timer to time
This commit is contained in:
parent
3d51aa7115
commit
67961f8a36
@ -80,7 +80,8 @@ fn main() {
|
|||||||
future::ok(())
|
future::ok(())
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
).unwrap()
|
)
|
||||||
|
.unwrap()
|
||||||
.start();
|
.start();
|
||||||
|
|
||||||
sys.run();
|
sys.run();
|
||||||
|
@ -60,7 +60,8 @@ fn main() {
|
|||||||
println!("got ssl connection {:?}", num);
|
println!("got ssl connection {:?}", num);
|
||||||
future::ok(())
|
future::ok(())
|
||||||
})
|
})
|
||||||
}).unwrap()
|
})
|
||||||
|
.unwrap()
|
||||||
.start();
|
.start();
|
||||||
|
|
||||||
sys.run();
|
sys.run();
|
||||||
|
@ -197,7 +197,8 @@ where
|
|||||||
io::ErrorKind::WriteZero,
|
io::ErrorKind::WriteZero,
|
||||||
"failed to \
|
"failed to \
|
||||||
write frame to transport",
|
write frame to transport",
|
||||||
).into());
|
)
|
||||||
|
.into());
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Add a way to `bytes` to do this w/o returning the drained
|
// TODO: Add a way to `bytes` to do this w/o returning the drained
|
||||||
|
@ -6,13 +6,13 @@ use futures::{Async, Future, Poll};
|
|||||||
use tokio_timer::Delay;
|
use tokio_timer::Delay;
|
||||||
|
|
||||||
use super::service::{NewService, Service};
|
use super::service::{NewService, Service};
|
||||||
use super::timer::{LowResTimer, LowResTimerService};
|
use super::time::{LowResTime, LowResTimeService};
|
||||||
use super::Never;
|
use super::Never;
|
||||||
|
|
||||||
pub struct KeepAlive<R, E, F> {
|
pub struct KeepAlive<R, E, F> {
|
||||||
f: F,
|
f: F,
|
||||||
ka: Duration,
|
ka: Duration,
|
||||||
timer: LowResTimer,
|
time: LowResTime,
|
||||||
_t: PhantomData<(R, E)>,
|
_t: PhantomData<(R, E)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -20,11 +20,11 @@ impl<R, E, F> KeepAlive<R, E, F>
|
|||||||
where
|
where
|
||||||
F: Fn() -> E + Clone,
|
F: Fn() -> E + Clone,
|
||||||
{
|
{
|
||||||
pub fn new(ka: Duration, timer: LowResTimer, f: F) -> Self {
|
pub fn new(ka: Duration, time: LowResTime, f: F) -> Self {
|
||||||
KeepAlive {
|
KeepAlive {
|
||||||
f,
|
f,
|
||||||
ka,
|
ka,
|
||||||
timer,
|
time,
|
||||||
_t: PhantomData,
|
_t: PhantomData,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -38,7 +38,7 @@ where
|
|||||||
KeepAlive {
|
KeepAlive {
|
||||||
f: self.f.clone(),
|
f: self.f.clone(),
|
||||||
ka: self.ka,
|
ka: self.ka,
|
||||||
timer: self.timer.clone(),
|
time: self.time.clone(),
|
||||||
_t: PhantomData,
|
_t: PhantomData,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -58,7 +58,7 @@ where
|
|||||||
fn new_service(&self) -> Self::Future {
|
fn new_service(&self) -> Self::Future {
|
||||||
ok(KeepAliveService::new(
|
ok(KeepAliveService::new(
|
||||||
self.ka,
|
self.ka,
|
||||||
self.timer.timer(),
|
self.time.timer(),
|
||||||
self.f.clone(),
|
self.f.clone(),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
@ -67,7 +67,7 @@ where
|
|||||||
pub struct KeepAliveService<R, E, F> {
|
pub struct KeepAliveService<R, E, F> {
|
||||||
f: F,
|
f: F,
|
||||||
ka: Duration,
|
ka: Duration,
|
||||||
timer: LowResTimerService,
|
time: LowResTimeService,
|
||||||
delay: Delay,
|
delay: Delay,
|
||||||
expire: Instant,
|
expire: Instant,
|
||||||
_t: PhantomData<(R, E)>,
|
_t: PhantomData<(R, E)>,
|
||||||
@ -77,14 +77,14 @@ impl<R, E, F> KeepAliveService<R, E, F>
|
|||||||
where
|
where
|
||||||
F: Fn() -> E,
|
F: Fn() -> E,
|
||||||
{
|
{
|
||||||
pub fn new(ka: Duration, timer: LowResTimerService, f: F) -> Self {
|
pub fn new(ka: Duration, time: LowResTimeService, f: F) -> Self {
|
||||||
let expire = timer.now() + ka;
|
let expire = time.now() + ka;
|
||||||
KeepAliveService {
|
KeepAliveService {
|
||||||
f,
|
f,
|
||||||
ka,
|
ka,
|
||||||
timer,
|
time,
|
||||||
delay: Delay::new(expire),
|
|
||||||
expire,
|
expire,
|
||||||
|
delay: Delay::new(expire),
|
||||||
_t: PhantomData,
|
_t: PhantomData,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -102,7 +102,7 @@ where
|
|||||||
fn poll_ready(&mut self) -> Poll<(), Self::Error> {
|
fn poll_ready(&mut self) -> Poll<(), Self::Error> {
|
||||||
match self.delay.poll() {
|
match self.delay.poll() {
|
||||||
Ok(Async::Ready(_)) => {
|
Ok(Async::Ready(_)) => {
|
||||||
let now = self.timer.now();
|
let now = self.time.now();
|
||||||
if self.expire <= now {
|
if self.expire <= now {
|
||||||
Err((self.f)())
|
Err((self.f)())
|
||||||
} else {
|
} else {
|
||||||
@ -117,7 +117,7 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn call(&mut self, req: Self::Request) -> Self::Future {
|
fn call(&mut self, req: Self::Request) -> Self::Future {
|
||||||
self.expire = self.timer.now() + self.ka;
|
self.expire = self.time.now() + self.ka;
|
||||||
ok(req)
|
ok(req)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,10 +9,7 @@
|
|||||||
|
|
||||||
#![cfg_attr(
|
#![cfg_attr(
|
||||||
feature = "cargo-clippy",
|
feature = "cargo-clippy",
|
||||||
allow(
|
allow(declare_interior_mutable_const, borrow_interior_mutable_const)
|
||||||
declare_interior_mutable_const,
|
|
||||||
borrow_interior_mutable_const
|
|
||||||
)
|
|
||||||
)]
|
)]
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
@ -69,8 +66,8 @@ pub mod server;
|
|||||||
pub mod service;
|
pub mod service;
|
||||||
pub mod ssl;
|
pub mod ssl;
|
||||||
pub mod stream;
|
pub mod stream;
|
||||||
|
pub mod time;
|
||||||
pub mod timeout;
|
pub mod timeout;
|
||||||
pub mod timer;
|
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug)]
|
#[derive(Copy, Clone, Debug)]
|
||||||
pub enum Never {}
|
pub enum Never {}
|
||||||
|
@ -243,9 +243,11 @@ impl Accept {
|
|||||||
for event in events.iter() {
|
for event in events.iter() {
|
||||||
let token = event.token();
|
let token = event.token();
|
||||||
match token {
|
match token {
|
||||||
CMD => if !self.process_cmd() {
|
CMD => {
|
||||||
|
if !self.process_cmd() {
|
||||||
return;
|
return;
|
||||||
},
|
}
|
||||||
|
}
|
||||||
TIMER => self.process_timer(),
|
TIMER => self.process_timer(),
|
||||||
NOTIFY => self.backpressure(false),
|
NOTIFY => self.backpressure(false),
|
||||||
_ => {
|
_ => {
|
||||||
|
@ -151,7 +151,8 @@ impl Worker {
|
|||||||
.map_err(|e| {
|
.map_err(|e| {
|
||||||
error!("Can not start worker: {:?}", e);
|
error!("Can not start worker: {:?}", e);
|
||||||
Arbiter::current().do_send(StopArbiter(0));
|
Arbiter::current().do_send(StopArbiter(0));
|
||||||
}).and_then(move |services| {
|
})
|
||||||
|
.and_then(move |services| {
|
||||||
wrk.services.extend(services);
|
wrk.services.extend(services);
|
||||||
wrk
|
wrk
|
||||||
}),
|
}),
|
||||||
|
@ -10,7 +10,7 @@ use super::service::{NewService, Service};
|
|||||||
use super::Never;
|
use super::Never;
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct LowResTimer(Cell<Inner>);
|
pub struct LowResTime(Cell<Inner>);
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
struct Inner {
|
struct Inner {
|
||||||
@ -27,28 +27,28 @@ impl Inner {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LowResTimer {
|
impl LowResTime {
|
||||||
pub fn with(resolution: Duration) -> LowResTimer {
|
pub fn with(resolution: Duration) -> LowResTime {
|
||||||
LowResTimer(Cell::new(Inner::new(resolution)))
|
LowResTime(Cell::new(Inner::new(resolution)))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn timer(&self) -> LowResTimerService {
|
pub fn timer(&self) -> LowResTimeService {
|
||||||
LowResTimerService(self.0.clone())
|
LowResTimeService(self.0.clone())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for LowResTimer {
|
impl Default for LowResTime {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
LowResTimer(Cell::new(Inner::new(Duration::from_secs(1))))
|
LowResTime(Cell::new(Inner::new(Duration::from_secs(1))))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl NewService for LowResTimer {
|
impl NewService for LowResTime {
|
||||||
type Request = ();
|
type Request = ();
|
||||||
type Response = Instant;
|
type Response = Instant;
|
||||||
type Error = Never;
|
type Error = Never;
|
||||||
type InitError = Never;
|
type InitError = Never;
|
||||||
type Service = LowResTimerService;
|
type Service = LowResTimeService;
|
||||||
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 {
|
||||||
@ -57,11 +57,11 @@ impl NewService for LowResTimer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct LowResTimerService(Cell<Inner>);
|
pub struct LowResTimeService(Cell<Inner>);
|
||||||
|
|
||||||
impl LowResTimerService {
|
impl LowResTimeService {
|
||||||
pub fn with(resolution: Duration) -> LowResTimerService {
|
pub fn with(resolution: Duration) -> LowResTimeService {
|
||||||
LowResTimerService(Cell::new(Inner::new(resolution)))
|
LowResTimeService(Cell::new(Inner::new(resolution)))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get current time. This function has to be called from
|
/// Get current time. This function has to be called from
|
||||||
@ -88,7 +88,7 @@ impl LowResTimerService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Service for LowResTimerService {
|
impl Service for LowResTimeService {
|
||||||
type Request = ();
|
type Request = ();
|
||||||
type Response = Instant;
|
type Response = Instant;
|
||||||
type Error = Never;
|
type Error = Never;
|
Loading…
Reference in New Issue
Block a user