[−][src]Trait roa_tcp::Listener
An app extension.
Associated Types
type Server
http server
Required methods
fn bind(self, addr: impl ToSocketAddrs) -> Result<(SocketAddr, Self::Server)>
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>
Listen on a socket addr, return a server, and pass real addr to the callback.
fn run(self) -> Result<(SocketAddr, Self::Server)>
Listen on an unused port of 127.0.0.1, return a server and the real addr it binds.
Example
use roa_core::{App, Context, Error}; use roa_tcp::Listener; use roa_core::http::StatusCode; use async_std::task::spawn; use std::time::Instant; async fn end(_ctx: &mut Context<()>) -> Result<(), Error> { 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(()) }
Implementations on Foreign Types
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>
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>