Struct breadx::connection::BufConnection
source · [−]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 Connection
s.
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
sourceimpl<C> BufConnection<C>
impl<C> BufConnection<C>
sourcepub fn new(conn: C) -> Self
pub fn new(conn: C) -> Self
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);
sourcepub fn with_capacity(
read_capacity: usize,
write_capacity: usize,
conn: C
) -> Self
pub fn with_capacity(
read_capacity: usize,
write_capacity: usize,
conn: C
) -> Self
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
sourceimpl<C: ?Sized> AsMut<C> for BufConnection<C>
impl<C: ?Sized> AsMut<C> for BufConnection<C>
sourceimpl<C: AsRawFd + ?Sized> AsRawFd for BufConnection<C>
impl<C: AsRawFd + ?Sized> AsRawFd for BufConnection<C>
sourceimpl<C: ?Sized> AsRef<C> for BufConnection<C>
impl<C: ?Sized> AsRef<C> for BufConnection<C>
sourceimpl<Conn: Connection + ?Sized> Connection for BufConnection<Conn>
impl<Conn: Connection + ?Sized> Connection for BufConnection<Conn>
sourcefn recv_slices_and_fds(
&mut self,
slices: &mut [IoSliceMut<'_>],
fds: &mut Vec<Fd>
) -> Result<usize>
fn recv_slices_and_fds(
&mut self,
slices: &mut [IoSliceMut<'_>],
fds: &mut Vec<Fd>
) -> Result<usize>
Read data to a series of I/O slices and a buffer for file descriptors. Read more
sourcefn recv_slice_and_fds(
&mut self,
slice: &mut [u8],
fds: &mut Vec<Fd>
) -> Result<usize>
fn recv_slice_and_fds(
&mut self,
slice: &mut [u8],
fds: &mut Vec<Fd>
) -> Result<usize>
Read data to a single I/O slice and a buffer for file descriptors. Read more
sourcefn recv_slice(&mut self, slice: &mut [u8]) -> Result<usize>
fn recv_slice(&mut self, slice: &mut [u8]) -> Result<usize>
Read data for a single I/O slice. Read more
sourcefn non_blocking_recv_slices_and_fds(
&mut self,
slices: &mut [IoSliceMut<'_>],
fds: &mut Vec<Fd>
) -> Result<usize>
fn non_blocking_recv_slices_and_fds(
&mut self,
slices: &mut [IoSliceMut<'_>],
fds: &mut Vec<Fd>
) -> Result<usize>
Receive data from the X11 server into a set of I/O slices, in a non-blocking manner. Read more
sourcefn non_blocking_recv_slice_and_fds(
&mut self,
slice: &mut [u8],
fds: &mut Vec<Fd>
) -> Result<usize>
fn non_blocking_recv_slice_and_fds(
&mut self,
slice: &mut [u8],
fds: &mut Vec<Fd>
) -> Result<usize>
Receive data from the X11 server into a single slice, in a non-blocking manner. Read more
sourcefn send_slices_and_fds(
&mut self,
slices: &[IoSlice<'_>],
fds: &mut Vec<Fd>
) -> Result<usize>
fn send_slices_and_fds(
&mut self,
slices: &[IoSlice<'_>],
fds: &mut Vec<Fd>
) -> Result<usize>
Write a series of I/O slices and a series of file descriptors to the X11 server. Read more
sourcefn send_slices(&mut self, slices: &[IoSlice<'_>]) -> Result<usize>
fn send_slices(&mut self, slices: &[IoSlice<'_>]) -> Result<usize>
Write a series of I/O slices to the X11 server. Read more
sourceimpl<C> From<C> for BufConnection<C>
impl<C> From<C> for BufConnection<C>
Auto Trait Implementations
impl<C: ?Sized> RefUnwindSafe for BufConnection<C> where
C: RefUnwindSafe,
impl<C: ?Sized> Send for BufConnection<C> where
C: Send,
impl<C: ?Sized> Sync for BufConnection<C> where
C: Sync,
impl<C: ?Sized> Unpin for BufConnection<C> where
C: Unpin,
impl<C: ?Sized> UnwindSafe for BufConnection<C> where
C: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more