1
0
mirror of https://github.com/fafhrd91/actix-net synced 2024-11-27 20:12:58 +01:00

Disconnect callback accepts owned state

This commit is contained in:
Nikolay Kim 2019-12-11 18:57:43 +06:00
parent 8bb81c0768
commit 081205a02f
4 changed files with 21 additions and 17 deletions

View File

@ -1,6 +1,10 @@
# Changes # Changes
## [0.4.0] - 2019-12-1 ## [0.4.1] - 2019-12-11
* Disconnect callback accepts owned state
## [0.4.0] - 2019-12-11
* Remove `E` param * Remove `E` param

View File

@ -1,6 +1,6 @@
[package] [package]
name = "actix-ioframe" name = "actix-ioframe"
version = "0.4.0" version = "0.4.1"
authors = ["Nikolay Kim <fafhrd91@gmail.com>"] authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
description = "Actix framed service" description = "Actix framed service"
keywords = ["network", "framework", "async", "futures"] keywords = ["network", "framework", "async", "futures"]
@ -19,7 +19,7 @@ path = "src/lib.rs"
[dependencies] [dependencies]
actix-service = "1.0.0" actix-service = "1.0.0"
actix-codec = "0.2.0" actix-codec = "0.2.0"
actix-utils = "1.0.0" actix-utils = "1.0.1"
actix-rt = "1.0.0" actix-rt = "1.0.0"
bytes = "0.5" bytes = "0.5"
either = "1.5.2" either = "1.5.2"

View File

@ -43,7 +43,7 @@ where
framed: Framed<T, U>, framed: Framed<T, U>,
rx: mpsc::Receiver<Result<Message<<U as Encoder>::Item>, S::Error>>, rx: mpsc::Receiver<Result<Message<<U as Encoder>::Item>, S::Error>>,
tx: mpsc::Sender<Result<Message<<U as Encoder>::Item>, S::Error>>, tx: mpsc::Sender<Result<Message<<U as Encoder>::Item>, S::Error>>,
disconnect: Option<Rc<dyn Fn(&mut St, bool)>>, disconnect: Option<Rc<dyn Fn(St, bool)>>,
} }
impl<St, S, T, U> Dispatcher<St, S, T, U> impl<St, S, T, U> Dispatcher<St, S, T, U>
@ -63,7 +63,7 @@ where
service: F, service: F,
sink: Sink<<U as Encoder>::Item>, sink: Sink<<U as Encoder>::Item>,
rx: mpsc::Receiver<Result<Message<<U as Encoder>::Item>, S::Error>>, rx: mpsc::Receiver<Result<Message<<U as Encoder>::Item>, S::Error>>,
disconnect: Option<Rc<dyn Fn(&mut St, bool)>>, disconnect: Option<Rc<dyn Fn(St, bool)>>,
) -> Self { ) -> Self {
let tx = rx.sender(); let tx = rx.sender();
@ -245,7 +245,7 @@ where
} }
} }
if let Some(ref disconnect) = self.disconnect { if let Some(ref disconnect) = self.disconnect {
(&*disconnect)(&mut self.state, true); (&*disconnect)(self.state.clone(), true);
} }
Poll::Ready(Err(self.dispatch_state.take_error())) Poll::Ready(Err(self.dispatch_state.take_error()))
} }
@ -265,19 +265,19 @@ where
let _ = tx.send(()); let _ = tx.send(());
} }
if let Some(ref disconnect) = self.disconnect { if let Some(ref disconnect) = self.disconnect {
(&*disconnect)(&mut self.state, false); (&*disconnect)(self.state.clone(), false);
} }
Poll::Ready(Ok(())) Poll::Ready(Ok(()))
} }
FramedState::FramedError(_) => { FramedState::FramedError(_) => {
if let Some(ref disconnect) = self.disconnect { if let Some(ref disconnect) = self.disconnect {
(&*disconnect)(&mut self.state, true); (&*disconnect)(self.state.clone(), true);
} }
Poll::Ready(Err(self.dispatch_state.take_framed_error())) Poll::Ready(Err(self.dispatch_state.take_framed_error()))
} }
FramedState::Stopping => { FramedState::Stopping => {
if let Some(ref disconnect) = self.disconnect { if let Some(ref disconnect) = self.disconnect {
(&*disconnect)(&mut self.state, false); (&*disconnect)(self.state.clone(), false);
} }
Poll::Ready(Ok(())) Poll::Ready(Ok(()))
} }

