pub struct Controller<E> { /* private fields */ }Expand description
A controller that can be used to interact with the receiver thread.
Implementations§
Source§impl<E> Controller<E>where
E: 'static,
impl<E> Controller<E>where
E: 'static,
Sourcepub fn signal_inspect(&mut self) -> Result<(), Error<E>>
Available on crate feature inspect only.
pub fn signal_inspect(&mut self) -> Result<(), Error<E>>
inspect only.Signal the receiver thread that it should call the
PacketHandler::inspect() callback.
This call is asynchronous with regards to the callback; the call may return to the caller before the receiver has received the request.
Examples found in repository?
36fn main() {
37 let args: Vec<String> = env::args().skip(1).collect();
38
39 let rt = RecvThread::new(&args[0]);
40
41 #[cfg(feature = "idle")]
42 let rt = rt.idle_duration(std::time::Duration::from_secs(4));
43
44 let pp = PktProc::default();
45
46 #[cfg(feature = "inspect")]
47 let mut ctrl = rt.run(pp).unwrap();
48
49 #[cfg(not(feature = "inspect"))]
50 let ctrl = rt.run(pp).unwrap();
51
52 std::thread::sleep(std::time::Duration::from_secs(10));
53
54 #[cfg(feature = "inspect")]
55 ctrl.signal_inspect().unwrap();
56
57 #[cfg(feature = "inspect")]
58 {
59 let stats = ctrl.inspect().unwrap();
60 println!("{stats:#?}");
61 }
62
63 std::thread::sleep(std::time::Duration::from_secs(30));
64
65 #[cfg(feature = "inspect")]
66 {
67 let stats = ctrl.inspect().unwrap();
68 println!("{stats:#?}");
69 }
70
71 println!("Killing receiver thread..");
72
73 ctrl.shutdown().unwrap();
74}Sourcepub fn inspect(&self) -> Result<RecvInfo, Error<E>>
Available on crate feature inspect only.
pub fn inspect(&self) -> Result<RecvInfo, Error<E>>
inspect only.Examples found in repository?
36fn main() {
37 let args: Vec<String> = env::args().skip(1).collect();
38
39 let rt = RecvThread::new(&args[0]);
40
41 #[cfg(feature = "idle")]
42 let rt = rt.idle_duration(std::time::Duration::from_secs(4));
43
44 let pp = PktProc::default();
45
46 #[cfg(feature = "inspect")]
47 let mut ctrl = rt.run(pp).unwrap();
48
49 #[cfg(not(feature = "inspect"))]
50 let ctrl = rt.run(pp).unwrap();
51
52 std::thread::sleep(std::time::Duration::from_secs(10));
53
54 #[cfg(feature = "inspect")]
55 ctrl.signal_inspect().unwrap();
56
57 #[cfg(feature = "inspect")]
58 {
59 let stats = ctrl.inspect().unwrap();
60 println!("{stats:#?}");
61 }
62
63 std::thread::sleep(std::time::Duration::from_secs(30));
64
65 #[cfg(feature = "inspect")]
66 {
67 let stats = ctrl.inspect().unwrap();
68 println!("{stats:#?}");
69 }
70
71 println!("Killing receiver thread..");
72
73 ctrl.shutdown().unwrap();
74}Sourcepub fn signal_shutdown(&self) -> Result<(), Error<E>>
pub fn signal_shutdown(&self) -> Result<(), Error<E>>
Signal receiver thread to terminate.
This call is asynchronous; at the time this function returns to the caller the termination request may not have reached the receiver thread.
A call to this method should be followed by a call to
Controller::wait() to wait for the receiver to report termination.
Sourcepub fn wait(self) -> Result<(), Error<E>>
pub fn wait(self) -> Result<(), Error<E>>
Wait for receiver to shut down.
Blocks the calling thread, and assumes that the receiver will be killed by another source.
Use Controller::signal_shutdown() to signal the receiver thread to
shut down before calling Controller::wait().
To avoid having the application need perform the two-stage shutdown, use
Controller::shutdown() instead.
Sourcepub fn shutdown(self) -> Result<(), Error<E>>
pub fn shutdown(self) -> Result<(), Error<E>>
Tell receiver thread to terminate and wait for for it to end.
Examples found in repository?
36fn main() {
37 let args: Vec<String> = env::args().skip(1).collect();
38
39 let rt = RecvThread::new(&args[0]);
40
41 #[cfg(feature = "idle")]
42 let rt = rt.idle_duration(std::time::Duration::from_secs(4));
43
44 let pp = PktProc::default();
45
46 #[cfg(feature = "inspect")]
47 let mut ctrl = rt.run(pp).unwrap();
48
49 #[cfg(not(feature = "inspect"))]
50 let ctrl = rt.run(pp).unwrap();
51
52 std::thread::sleep(std::time::Duration::from_secs(10));
53
54 #[cfg(feature = "inspect")]
55 ctrl.signal_inspect().unwrap();
56
57 #[cfg(feature = "inspect")]
58 {
59 let stats = ctrl.inspect().unwrap();
60 println!("{stats:#?}");
61 }
62
63 std::thread::sleep(std::time::Duration::from_secs(30));
64
65 #[cfg(feature = "inspect")]
66 {
67 let stats = ctrl.inspect().unwrap();
68 println!("{stats:#?}");
69 }
70
71 println!("Killing receiver thread..");
72
73 ctrl.shutdown().unwrap();
74}