#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 channel, const struct ares_socket_functions * functions, void *user_data);
This function sets a set of callback functions in the given ares channel handle. 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.
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.