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