[−][src]Struct net2::TcpBuilder
An "in progress" TCP socket which has not yet been connected or listened.
Allows configuration of a socket before one of these operations is executed.
Methods
impl TcpBuilder
[src]
pub fn new_v4() -> Result<TcpBuilder>
[src]
Constructs a new TcpBuilder with the AF_INET
domain, the SOCK_STREAM
type, and with a protocol argument of 0.
Note that passing other kinds of flags or arguments can be done through
the FromRaw{Fd,Socket}
implementation.
pub fn new_v6() -> Result<TcpBuilder>
[src]
Constructs a new TcpBuilder with the AF_INET6
domain, the SOCK_STREAM
type, and with a protocol argument of 0.
Note that passing other kinds of flags or arguments can be done through
the FromRaw{Fd,Socket}
implementation.
pub fn bind<T>(&self, addr: T) -> Result<&TcpBuilder> where
T: ToSocketAddrs,
[src]
T: ToSocketAddrs,
Binds this socket to the specified address.
This function directly corresponds to the bind(2) function on Windows and Unix.
pub fn listen(&self, backlog: i32) -> Result<TcpListener>
[src]
Mark a socket as ready to accept incoming connection requests using accept()
This function directly corresponds to the listen(2) function on Windows and Unix.
An error will be returned if listen
or connect
has already been
called on this builder.
pub fn connect<T>(&self, addr: T) -> Result<TcpStream> where
T: ToSocketAddrs,
[src]
T: ToSocketAddrs,
Initiate a connection on this socket to the specified address.
This function directly corresponds to the connect(2) function on Windows and Unix.
An error will be returned if listen
or connect
has already been
called on this builder.
pub fn to_tcp_stream(&self) -> Result<TcpStream>
[src]
Converts this builder into a TcpStream
This function will consume the internal socket and return it re-wrapped
as a TcpStream
. An error will be returned if the internal socket has
already been consumed from a successful call to connect
, listen
,
etc.
pub fn to_tcp_listener(&self) -> Result<TcpListener>
[src]
Converts this builder into a TcpListener
This function will consume the internal socket and return it re-wrapped
as a TcpListener
. An error will be returned if the internal socket has
already been consumed from a successful call to connect
, listen
,
etc.
pub fn local_addr(&self) -> Result<SocketAddr>
[src]
Returns the address of the local half of this TCP socket.
An error will be returned if listen
or connect
has already been
called on this builder.
impl TcpBuilder
[src]
pub fn ttl(&self, ttl: u32) -> Result<&Self>
[src]
Sets the value for the IP_TTL
option on this socket.
This is the same as TcpStreamExt::set_ttl
.
pub fn only_v6(&self, only_v6: bool) -> Result<&Self>
[src]
Sets the value for the IPV6_V6ONLY
option on this socket.
This is the same as TcpStreamExt::set_only_v6
.
pub fn reuse_address(&self, reuse: bool) -> Result<&Self>
[src]
Set value for the SO_REUSEADDR
option on this socket.
This indicates that futher calls to bind
may allow reuse of local
addresses. For IPv4 sockets this means that a socket may bind even when
there's a socket already listening on this port.
pub fn get_reuse_address(&self) -> Result<bool>
[src]
Check the SO_REUSEADDR
option on this socket.
pub fn take_error(&self) -> Result<Option<Error>>
[src]
Get the value of the SO_ERROR
option on this socket.
This will retrieve the stored error in the underlying socket, clearing the field in the process. This can be useful for checking errors between calls.
Trait Implementations
impl UnixTcpBuilderExt for TcpBuilder
[src]
fn reuse_port(&self, reuse: bool) -> Result<&Self>
[src]
fn get_reuse_port(&self) -> Result<bool>
[src]
impl Debug for TcpBuilder
[src]
impl AsRawFd for TcpBuilder
[src]
impl FromRawFd for TcpBuilder
[src]
unsafe fn from_raw_fd(fd: c_int) -> TcpBuilder
[src]
Auto Trait Implementations
impl Send for TcpBuilder
impl Unpin for TcpBuilder
impl !Sync for TcpBuilder
impl UnwindSafe for TcpBuilder
impl !RefUnwindSafe for TcpBuilder
Blanket Implementations
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for T
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,