pub struct TcpListener(/* private fields */);Implementations§
Source§impl TcpListener
impl TcpListener
Sourcepub fn bind(addr: SocketAddr) -> Result<Self>
pub fn bind(addr: SocketAddr) -> Result<Self>
Examples found in repository?
examples/http1.rs (line 17)
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
async fn server() {
let addr = SERVER_SOCK_ADDR.parse().unwrap();
let listener = TcpListener::bind(addr).unwrap();
let mut accept = listener.accept();
while let Some(res) = accept.next().await {
// Spawn new task for the connection
asynk::spawn(async move {
// Accept the connection
let (stream, _) = res.unwrap();
if let Err(e) = http1::Builder::new()
.serve_connection(stream, service_fn(hello))
.await
{
eprintln!("error serving connection: {:?}", e);
}
});
}
}Sourcepub fn accept(self) -> Accept
pub fn accept(self) -> Accept
Examples found in repository?
examples/http1.rs (line 18)
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
async fn server() {
let addr = SERVER_SOCK_ADDR.parse().unwrap();
let listener = TcpListener::bind(addr).unwrap();
let mut accept = listener.accept();
while let Some(res) = accept.next().await {
// Spawn new task for the connection
asynk::spawn(async move {
// Accept the connection
let (stream, _) = res.unwrap();
if let Err(e) = http1::Builder::new()
.serve_connection(stream, service_fn(hello))
.await
{
eprintln!("error serving connection: {:?}", e);
}
});
}
}Auto Trait Implementations§
impl !Freeze for TcpListener
impl RefUnwindSafe for TcpListener
impl Send for TcpListener
impl Sync for TcpListener
impl Unpin for TcpListener
impl UnwindSafe for TcpListener
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