Crate realm_io

Source
Expand description

Realm’s high performance IO collections.

§Example

async {
    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(AsMut<[u8]>)
    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 or &mut 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;
};

§About Brutal Shutdown

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.

Modules§

mmsgLinux
Mmsg impl.
peekpeek
Peek impl.
statisticstatistic
Statistic impl.

Macros§

delegate_impl
Impl AsyncRawIO, delegates to required functions.

Structs§

CopyBuffer
A wrapper of its underlying buffer(array, vector, unix pipe…).
PipeLinux
Unix pipe.

Traits§

AsyncIOBuf
Type traits of CopyBuffer.
AsyncRawIOLinux
Type traits of Linux objects.

Functions§

bidi_copy
Copy data bidirectionally between two streams with userspace buffer.
bidi_copy_buf
Copy data bidirectionally between two streams with provided buffer.
bidi_zero_copyLinux
Copy data bidirectionally between two streams with pipe.
buf_size
Get current buffer size.
pipe_sizeLinux
Get pipe capacity.
set_buf_size
Set current buffer size.
set_pipe_sizeLinux
Set pipe capacity.