Struct ares_socket_functions_ex

Source
#[repr(C)]
pub struct ares_socket_functions_ex { pub version: c_uint, pub flags: c_uint, pub asocket: Option<unsafe extern "C" fn(domain: c_int, type_: c_int, protocol: c_int, user_data: *mut c_void) -> ares_socket_t>, pub aclose: Option<unsafe extern "C" fn(sock: ares_socket_t, user_data: *mut c_void) -> c_int>, pub asetsockopt: Option<unsafe extern "C" fn(sock: ares_socket_t, opt: ares_socket_opt_t, val: *const c_void, val_size: ares_socklen_t, user_data: *mut c_void) -> c_int>, pub aconnect: Option<unsafe extern "C" fn(sock: ares_socket_t, address: *const sockaddr, address_len: ares_socklen_t, flags: c_uint, user_data: *mut c_void) -> c_int>, pub arecvfrom: Option<unsafe extern "C" fn(sock: ares_socket_t, buffer: *mut c_void, length: usize, flags: c_int, address: *mut sockaddr, address_len: *mut ares_socklen_t, user_data: *mut c_void) -> ares_ssize_t>, pub asendto: Option<unsafe extern "C" fn(sock: ares_socket_t, buffer: *const c_void, length: usize, flags: c_int, address: *const sockaddr, address_len: ares_socklen_t, user_data: *mut c_void) -> ares_ssize_t>, pub agetsockname: Option<unsafe extern "C" fn(sock: ares_socket_t, address: *mut sockaddr, address_len: *mut ares_socklen_t, user_data: *mut c_void) -> c_int>, pub abind: Option<unsafe extern "C" fn(sock: ares_socket_t, flags: c_uint, address: *const sockaddr, address_len: socklen_t, user_data: *mut c_void) -> c_int>, pub aif_nametoindex: Option<unsafe extern "C" fn(ifname: *const c_char, user_data: *mut c_void) -> c_uint>, pub aif_indextoname: Option<unsafe extern "C" fn(ifindex: c_uint, ifname_buf: *mut c_char, ifname_buf_len: usize, user_data: *mut c_void) -> *const c_char>, }
Expand description

Socket functions to call rather than using OS-native functions

Fields§

§version: c_uint

ABI Version: must be “1”

§flags: c_uint

Flags indicating behavior of the subsystem. One or more ares_sockfunc_flags_t

§asocket: Option<unsafe extern "C" fn(domain: c_int, type_: c_int, protocol: c_int, user_data: *mut c_void) -> ares_socket_t>

REQUIRED. Create a new socket file descriptor. The file descriptor must be opened in non-blocking mode (so that reads and writes never block). Recommended other options would be to disable signals on write errors (SO_NOSIGPIPE), Disable the Nagle algorithm on SOCK_STREAM (TCP_NODELAY), and to automatically close file descriptors on exec (FD_CLOEXEC).

\param[in] domain Socket domain. Valid values are AF_INET, AF_INET6. \param[in] type Socket type. Valid values are SOCK_STREAM (tcp) and SOCK_DGRAM (udp). \param[in] protocol In general this should be ignored, may be passed as 0 (use as default for type), or may be IPPROTO_UDP or IPPROTO_TCP. \param[in] user_data Pointer provided to ares_set_socket_functions_ex(). \return ARES_SOCKET_BAD on error, or socket file descriptor on success. On error, it is expected to set errno (or WSASetLastError()) to an appropriate reason code such as EAFNOSUPPORT / WSAAFNOSUPPORT.

§aclose: Option<unsafe extern "C" fn(sock: ares_socket_t, user_data: *mut c_void) -> c_int>

REQUIRED. Close a socket file descriptor. \param[in] sock Socket file descriptor returned from asocket. \param[in] user_data Pointer provided to ares_set_socket_functions_ex(). \return 0 on success. On failure, should set errno (or WSASetLastError) to an appropriate code such as EBADF / WSAEBADF

§asetsockopt: Option<unsafe extern "C" fn(sock: ares_socket_t, opt: ares_socket_opt_t, val: *const c_void, val_size: ares_socklen_t, user_data: *mut c_void) -> c_int>

REQUIRED. Set socket option. This shares a similar syntax to the BSD setsockopt() call, however we use our own options. The value is typically a pointer to the desired value and each option has its own data type it will express in the documentation.

\param[in] sock Socket file descriptor returned from asocket. \param[in] opt Option to set. \param[in] val Pointer to value for option. \param[in] val_size Size of value. \param[in] user_data Pointer provided to ares_set_socket_functions_ex(). \return Return 0 on success, otherwise -1 should be returned with an appropriate errno (or WSASetLastError()) set. If error is ENOSYS / WSAEOPNOTSUPP an error will not be propagated as it will take it to mean it is an intentional decision to not support the feature.

