Struct glommio::net::TcpStream [−][src]
pub struct TcpStream { /* fields omitted */ }
Expand description
A Tcp Stream of bytes. This can be used with AsyncRead
, AsyncBufRead
and
AsyncWrite
Implementations
Creates a TCP connection to the specified address.
Examples
use glommio::{net::TcpStream, LocalExecutor};
let ex = LocalExecutor::default();
ex.run(async move {
TcpStream::connect("127.0.0.1:10000").await.unwrap();
})
Sets the read timeout to the timeout specified.
If the value specified is None
, then read calls will block
indefinitely. An Err
is returned if the zero Duration
is
passed to this method.
Examples
let stream = TcpStream::connect("127.0.0.1:10000").await.unwrap();
stream
.set_read_timeout(Some(Duration::from_secs(1)))
.unwrap();
Sets the write timeout to the timeout specified.
If the value specified is None
, then write calls will block
indefinitely. An Err
is returned if the zero Duration
is
passed to this method.
let stream = TcpStream::connect("127.0.0.1:10000").await.unwrap();
stream
.set_write_timeout(Some(Duration::from_secs(1)))
.unwrap();
Returns the read timeout of this socket.
Returns the write timeout of this socket.
pub async fn connect_timeout<A: ToSocketAddrs>(
addr: A,
duration: Duration
) -> Result<TcpStream, ()>
pub async fn connect_timeout<A: ToSocketAddrs>(
addr: A,
duration: Duration
) -> Result<TcpStream, ()>
Creates a TCP connection to the specified address with a timeout.
It is an error to pass a zero Duration
to this function.
Timeouts are implemented using io_uring
’s IORING_OP_LINK_TIMEOUT
.
Examples
use glommio::{net::TcpStream, LocalExecutor};
use std::time::Duration;
let ex = LocalExecutor::default();
ex.run(async move {
TcpStream::connect_timeout("127.0.0.1:10000", Duration::from_secs(10))
.await
.unwrap();
})
Shuts down the read, write, or both halves of this connection.
Sets the value of the TCP_NODELAY
option on this socket.
If set, this option disables the Nagle algorithm. This means that segments are always sent as soon as possible, even if there is only a small amount of data. When not set, data is buffered until there is a sufficient amount to send out, thereby avoiding the frequent sending of small packets.
Examples
use glommio::{net::TcpStream, LocalExecutor};
let ex = LocalExecutor::default();
ex.run(async move {
let stream = TcpStream::connect("127.0.0.1:10000").await.unwrap();
stream.set_nodelay(true).expect("set_nodelay call failed");
});
Gets the TCP_NODELAY
option on this socket.
For more information about this option, see TcpStream::set_nodelay
.
Examples
use glommio::{net::TcpStream, LocalExecutor};
let ex = LocalExecutor::default();
ex.run(async move {
let stream = TcpStream::connect("127.0.0.1:10000").await.unwrap();
stream.set_nodelay(true).expect("set_nodelay call failed");
assert_eq!(stream.nodelay().unwrap(), true);
});
Sets the buffer size used on the receive path
gets the buffer size used
Gets the value of the IP_TTL
option for this socket.
This option configures the time-to-live field that is used in every packet sent from this socket.
Examples
use glommio::{net::TcpStream, LocalExecutor};
let ex = LocalExecutor::default();
ex.run(async move {
let stream = TcpStream::connect("127.0.0.1:10000").await.unwrap();
stream.set_ttl(100).expect("could not set TTL");
assert_eq!(stream.ttl().unwrap(), 100);
});
Sets the value of the IP_TTL
option for this socket.
This option configures the time-to-live field that is used in every packet sent from this socket.
Examples
use glommio::{net::TcpStream, LocalExecutor};
let ex = LocalExecutor::default();
ex.run(async move {
let stream = TcpStream::connect("127.0.0.1:10000").await.unwrap();
stream.set_ttl(100).expect("could not set TTL");
assert_eq!(stream.ttl().unwrap(), 100);
});
Receives data on the socket from the remote address to which it is connected, without removing that data from the queue.
On success, returns the number of bytes peeked. Successive calls return the same data. This is accomplished by passing MSG_PEEK as a flag to the underlying recv system call.
Returns the socket address of the remote peer of this TCP connection.
Examples
use glommio::{net::TcpStream, LocalExecutor};
let ex = LocalExecutor::default();
ex.run(async move {
let stream = TcpStream::connect("127.0.0.1:10000").await.unwrap();
println!("My peer: {:?}", stream.peer_addr());
})
Returns the socket address of the local half of this TCP connection.
Examples
use glommio::{net::TcpStream, LocalExecutor};
let ex = LocalExecutor::default();
ex.run(async move {
let stream = TcpStream::connect("127.0.0.1:10000").await.unwrap();
println!("My peer: {:?}", stream.local_addr());
})
Trait Implementations
Attempt to return the contents of the internal buffer, filling it with more data from the inner reader if it is empty. Read more
Attempt to read from the AsyncRead
into buf
. Read more
Constructs a new instance of Self
from the given raw file
descriptor. Read more
Auto Trait Implementations
impl !RefUnwindSafe for TcpStream
impl !UnwindSafe for TcpStream
Blanket Implementations
Returns the contents of the internal buffer, filling it with more data if empty. Read more
fn read_until(
&'a mut self,
byte: u8,
buf: &'a mut Vec<u8, Global>
) -> ReadUntilFuture<'a, Self> where
Self: Unpin,
fn read_until(
&'a mut self,
byte: u8,
buf: &'a mut Vec<u8, Global>
) -> ReadUntilFuture<'a, Self> where
Self: Unpin,
Reads all bytes and appends them into buf
until the delimiter byte
or EOF is found. Read more
Reads all bytes and appends them into buf
until a newline (the 0xA byte) or EOF is found. Read more
Returns a stream over the lines of this byte stream. Read more
Reads some bytes from the byte stream. Read more
fn read_vectored(
&'a mut self,
bufs: &'a mut [IoSliceMut<'a>]
) -> ReadVectoredFuture<'a, Self> where
Self: Unpin,
fn read_vectored(
&'a mut self,
bufs: &'a mut [IoSliceMut<'a>]
) -> ReadVectoredFuture<'a, Self> where
Self: Unpin,
fn read_to_end(
&'a mut self,
buf: &'a mut Vec<u8, Global>
) -> ReadToEndFuture<'a, Self> where
Self: Unpin,
fn read_to_end(
&'a mut self,
buf: &'a mut Vec<u8, Global>
) -> ReadToEndFuture<'a, Self> where
Self: Unpin,
fn read_to_string(
&'a mut self,
buf: &'a mut String
) -> ReadToStringFuture<'a, Self> where
Self: Unpin,
fn read_to_string(
&'a mut self,
buf: &'a mut String
) -> ReadToStringFuture<'a, Self> where
Self: Unpin,
Reads the exact number of bytes required to fill buf
. Read more
Creates an adapter which will read at most limit
bytes from it. Read more
Creates an adapter which will chain this stream with another. Read more
Writes some bytes into the byte stream. Read more
fn write_vectored(
&'a mut self,
bufs: &'a [IoSlice<'a>]
) -> WriteVectoredFuture<'a, Self> where
Self: Unpin,
fn write_vectored(
&'a mut self,
bufs: &'a [IoSlice<'a>]
) -> WriteVectoredFuture<'a, Self> where
Self: Unpin,
Writes an entire buffer into the byte stream. Read more
Flushes the stream to ensure that all buffered contents reach their destination. Read more
Closes the writer. Read more
Mutably borrows from an owned value. Read more
Instruments this type with the provided Span
, returning an
Instrumented
wrapper. Read more
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