mirror of https://github.com/stjepang/smol
More explicit examples
This commit is contained in:
parent
e66cb48ec9
commit
ba4c816545
|
@ -6,6 +6,8 @@
|
|||
//! $ nc localhost 8080
|
||||
//! ```
|
||||
|
||||
use std::net::TcpStream;
|
||||
|
||||
use futures::executor::block_on;
|
||||
use futures::io;
|
||||
use futures::prelude::*;
|
||||
|
@ -13,7 +15,7 @@ use smol::Async;
|
|||
|
||||
fn main() -> io::Result<()> {
|
||||
block_on(async {
|
||||
let mut stream = Async::connect("www.example.com:80").await?;
|
||||
let mut stream = Async::<TcpStream>::connect("www.example.com:80").await?;
|
||||
stream
|
||||
.write_all(b"GET / HTTP/1.0\r\nHost: example.com\r\n\r\n")
|
||||
.await?;
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
//! $ nc localhost 8080
|
||||
//! ```
|
||||
|
||||
use std::net::TcpStream;
|
||||
use std::net::{TcpListener, TcpStream};
|
||||
|
||||
use futures::executor::block_on;
|
||||
use futures::io;
|
||||
|
@ -14,12 +14,13 @@ use smol::Async;
|
|||
|
||||
async fn process(mut stream: Async<TcpStream>) -> io::Result<()> {
|
||||
println!("Peer: {}", stream.source().peer_addr()?);
|
||||
io::copy(stream.clone(), &mut stream).await
|
||||
io::copy(stream.clone(), &mut stream).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn main() -> io::Result<()> {
|
||||
block_on(async {
|
||||
let listener = Async::bind("127.0.0.1:8080")?;
|
||||
let listener = Async::<TcpListener>::bind("127.0.0.1:8080")?;
|
||||
println!("Local: {}", listener.source().local_addr()?);
|
||||
|
||||
loop {
|
||||
|
|
Loading…
Reference in New Issue