View File

@ -75,7 +75,7 @@ impl<St: Clone, Codec> Builder<St, Codec> {
pub struct ServiceBuilder<St, C, Io, Codec> { pub struct ServiceBuilder<St, C, Io, Codec> {
connect: C, connect: C,
disconnect: Option<Rc<dyn Fn(&mut St, bool)>>, disconnect: Option<Rc<dyn Fn(St, bool)>>,
_t: PhantomData<(St, Io, Codec)>, _t: PhantomData<(St, Io, Codec)>,
} }
@ -93,7 +93,7 @@ where
/// Second parameter indicates error occured during disconnect. /// Second parameter indicates error occured during disconnect.
pub fn disconnect<F, Out>(mut self, disconnect: F) -> Self pub fn disconnect<F, Out>(mut self, disconnect: F) -> Self
where where
F: Fn(&mut St, bool) + 'static, F: Fn(St, bool) + 'static,
{ {
self.disconnect = Some(Rc::new(disconnect)); self.disconnect = Some(Rc::new(disconnect));
self self
@ -122,7 +122,7 @@ where
pub struct NewServiceBuilder<St, C, Io, Codec> { pub struct NewServiceBuilder<St, C, Io, Codec> {
connect: C, connect: C,
disconnect: Option<Rc<dyn Fn(&mut St, bool)>>, disconnect: Option<Rc<dyn Fn(St, bool)>>,
_t: PhantomData<(St, Io, Codec)>, _t: PhantomData<(St, Io, Codec)>,
} }
@ -146,7 +146,7 @@ where
/// Second parameter indicates error occured during disconnect. /// Second parameter indicates error occured during disconnect.
pub fn disconnect<F>(mut self, disconnect: F) -> Self pub fn disconnect<F>(mut self, disconnect: F) -> Self
where where
F: Fn(&mut St, bool) + 'static, F: Fn(St, bool) + 'static,
{ {
self.disconnect = Some(Rc::new(disconnect)); self.disconnect = Some(Rc::new(disconnect));
self self
@ -175,7 +175,7 @@ where
pub struct FramedService<St, C, T, Io, Codec, Cfg> { pub struct FramedService<St, C, T, Io, Codec, Cfg> {
connect: C, connect: C,
handler: Rc<T>, handler: Rc<T>,
disconnect: Option<Rc<dyn Fn(&mut St, bool)>>, disconnect: Option<Rc<dyn Fn(St, bool)>>,
_t: PhantomData<(St, Io, Codec, Cfg)>, _t: PhantomData<(St, Io, Codec, Cfg)>,
} }
@ -232,7 +232,7 @@ where
pub struct FramedServiceImpl<St, C, T, Io, Codec> { pub struct FramedServiceImpl<St, C, T, Io, Codec> {
connect: C, connect: C,
handler: Rc<T>, handler: Rc<T>,
disconnect: Option<Rc<dyn Fn(&mut St, bool)>>, disconnect: Option<Rc<dyn Fn(St, bool)>>,
_t: PhantomData<(St, Io, Codec)>, _t: PhantomData<(St, Io, Codec)>,
} }
@ -359,13 +359,13 @@ where
Connect( Connect(
#[pin] C::Future, #[pin] C::Future,
Rc<T>, Rc<T>,
Option<Rc<dyn Fn(&mut St, bool)>>, Option<Rc<dyn Fn(St, bool)>>,
Option<mpsc::Receiver<ServiceResult<Codec, C::Error>>>, Option<mpsc::Receiver<ServiceResult<Codec, C::Error>>>,
), ),
Handler( Handler(
#[pin] T::Future, #[pin] T::Future,
Option<ConnectResult<Io, St, Codec>>, Option<ConnectResult<Io, St, Codec>>,
Option<Rc<dyn Fn(&mut St, bool)>>, Option<Rc<dyn Fn(St, bool)>>,
Option<mpsc::Receiver<ServiceResult<Codec, C::Error>>>, Option<mpsc::Receiver<ServiceResult<Codec, C::Error>>>,
), ),
Dispatcher(Dispatcher<St, T::Service, Io, Codec>), Dispatcher(Dispatcher<St, T::Service, Io, Codec>),