§aconnect: Option<unsafe extern "C" fn(sock: ares_socket_t, address: *const sockaddr, address_len: ares_socklen_t, flags: c_uint, user_data: *mut c_void) -> c_int>

REQUIRED. Connect to the remote using the supplied address. For UDP sockets this will bind the file descriptor to only send and receive packets from the remote address provided.

\param[in] sock Socket file descriptor returned from asocket. \param[in] address Address to connect to \param[in] address_len Size of address structure passed \param[in] flags One or more ares_socket_connect_flags_t \param[in] user_data Pointer provided to ares_set_socket_functions_ex(). \return Return 0 upon successful establishement, otherwise -1 should be returned with an appropriate errno (or WSASetLastError()) set. It is generally expected that most TCP connections (not using TCP Fast Open) will return -1 with an error of EINPROGRESS / WSAEINPROGRESS due to the non-blocking nature of the connection. It is then the responsibility of the implementation to notify of writability on the socket to indicate the connection has succeeded (or readability on failure to retrieve the appropriate error).

§arecvfrom: Option<unsafe extern "C" fn(sock: ares_socket_t, buffer: *mut c_void, length: usize, flags: c_int, address: *mut sockaddr, address_len: *mut ares_socklen_t, user_data: *mut c_void) -> ares_ssize_t>

REQUIRED. Attempt to read data from the remote.

\param[in] sock Socket file descriptor returned from asocket. \param[in,out] buffer Allocated buffer to place data read from socket. \param[in] length Size of buffer \param[in] flags Unused, always 0. \param[in,out] address Buffer to hold address data was received from. May be NULL if address not desired. \param[in,out] address_len Input size of address buffer, output actual written size. Must be NULL if address is NULL. \param[in] user_data Pointer provided to ares_set_socket_functions_ex(). \return -1 on error with appropriate errno (or WSASetLastError()) set, such as EWOULDBLOCK / EAGAIN / WSAEWOULDBLOCK, or ECONNRESET / WSAECONNRESET.

§asendto: Option<unsafe extern "C" fn(sock: ares_socket_t, buffer: *const c_void, length: usize, flags: c_int, address: *const sockaddr, address_len: ares_socklen_t, user_data: *mut c_void) -> ares_ssize_t>

REQUIRED. Attempt to send data to the remote. Optional address may be specified which may be useful on unbound UDP sockets (though currently not used), and TCP FastOpen where the connection is delayed until first write.

\param[in] sock Socket file descriptor returned from asocket. \param[in] buffer Containing data to place onto wire. \param[in] length Size of buffer \param[in] flags Flags for writing. Currently only used flag is MSG_NOSIGNAL if the host OS has such a flag. In general flags can be ignored. \param[in] address Buffer containing address to send data to. May be NULL. \param[in,out] address_len Size of address buffer. Must be 0 if address is NULL. \param[in] user_data Pointer provided to ares_set_socket_functions_ex(). \return Number of bytes written. -1 on error with appropriate errno (or WSASetLastError()) set.

§agetsockname: Option<unsafe extern "C" fn(sock: ares_socket_t, address: *mut sockaddr, address_len: *mut ares_socklen_t, user_data: *mut c_void) -> c_int>

Optional. Retrieve the local address of the socket.

\param[in] sock Socket file descriptor returned from asocket \param[in,out] address Buffer to hold address \param[in,out] address_len Size of address buffer on input, written size on output. \param[in] user_data Pointer provided to ares_set_socket_functions_ex(). \return 0 on success. -1 on error with an appropriate errno (or WSASetLastError()) set.

§abind: Option<unsafe extern "C" fn(sock: ares_socket_t, flags: c_uint, address: *const sockaddr, address_len: socklen_t, user_data: *mut c_void) -> c_int>

Optional. Bind the socket to an address. This can be used for client connections to bind the source address for packets before connect, or for server connections to bind to an address and port before listening. Currently c-ares only supports client connections.

\param[in] sock Socket file descriptor returned from asocket \param[in] flags ares_socket_bind_flags_t flags. \param[in] address Buffer containing address. \param[in] address_len Size of address buffer. \param[in] user_data Pointer provided to ares_set_socket_functions_ex(). \return 0 on success. -1 on error with an appropriate errno (or WSASetLastError()) set.

§aif_nametoindex: Option<unsafe extern "C" fn(ifname: *const c_char, user_data: *mut c_void) -> c_uint>§aif_indextoname: Option<unsafe extern "C" fn(ifindex: c_uint, ifname_buf: *mut c_char, ifname_buf_len: usize, user_data: *mut c_void) -> *const c_char>

Trait Implementations§

Source§

impl Clone for ares_socket_functions_ex

Source§

fn clone(&self) -> ares_socket_functions_ex

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 Debug for ares_socket_functions_ex

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Copy for ares_socket_functions_ex

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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,

Source§

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>,

Source§

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>,

Source§

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.