static const int dns_port = 53;
static const int default_io_cnt = 8;
+static const int default_tcp_io_cnt = 2;
#define UDP_PACKET_SIZE (4096 * 2)
char *name;
unsigned int port;
unsigned int io_cnt;
+ unsigned int tcp_io_cnt;
struct rdns_io_channel **io_channels;
+ struct rdns_io_channel **tcp_io_channels;
void *ups_elt;
upstream_entry_t up;
};
serv->io_channels[i] = ioc;
}
+
+ serv->tcp_io_channels = calloc (serv->tcp_io_cnt, sizeof (struct rdns_io_channel *));
+ for (i = 0; i < serv->tcp_io_cnt; i ++) {
+ ioc = rdns_ioc_new (serv, resolver, true);
+
+ if (ioc == NULL) {
+ rdns_err ("cannot allocate memory for the resolver IO channels");
+ return false;
+ }
+
+ serv->tcp_io_channels[i] = ioc;
+ }
}
if (resolver->async->add_periodic) {
}
serv->io_cnt = io_cnt;
+ /* TODO: make it configurable maybe? */
+ serv->tcp_io_cnt = default_tcp_io_cnt;
serv->port = port;
UPSTREAM_ADD (resolver->servers, serv, priority);
ioc = serv->io_channels[i];
REF_RELEASE (ioc);
}
- serv->io_cnt = 0;
+ for (i = 0; i < serv->tcp_io_cnt; i ++) {
+ ioc = serv->tcp_io_channels[i];
+ REF_RELEASE (ioc);
+ }
UPSTREAM_DEL (resolver->servers, serv);
free (serv->io_channels);
free (serv->name);
return NULL;
}
+ if (is_tcp) {
+ /* We also need to connect a TCP channel */
+ int r = connect (nioc->sock, nioc->saddr, nioc->slen);
+
+ if (r == -1) {
+ if (errno != EAGAIN && errno != EINTR && errno != EINPROGRESS) {
+ rdns_err ("cannot connect a TCP socket: %s for server %s",
+ strerror(errno), serv->name);
+ close(nioc->sock);
+ free(nioc);
+
+ return NULL;
+ }
+ else {
+ /* We need to wait for write readiness here */
+ nioc->async_io = resolver->async->add_write (resolver->async->data,
+ nioc->sock, nioc);
+ }
+ }
+ else {
+ nioc->flags |= RDNS_CHANNEL_CONNECTED|RDNS_CHANNEL_ACTIVE;
+ }
+
+ nioc->flags |= RDNS_CHANNEL_TCP;
+ }
+
nioc->srv = serv;
- nioc->flags = RDNS_CHANNEL_ACTIVE;
nioc->resolver = resolver;
- nioc->async_io = resolver->async->add_read (resolver->async->data,
- nioc->sock, nioc);
+
+ /* If it is not NULL then we are in a delayed connection state */
+ if (nioc->async_io == NULL) {
+ nioc->flags |= RDNS_CHANNEL_ACTIVE;
+ nioc->async_io = resolver->async->add_read(resolver->async->data,
+ nioc->sock, nioc);
+ }
+
nioc->requests = kh_init(rdns_requests_hash);
REF_INIT_RETAIN (nioc, rdns_ioc_free);