ARES_SET_SOCKET_FUNCTIONS(3) | Library Functions Manual | ARES_SET_SOCKET_FUNCTIONS(3) |
ares_set_socket_functions - Set socket io callbacks
#include <ares.h> struct ares_socket_functions { ares_socket_t (*asocket)(int, int, int, void *); int (*aclose)(ares_socket_t, void *); int (*aconnect)(ares_socket_t, const struct sockaddr *, ares_socklen_t, void *); ares_ssize_t (*arecvfrom)(ares_socket_t, void *, size_t, int, struct sockaddr *, ares_socklen_t *, void *); ares_ssize_t (*asendv)(ares_socket_t, const struct iovec *, int, void *); }; void ares_set_socket_functions(ares_channel_t *channel, const struct ares_socket_functions * functions, void *user_data);
This function sets a set of callback functions in the given ares channel handle. Cannot be used when ARES_OPT_EVENT_THREAD is passed to ares_init_options(3).
These callback functions will be invoked to create/destroy socket objects and perform io, instead of the normal system calls. A client application can override normal network operation fully through this functionality, and provide its own transport layer. You can choose to only implement some of the socket functions, and provide NULL to any others and c-ares will use its built-in system functions in that case.
All callback functions are expected to operate like their system equivalents, and to set errno(3) to an appropriate error code on failure. C-ares also expects all io functions to behave asynchronously, i.e. as if the socket object has been set to non-blocking mode. Thus read/write calls (for TCP connections) are expected to often generate EAGAIN or EWOULDBLOCK.
The user_data value is provided to each callback function invocation to serve as context.
The ares_socket_functions must provide the following callbacks:
The ares_socket_functions struct provided is not copied but directly referenced, and must thus remain valid through out the channels and any created socket's lifetime.
Added in c-ares 1.13.0
ares_init_options(3), socket(2), close(2), connect(2), recv(2), recvfrom(2), send(2), writev(2)
Carl Wilund
13 Dec 2016 |