pub struct TcpHandle { /* private fields */ }
Expand description
TCP handles are used to represent both TCP streams and servers.
Implementations§
source§impl TcpHandle
impl TcpHandle
sourcepub fn new(loop: &Loop) -> Result<TcpHandle>
pub fn new(loop: &Loop) -> Result<TcpHandle>
Initialize the handle. No socket is created as of yet.
sourcepub fn new_ex(loop: &Loop, flags: TcpFlags) -> Result<TcpHandle>
pub fn new_ex(loop: &Loop, flags: TcpFlags) -> Result<TcpHandle>
Initialize the handle with the specified flags. A socket will be created for the given domain. If the specified domain is AF_UNSPEC no socket is created, just like new().
sourcepub fn open(&mut self, socket: Socket) -> Result<()>
pub fn open(&mut self, socket: Socket) -> Result<()>
Open an existing file descriptor or SOCKET as a TCP handle.
Changed in version 1.2.1: the file descriptor is set to non-blocking mode.
Note The passed file descriptor or SOCKET is not checked for its type, but it’s required that it represents a valid stream socket.
sourcepub fn nodelay(&mut self, enable: bool) -> Result<()>
pub fn nodelay(&mut self, enable: bool) -> Result<()>
Enable TCP_NODELAY, which disables Nagle’s algorithm.
sourcepub fn keepalive(&mut self, enable: bool, delay: u32) -> Result<()>
pub fn keepalive(&mut self, enable: bool, delay: u32) -> Result<()>
Enable / disable TCP keep-alive. delay is the initial delay in seconds, ignored when enable is zero.
After delay has been reached, 10 successive probes, each spaced 1 second from the previous one, will still happen. If the connection is still lost at the end of this procedure, then the handle is destroyed with a ETIMEDOUT error passed to the corresponding callback.
sourcepub fn simultaneous_accepts(&mut self, enable: bool) -> Result<()>
pub fn simultaneous_accepts(&mut self, enable: bool) -> Result<()>
Enable / disable simultaneous asynchronous accept requests that are queued by the operating system when listening for new TCP connections.
This setting is used to tune a TCP server for the desired performance. Having simultaneous accepts can significantly improve the rate of accepting connections (which is why it is enabled by default) but may lead to uneven load distribution in multi-process setups.
sourcepub fn bind(
&mut self,
addr: &SocketAddr,
flags: TcpBindFlags
) -> Result<(), Box<dyn Error>>
pub fn bind( &mut self, addr: &SocketAddr, flags: TcpBindFlags ) -> Result<(), Box<dyn Error>>
Bind the handle to an address and port.
When the port is already taken, you can expect to see an EADDRINUSE error from listen() or connect(). That is, a successful call to this function does not guarantee that the call to listen() or connect() will succeed as well.
flags can contain IPV6ONLY, in which case dual-stack support is disabled and only IPv6 is used.
sourcepub fn getsockname(&self) -> Result<SocketAddr, Box<dyn Error>>
pub fn getsockname(&self) -> Result<SocketAddr, Box<dyn Error>>
Get the current address to which the handle is bound.
sourcepub fn getpeername(&self) -> Result<SocketAddr, Box<dyn Error>>
pub fn getpeername(&self) -> Result<SocketAddr, Box<dyn Error>>
Get the address of the peer connected to the handle.
sourcepub fn connect<CB: Into<ConnectCB<'static>>>(
&mut self,
addr: &SocketAddr,
cb: CB
) -> Result<ConnectReq, Box<dyn Error>>
pub fn connect<CB: Into<ConnectCB<'static>>>( &mut self, addr: &SocketAddr, cb: CB ) -> Result<ConnectReq, Box<dyn Error>>
Establish an IPv4 or IPv6 TCP connection.
On Windows if the addr is initialized to point to an unspecified address (0.0.0.0 or ::) it will be changed to point to localhost. This is done to match the behavior of Linux systems.
The callback is made when the connection has been established or when a connection error happened.
sourcepub fn close_reset<CB: Into<CloseCB<'static>>>(&mut self, cb: CB) -> Result<()>
pub fn close_reset<CB: Into<CloseCB<'static>>>(&mut self, cb: CB) -> Result<()>
Resets a TCP connection by sending a RST packet. This is accomplished by setting the SO_LINGER socket option with a linger interval of zero and then calling close(). Due to some platform inconsistencies, mixing of shutdown() and close_reset() calls is not allowed.