Skip to content

tyrchen/async-io-helper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Async IO Helper

Boxed async IO for tokio client/server.

Usage:

Server:

let listener = TcpListener::bind(addr).await.unwrap();
tokio::spawn(async move {
    let (stream, _) = listener.accept().await.unwrap();
    let io = ServerIo::new(stream);
    info!("server: accepted: {:?}", io.remote_addr());
    let (mut reader, mut writer) = split(io);
    let mut buf = [0; 12];
    reader.read_exact(&mut buf).await.unwrap();
    info!("server: got data: {:?}", buf);
    writer.write_all(&buf).await.unwrap();
    info!("server: flush the data out");
});

Client:

let mut stream = TcpStream::connect(addr).await.unwrap();
info!("client: conn established");

stream.write_all(msg).await.unwrap();

info!("client: send data");

let (mut reader, _writer) = split(stream);

reader.read_exact(buf).await.unwrap();

info!("client: read echoed data");

License

async-io-helper is distributed under the terms of MIT.

See LICENSE for details.

Copyright 2021 Tyr Chen

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages