Add virtual function set for socket IO

Defines a structure of basic create, close, read/write
functions as virtual function calls, settable for individual
c-ares channels.
pull/76/merge
elcallio 8 years ago committed by Daniel Stenberg
parent bac968cbb0
commit c32103e112
  1. 21
      ares.h
  2. 12
      ares_init.c
  3. 3
      ares_private.h

@ -356,6 +356,27 @@ CARES_EXTERN void ares_set_socket_configure_callback(ares_channel channel,
CARES_EXTERN int ares_set_sortlist(ares_channel channel,
const char *sortstr);
/*
* Virtual function set to have user-managed socket IO.
* Note that all functions need to be defined, and when
* set, the library will not do any bind nor set any
* socket options, assuming the client handles these
* through either socket creation or the
* ares_sock_config_callback call.
*/
struct iovec;
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 *, socklen_t, void *);
ssize_t(*arecvfrom)(ares_socket_t, void *, size_t, int, struct sockaddr *, socklen_t *, void *);
ssize_t(*asendv)(ares_socket_t, const struct iovec *, int, void *);
};
CARES_EXTERN void ares_set_socket_functions(ares_channel channel,
const struct ares_socket_functions * funcs,
void *user_data);
CARES_EXTERN void ares_send(ares_channel channel,
const unsigned char *qbuf,
int qlen,

@ -166,6 +166,8 @@ int ares_init_options(ares_channel *channelptr, struct ares_options *options,
channel->sock_create_cb_data = NULL;
channel->sock_config_cb = NULL;
channel->sock_config_cb_data = NULL;
channel->sock_funcs = NULL;
channel->sock_func_cb_data = NULL;
channel->last_server = 0;
channel->last_timeout_processed = (time_t)now.tv_sec;
@ -292,6 +294,8 @@ int ares_dup(ares_channel *dest, ares_channel src)
(*dest)->sock_create_cb_data = src->sock_create_cb_data;
(*dest)->sock_config_cb = src->sock_config_cb;
(*dest)->sock_config_cb_data = src->sock_config_cb_data;
(*dest)->sock_funcs = src->sock_funcs;
(*dest)->sock_func_cb_data = src->sock_func_cb_data;
strncpy((*dest)->local_dev_name, src->local_dev_name,
sizeof(src->local_dev_name));
@ -2103,6 +2107,14 @@ void ares_set_socket_configure_callback(ares_channel channel,
channel->sock_config_cb_data = data;
}
void ares_set_socket_functions(ares_channel channel,
const struct ares_socket_functions * funcs,
void *data)
{
channel->sock_funcs = funcs;
channel->sock_func_cb_data = data;
}
int ares_set_sortlist(ares_channel channel, const char *sortstr)
{
int nsort = 0;

@ -314,6 +314,9 @@ struct ares_channeldata {
ares_sock_config_callback sock_config_cb;
void *sock_config_cb_data;
const struct ares_socket_functions * sock_funcs;
void *sock_func_cb_data;
};
/* Memory management functions */

Loading…
Cancel
Save