pub struct TcpHandle { /* private fields */ }
Expand description

TCP handles are used to represent both TCP streams and servers.

Implementations§

source§

impl TcpHandle

source

pub fn new(loop: &Loop) -> Result<TcpHandle>

Initialize the handle. No socket is created as of yet.

source

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().

source

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.

source

pub fn nodelay(&mut self, enable: bool) -> Result<()>

Enable TCP_NODELAY, which disables Nagle’s algorithm.

source

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.

source

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.

source

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.

source

pub fn getsockname(&self) -> Result<SocketAddr, Box<dyn Error>>

Get the current address to which the handle is bound.

source

pub fn getpeername(&self) -> Result<SocketAddr, Box<dyn Error>>

Get the address of the peer connected to the handle.

source

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.

source

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.

Trait Implementations§

source§

impl Clone for TcpHandle

source§

fn clone(&self) -> TcpHandle

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl From<TcpHandle> for Handle

source§

fn from(tcp: TcpHandle) -> Handle

Converts to this type from the input type.
source§

impl From<TcpHandle> for StreamHandle

source§

fn from(tcp: TcpHandle) -> StreamHandle

Converts to this type from the input type.
source§

impl HandleTrait for TcpHandle

source§

fn is_active(&self) -> bool

Returns non-zero if the handle is active, zero if it’s inactive. What “active” means depends on the type of handle: Read more
source§

fn is_closing(&self) -> bool

Returns non-zero if the handle is closing or closed, zero otherwise. Read more
source§

fn close<CB: Into<CloseCB<'static>>>(&mut self, cb: CB)

Request handle to be closed. close_cb will be called asynchronously after this call. This MUST be called on each handle before memory is released. Moreover, the memory can only be released in close_cb or after it has returned. Read more
source§

fn ref(&mut self)

Reference the given handle. References are idempotent, that is, if a handle is already referenced calling this function again will have no effect.
source§

fn unref(&mut self)

Un-reference the given handle. References are idempotent, that is, if a handle is not referenced calling this function again will have no effect.
source§

fn has_ref(&self) -> bool

Returns true if the handle referenced, zero otherwise.
source§

fn send_buffer_size(&mut self, value: i32) -> Result<i32>

Gets or sets the size of the send buffer that the operating system uses for the socket. Read more
source§

fn recv_buffer_size(&mut self, value: i32) -> Result<i32>

Gets or sets the size of the receive buffer that the operating system uses for the socket. Read more
source§

fn get_fileno(&self) -> Result<OsFile>

Gets the platform dependent file descriptor equivalent. Read more
source§

fn get_loop(&self) -> Loop

Returns the Loop associated with this handle.
source§

fn get_type(&self) -> HandleType

Returns the type of the handle.
source§

impl StreamTrait for TcpHandle

source§

fn shutdown<CB: Into<ShutdownCB<'static>>>( &mut self, cb: CB ) -> Result<ShutdownReq>

Shutdown the outgoing (write) side of a duplex stream. It waits for pending write requests to complete. The handle should refer to a initialized stream. The cb is called after shutdown is complete at which point the returned ShutdownReq is automatically destroy()’d.
source§

fn listen<CB: Into<ConnectionCB<'static>>>( &mut self, backlog: i32, cb: CB ) -> Result<()>

Start listening for incoming connections. backlog indicates the number of connections the kernel might queue, same as listen(2). When a new incoming connection is received the uv_connection_cb callback is called.
source§

fn accept(&mut self, client: &mut StreamHandle) -> Result<()>

This call is used in conjunction with listen() to accept incoming connections. Call this function after receiving the connection callback to accept the connection. Before calling this function the client handle must be initialized. Read more
source§

fn read_start<ACB: Into<AllocCB<'static>>, RCB: Into<ReadCB<'static>>>( &mut self, alloc_cb: ACB, read_cb: RCB ) -> Result<()>

Read data from an incoming stream. The read_cb callback will be made several times until there is no more data to read or read_stop() is called. Read more
source§

fn read_stop(&mut self) -> Result<()>

Stop reading data from the stream. The uv_read_cb callback will no longer be called. Read more
source§

fn write<CB: Into<WriteCB<'static>>>( &mut self, bufs: &[impl BufTrait], cb: CB ) -> Result<WriteReq>

Write data to stream. Buffers are written in order. Read more
source§

fn write2<CB: Into<WriteCB<'static>>>( &mut self, send_handle: &StreamHandle, bufs: &[impl BufTrait], cb: CB ) -> Result<WriteReq>

Extended write function for sending handles over a pipe. The pipe must be initialized with ipc == 1. Read more
source§

fn try_write(&mut self, bufs: &[impl BufTrait]) -> Result<i32>

Same as write(), but won’t queue a write request if it can’t be completed immediately. Read more
source§

fn try_write2( &mut self, send_handle: &StreamHandle, bufs: &[impl BufTrait] ) -> Result<i32>

Same as try_write() and extended write function for sending handles over a pipe like write2. Read more
source§

fn is_readable(&self) -> bool

Returns true if the stream is readable, false otherwise.
source§

fn is_writable(&self) -> bool

Returns true if the stream is writable, false otherwise.
source§

fn set_blocking(&mut self, blocking: bool) -> Result<()>

Enable or disable blocking mode for a stream. Read more
source§

fn get_write_queue_size(&self) -> usize

Returns the size of the write queue.
source§

impl ToHandle for TcpHandle

source§

impl ToStream for TcpHandle

source§

impl TryFrom<Handle> for TcpHandle

§

type Error = ConversionError

The type returned in the event of a conversion error.
source§

fn try_from(handle: Handle) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<StreamHandle> for TcpHandle

§

type Error = ConversionError

The type returned in the event of a conversion error.
source§

fn try_from(stream: StreamHandle) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl Copy for TcpHandle

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

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

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.