[−][src]Trait roa::tcp::Listener
This is supported on
feature="tcp"
only.An app extension.
Associated Types
Loading content...Required methods
fn bind(self, addr: impl ToSocketAddrs) -> Result<(SocketAddr, Self::Server)>
This is supported on
feature="tcp"
only.Listen on a socket addr, return a server and the real addr it binds.
fn listen(
self,
addr: impl ToSocketAddrs,
callback: impl Fn(SocketAddr)
) -> Result<Self::Server>
self,
addr: impl ToSocketAddrs,
callback: impl Fn(SocketAddr)
) -> Result<Self::Server>
This is supported on
feature="tcp"
only.Listen on a socket addr, return a server, and pass real addr to the callback.
fn run(self) -> Result<(SocketAddr, Self::Server)>
This is supported on
feature="tcp"
only.Listen on an unused port of 127.0.0.1, return a server and the real addr it binds.
Example
use roa::{App, Context, Status}; use roa::tcp::Listener; use roa::http::StatusCode; use async_std::task::spawn; use std::time::Instant; async fn end(_ctx: &mut Context) -> Result<(), Status> { Ok(()) } #[tokio::main] async fn main() -> Result<(), Box<dyn std::error::Error>> { let (addr, server) = App::new().end(end).run()?; spawn(server); let resp = reqwest::get(&format!("http://{}", addr)).await?; assert_eq!(StatusCode::OK, resp.status()); Ok(()) }
Implementors
impl<S, E> Listener for App<S, Arc<E>> where
S: State,
E: for<'a> Endpoint<'a, S>,
[src]
S: State,
E: for<'a> Endpoint<'a, S>,
type Server = Server<TcpIncoming, Self, Executor>
This is supported on
feature="tcp"
only.fn bind(self, addr: impl ToSocketAddrs) -> Result<(SocketAddr, Self::Server)>
[src]
fn listen(
self,
addr: impl ToSocketAddrs,
callback: impl Fn(SocketAddr)
) -> Result<Self::Server>
[src]
self,
addr: impl ToSocketAddrs,
callback: impl Fn(SocketAddr)
) -> Result<Self::Server>