Crates.io | realm_io |
lib.rs | realm_io |
version | 0.5.1 |
source | src |
created_at | 2022-04-23 20:47:28.01806 |
updated_at | 2024-05-19 22:05:40.745133 |
description | Realm's high performance IO collections. |
homepage | |
repository | https://github.com/zhboner/realm |
max_upload_size | |
id | 572792 |
size | 40,883 |
Realm's high performance IO collections.
use tokio::net::TcpStream;
use realm_io::{bidi_copy, bidi_zero_copy, bidi_copy_buf};
use realm_io::{Pipe, CopyBuffer};
let mut left = TcpStream::connect("abc").await.unwrap();
let mut right = TcpStream::connect("def").await.unwrap();
// direct copy
bidi_copy(&mut left, &mut right).await;
// zero copy
bidi_zero_copy(&mut left, &mut right).await;
// use custom buffer(vector)
let buf1 = CopyBuffer::new(vec![0; 0x2000]);
let buf2 = CopyBuffer::new(vec![0; 0x2000]);
bidi_copy_buf(&mut left, &mut right, buf1, buf2).await;
// use custom buffer(pipe)
let buf1 = CopyBuffer::new(Pipe::new().unwrap());
let buf2 = CopyBuffer::new(Pipe::new().unwrap());
bidi_copy_buf(&mut left, &mut right, buf1, buf2).await;
By default, bidi_copy_buf
and other IO functions perform a graceful shutdown.
With the feature brutal-shutdown
enabled, these IO functions will decide to
perform a brutal shutdown once a FIN
packet reaches, which will forcefully
close two connections on both sides without waiting for a reply packet.
This is helpful when handling connections from a poorly implemented client or server, which may never shutdown its write side nor close the underlying socket.