Struct nex_socket::AsyncSocket
source · pub struct AsyncSocket { /* private fields */ }Expand description
Async socket. Provides cross-platform async adapter for system socket.
Implementations§
source§impl AsyncSocket
impl AsyncSocket
sourcepub fn new(socket_option: SocketOption) -> Result<AsyncSocket>
pub fn new(socket_option: SocketOption) -> Result<AsyncSocket>
Constructs a new AsyncSocket.
sourcepub async fn new_with_async_connect(addr: &SocketAddr) -> Result<AsyncSocket>
pub async fn new_with_async_connect(addr: &SocketAddr) -> Result<AsyncSocket>
Constructs a new AsyncSocket with async non-blocking TCP connect.
sourcepub async fn new_with_async_connect_timeout(
addr: &SocketAddr,
timeout: Duration,
) -> Result<AsyncSocket>
pub async fn new_with_async_connect_timeout( addr: &SocketAddr, timeout: Duration, ) -> Result<AsyncSocket>
Constructs a new AsyncSocket with async non-blocking TCP connect and timeout.
sourcepub fn new_with_connect(
socket_option: SocketOption,
addr: &SocketAddr,
) -> Result<AsyncSocket>
pub fn new_with_connect( socket_option: SocketOption, addr: &SocketAddr, ) -> Result<AsyncSocket>
Constructs a new AsyncSocket with TCP connect.
If you want to async non-blocking connect, use new_with_async_connect instead.
sourcepub fn new_with_connect_timeout(
socket_option: SocketOption,
addr: &SocketAddr,
timeout: Duration,
) -> Result<AsyncSocket>
pub fn new_with_connect_timeout( socket_option: SocketOption, addr: &SocketAddr, timeout: Duration, ) -> Result<AsyncSocket>
Constructs a new AsyncSocket with TCP connect and timeout.
If you want to async non-blocking connect, use new_with_async_connect_timeout instead.
sourcepub fn new_with_listener(
socket_option: SocketOption,
addr: &SocketAddr,
) -> Result<AsyncSocket>
pub fn new_with_listener( socket_option: SocketOption, addr: &SocketAddr, ) -> Result<AsyncSocket>
Constructs a new AsyncSocket with listener.
sourcepub fn new_with_bind(
socket_option: SocketOption,
addr: &SocketAddr,
) -> Result<AsyncSocket>
pub fn new_with_bind( socket_option: SocketOption, addr: &SocketAddr, ) -> Result<AsyncSocket>
Constructs a new AsyncSocket with bind.
sourcepub fn from_tcp_stream(tcp_stream: TcpStream) -> Result<AsyncSocket>
pub fn from_tcp_stream(tcp_stream: TcpStream) -> Result<AsyncSocket>
Constructs a new AsyncSocket from TcpStream. Async Socket does not support non-blocking connect. Use TCP Stream to connect to the target.
sourcepub fn from_tcp_listener(tcp_listener: TcpListener) -> Result<AsyncSocket>
pub fn from_tcp_listener(tcp_listener: TcpListener) -> Result<AsyncSocket>
Constructs a new AsyncSocket from TcpListener.
sourcepub fn from_udp_socket(udp_socket: UdpSocket) -> Result<AsyncSocket>
pub fn from_udp_socket(udp_socket: UdpSocket) -> Result<AsyncSocket>
Constructs a new AsyncSocket from UdpSocket.
sourcepub async fn bind(&self, addr: SocketAddr) -> Result<()>
pub async fn bind(&self, addr: SocketAddr) -> Result<()>
Bind socket to address.
sourcepub async fn send_to(&self, buf: &[u8], target: SocketAddr) -> Result<usize>
pub async fn send_to(&self, buf: &[u8], target: SocketAddr) -> Result<usize>
Send packet to target.
sourcepub async fn receive_from(
&self,
buf: &mut Vec<u8>,
) -> Result<(usize, SocketAddr)>
pub async fn receive_from( &self, buf: &mut Vec<u8>, ) -> Result<(usize, SocketAddr)>
Receive packet with sender address.
sourcepub async fn write(&self, buf: &[u8]) -> Result<usize>
pub async fn write(&self, buf: &[u8]) -> Result<usize>
Write data to the socket and send to the target. Return how many bytes were written.
sourcepub async fn write_timeout(
&self,
buf: &[u8],
timeout: Duration,
) -> Result<usize>
pub async fn write_timeout( &self, buf: &[u8], timeout: Duration, ) -> Result<usize>
Write data with timeout. Return how many bytes were written.
sourcepub async fn read(&self, buf: &mut Vec<u8>) -> Result<usize>
pub async fn read(&self, buf: &mut Vec<u8>) -> Result<usize>
Read data from the socket. Return how many bytes were read.
sourcepub async fn read_timeout(
&self,
buf: &mut Vec<u8>,
timeout: Duration,
) -> Result<usize>
pub async fn read_timeout( &self, buf: &mut Vec<u8>, timeout: Duration, ) -> Result<usize>
Read data with timeout. Return how many bytes were read.
sourcepub async fn set_ttl(&self, ttl: u32, ip_version: IpVersion) -> Result<()>
pub async fn set_ttl(&self, ttl: u32, ip_version: IpVersion) -> Result<()>
Set TTL or Hop Limit.
sourcepub async fn set_tos(&self, tos: u32) -> Result<()>
pub async fn set_tos(&self, tos: u32) -> Result<()>
Set the value of the IP_TOS option for this socket.
sourcepub async fn receive_tos(&self) -> Result<bool>
pub async fn receive_tos(&self) -> Result<bool>
Get the value of the IP_RECVTOS option for this socket.
sourcepub async fn set_receive_tos(&self, receive_tos: bool) -> Result<()>
pub async fn set_receive_tos(&self, receive_tos: bool) -> Result<()>
Set the value of the IP_RECVTOS option for this socket.
sourcepub async fn connect(&mut self, addr: &SocketAddr) -> Result<()>
pub async fn connect(&mut self, addr: &SocketAddr) -> Result<()>
Initiate TCP connection.
sourcepub async fn connect_timeout(
&self,
addr: &SocketAddr,
timeout: Duration,
) -> Result<()>
pub async fn connect_timeout( &self, addr: &SocketAddr, timeout: Duration, ) -> Result<()>
Initiate a connection on this socket to the specified address, only only waiting for a certain period of time for the connection to be established. The non-blocking state of the socket is overridden by this function.
sourcepub async fn accept(&self) -> Result<(AsyncSocket, SocketAddr)>
pub async fn accept(&self) -> Result<(AsyncSocket, SocketAddr)>
Accept TCP connection.
sourcepub async fn local_addr(&self) -> Result<SocketAddr>
pub async fn local_addr(&self) -> Result<SocketAddr>
Get local address.
sourcepub async fn peer_addr(&self) -> Result<SocketAddr>
pub async fn peer_addr(&self) -> Result<SocketAddr>
Get peer address.
sourcepub async fn socket_type(&self) -> Result<SocketType>
pub async fn socket_type(&self) -> Result<SocketType>
Get type of the socket.
sourcepub async fn try_clone(&self) -> Result<AsyncSocket>
pub async fn try_clone(&self) -> Result<AsyncSocket>
Create a new socket with the same configuration and bound to the same address.
sourcepub async fn is_nonblocking(&self) -> Result<bool>
pub async fn is_nonblocking(&self) -> Result<bool>
Returns true if this socket is set to nonblocking mode, false otherwise.
sourcepub async fn set_nonblocking(&self, nonblocking: bool) -> Result<()>
pub async fn set_nonblocking(&self, nonblocking: bool) -> Result<()>
Set non-blocking mode.
sourcepub async fn is_broadcast(&self) -> Result<bool>
pub async fn is_broadcast(&self) -> Result<bool>
Get the value of the SO_BROADCAST option for this socket.
sourcepub async fn set_broadcast(&self, broadcast: bool) -> Result<()>
pub async fn set_broadcast(&self, broadcast: bool) -> Result<()>
Set the value of the SO_BROADCAST option for this socket.
When enabled, this socket is allowed to send packets to a broadcast address.
sourcepub async fn get_error(&self) -> Result<Option<Error>>
pub async fn get_error(&self) -> Result<Option<Error>>
Get the value of the SO_ERROR option on this socket.
sourcepub async fn is_keepalive(&self) -> Result<bool>
pub async fn is_keepalive(&self) -> Result<bool>
Get the value of the SO_KEEPALIVE option on this socket.
sourcepub async fn set_keepalive(&self, keepalive: bool) -> Result<()>
pub async fn set_keepalive(&self, keepalive: bool) -> Result<()>
Set value for the SO_KEEPALIVE option on this socket.
Enable sending of keep-alive messages on connection-oriented sockets.
sourcepub async fn linger(&self) -> Result<Option<Duration>>
pub async fn linger(&self) -> Result<Option<Duration>>
Get the value of the SO_LINGER option on this socket.
sourcepub async fn set_linger(&self, dur: Option<Duration>) -> Result<()>
pub async fn set_linger(&self, dur: Option<Duration>) -> Result<()>
Set value for the SO_LINGER option on this socket.
sourcepub async fn receive_buffer_size(&self) -> Result<usize>
pub async fn receive_buffer_size(&self) -> Result<usize>
Get the value of the SO_RCVBUF option on this socket.
sourcepub async fn set_receive_buffer_size(&self, size: usize) -> Result<()>
pub async fn set_receive_buffer_size(&self, size: usize) -> Result<()>
Set value for the SO_RCVBUF option on this socket.
Changes the size of the operating system’s receive buffer associated with the socket.
sourcepub async fn receive_timeout(&self) -> Result<Option<Duration>>
pub async fn receive_timeout(&self) -> Result<Option<Duration>>
Get value for the SO_RCVTIMEO option on this socket.
sourcepub async fn set_receive_timeout(
&self,
duration: Option<Duration>,
) -> Result<()>
pub async fn set_receive_timeout( &self, duration: Option<Duration>, ) -> Result<()>
Set value for the SO_RCVTIMEO option on this socket.
sourcepub async fn reuse_address(&self) -> Result<bool>
pub async fn reuse_address(&self) -> Result<bool>
Get value for the SO_REUSEADDR option on this socket.
sourcepub async fn set_reuse_address(&self, reuse: bool) -> Result<()>
pub async fn set_reuse_address(&self, reuse: bool) -> Result<()>
Set value for the SO_REUSEADDR option on this socket.
This indicates that futher calls to bind may allow reuse of local addresses.
sourcepub async fn send_buffer_size(&self) -> Result<usize>
pub async fn send_buffer_size(&self) -> Result<usize>
Get value for the SO_SNDBUF option on this socket.
sourcepub async fn set_send_buffer_size(&self, size: usize) -> Result<()>
pub async fn set_send_buffer_size(&self, size: usize) -> Result<()>
Set value for the SO_SNDBUF option on this socket.
Changes the size of the operating system’s send buffer associated with the socket.
sourcepub async fn send_timeout(&self) -> Result<Option<Duration>>
pub async fn send_timeout(&self) -> Result<Option<Duration>>
Get value for the SO_SNDTIMEO option on this socket.
sourcepub async fn set_send_timeout(&self, duration: Option<Duration>) -> Result<()>
pub async fn set_send_timeout(&self, duration: Option<Duration>) -> Result<()>
Set value for the SO_SNDTIMEO option on this socket.
If timeout is None, then write and send calls will block indefinitely.
sourcepub async fn is_ip_header_included(&self) -> Result<bool>
pub async fn is_ip_header_included(&self) -> Result<bool>
Get the value of the IP_HDRINCL option on this socket.
sourcepub async fn set_ip_header_included(&self, include: bool) -> Result<()>
pub async fn set_ip_header_included(&self, include: bool) -> Result<()>
Set the value of the IP_HDRINCL option on this socket.
sourcepub async fn is_nodelay(&self) -> Result<bool>
pub async fn is_nodelay(&self) -> Result<bool>
Get the value of the TCP_NODELAY option on this socket.
sourcepub async fn set_nodelay(&self, nodelay: bool) -> Result<()>
pub async fn set_nodelay(&self, nodelay: bool) -> Result<()>
Set the value of the TCP_NODELAY option on this socket.
If set, segments are always sent as soon as possible, even if there is only a small amount of data.
sourcepub fn into_tcp_stream(&self) -> Result<TcpStream>
pub fn into_tcp_stream(&self) -> Result<TcpStream>
Get TCP Stream This function will consume the socket and return a new std::net::TcpStream.
sourcepub fn into_tcp_listener(&self) -> Result<TcpListener>
pub fn into_tcp_listener(&self) -> Result<TcpListener>
Get TCP Listener This function will consume the socket and return a new std::net::TcpListener.
sourcepub fn into_udp_socket(&self) -> Result<UdpSocket>
pub fn into_udp_socket(&self) -> Result<UdpSocket>
Get UDP Socket This function will consume the socket and return a new std::net::UdpSocket.
Trait Implementations§
source§impl Clone for AsyncSocket
impl Clone for AsyncSocket
source§fn clone(&self) -> AsyncSocket
fn clone(&self) -> AsyncSocket
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more