pub struct Handle { /* private fields */ }Expand description
A server running in the background, from Server::spawn. Stopping it
(or dropping it) stops accepting connections and ends every session.
Implementations§
Source§impl Handle
impl Handle
Sourcepub fn local_addr(&self) -> SocketAddr
pub fn local_addr(&self) -> SocketAddr
The address the server listens on.
Sourcepub fn url(&self) -> &str
pub fn url(&self) -> &str
The address to open in a browser, with the token.
Examples found in repository?
examples/session_probe.rs (line 98)
65fn main() -> std::io::Result<()> {
66 let mut args = std::env::args().skip(1);
67 let mut addr = "127.0.0.1:8080".to_string();
68 let mut token = None;
69 let mut startup = None;
70 let mut stdin_stop = false;
71 let mut nested = false;
72 while let Some(arg) = args.next() {
73 let mut value = || args.next().expect("a value after the option");
74 match arg.as_str() {
75 "--token" => token = Some(value()),
76 "--startup-sleep" => startup = Some(value().parse::<u64>().expect("ms")),
77 "--stdin-stop" => stdin_stop = true,
78 "--nested" => nested = true,
79 _ => addr = arg,
80 }
81 }
82 if nested {
83 // An unrelated program that serves an app: it should get the
84 // address it asked for.
85 let server = rich_web::Server::bind(addr.as_str(), app)?;
86 println!("BOUND {}", server.local_addr());
87 return Ok(());
88 }
89 if let (Some(ms), true) = (startup, std::env::var_os(rich_web::SESSION_ENV).is_some()) {
90 std::thread::sleep(Duration::from_millis(ms));
91 }
92 let mut server = rich_web::Server::bind(addr.as_str(), app)?.title("session probe");
93 if let Some(token) = token {
94 server = server.token(token);
95 }
96 if stdin_stop {
97 let handle = server.spawn()?;
98 println!("Serving session probe at {}", handle.url());
99 let mut line = String::new();
100 std::io::stdin().lock().read_line(&mut line)?;
101 let started = Instant::now();
102 handle.stop();
103 println!("STOPPED {}", started.elapsed().as_millis());
104 return Ok(());
105 }
106 server.run()
107}Sourcepub fn stop(self)
pub fn stop(self)
Stop: no more connections, and every session ends (within one turn
of its loop, at most 50 ms). A program’s session ends its program:
it is hung up on, and a LocalPty’s is killed, with its process
group, if it is still running a second later. This returns once
every program has ended; a connection still sending its request is
not served.
Examples found in repository?
examples/session_probe.rs (line 102)
65fn main() -> std::io::Result<()> {
66 let mut args = std::env::args().skip(1);
67 let mut addr = "127.0.0.1:8080".to_string();
68 let mut token = None;
69 let mut startup = None;
70 let mut stdin_stop = false;
71 let mut nested = false;
72 while let Some(arg) = args.next() {
73 let mut value = || args.next().expect("a value after the option");
74 match arg.as_str() {
75 "--token" => token = Some(value()),
76 "--startup-sleep" => startup = Some(value().parse::<u64>().expect("ms")),
77 "--stdin-stop" => stdin_stop = true,
78 "--nested" => nested = true,
79 _ => addr = arg,
80 }
81 }
82 if nested {
83 // An unrelated program that serves an app: it should get the
84 // address it asked for.
85 let server = rich_web::Server::bind(addr.as_str(), app)?;
86 println!("BOUND {}", server.local_addr());
87 return Ok(());
88 }
89 if let (Some(ms), true) = (startup, std::env::var_os(rich_web::SESSION_ENV).is_some()) {
90 std::thread::sleep(Duration::from_millis(ms));
91 }
92 let mut server = rich_web::Server::bind(addr.as_str(), app)?.title("session probe");
93 if let Some(token) = token {
94 server = server.token(token);
95 }
96 if stdin_stop {
97 let handle = server.spawn()?;
98 println!("Serving session probe at {}", handle.url());
99 let mut line = String::new();
100 std::io::stdin().lock().read_line(&mut line)?;
101 let started = Instant::now();
102 handle.stop();
103 println!("STOPPED {}", started.elapsed().as_millis());
104 return Ok(());
105 }
106 server.run()
107}Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Handle
impl !UnwindSafe for Handle
impl Freeze for Handle
impl Send for Handle
impl Sync for Handle
impl Unpin for Handle
impl UnsafeUnpin for Handle
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.