pub struct BufConnection<C: ?Sized> { /* private fields */ }
Expand description

A wrapper around a Connection that buffers all of the I/O.

System calls for I/O are expensive, while reading to and writing from memory is not. This type aims to provide a simple wrapper around a Connection that buffers all of the I/O. It serves a similar purpose to BufReader and BufWriter, but for Connections.

If the Connection is already in memory, then BufReader serves no purpose. In addition, programs that make larger reads/writes tend to lose the advantage of buffering. However, smaller, more frequent reads are common in X11, so this type is useful in general.

Example

use breadx::connection::{BufConnection, Connection, StdConnection};
use std::net::TcpStream;

// create a connection that isn't buffered
let socket = TcpStream::connect("localhost:6000")?;
let connection = StdConnection::new(socket);

// create a connection that is buffered
let mut connection = BufConnection::new(connection);

let (mut buf1, mut buf2) = ([0u8; 16], [0u8; 16]);

// these two reads would normally result in two syscalls
// however, with buffering, only one syscall occurs
connection.recv_slice(&mut buf1)?;
connection.recv_slice(&mut buf2)?;

Implementations

Create a new BufConnection from a given connection.

Example
use breadx::connection::{BufConnection, Connection, StdConnection};
use std::net::TcpStream;

let socket = TcpStream::connect("localhost:6000")?;
let connection = StdConnection::new(socket);
let connection = BufConnection::new(connection);

Create a new BufConnection from a given connection, with the given read and write capacities.

This can be useful if you expect your program to use different amounts of read and write data than normal ones do.

Example
use breadx::connection::{BufConnection, Connection, StdConnection};
use std::net::TcpStream;

let socket = TcpStream::connect("localhost:6000")?;
let connection = StdConnection::new(socket);
let connection = BufConnection::with_capacity(1024, 2048, connection);

Trait Implementations

Converts this type into a mutable reference of the (usually inferred) input type.

Extracts the raw file descriptor. Read more

Converts this type into a shared reference of the (usually inferred) input type.

Read data to a series of I/O slices and a buffer for file descriptors. Read more

Read data to a single I/O slice and a buffer for file descriptors. Read more

Read data for a single I/O slice. Read more

Receive data from the X11 server into a set of I/O slices, in a non-blocking manner. Read more

Receive data from the X11 server into a single slice, in a non-blocking manner. Read more

Write a series of I/O slices and a series of file descriptors to the X11 server. Read more

Write a series of I/O slices to the X11 server. Read more

Write a slice of data to the X11 server. Read more

Flush all data in this connection’s buffer. Read more

Shutdown this connection. Read more

Converts to this type from the input type.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Converts to this type from the input type.

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more