};
+enum rdns_io_channel_flags {
+ RDNS_CHANNEL_CONNECTED = 1u << 0u,
+ RDNS_CHANNEL_ACTIVE = 1u << 1u,
+ RDNS_CHANNEL_TCP = 1u << 2u,
+};
+
+#define IS_CHANNEL_CONNECTED(ioc) (((ioc)->flags & RDNS_CHANNEL_CONNECTED) != 0)
+#define IS_CHANNEL_ACTIVE(ioc) (((ioc)->flags & RDNS_CHANNEL_ACTIVE) != 0)
+
+
/**
* IO channel for a specific DNS server
*/
struct sockaddr *saddr;
socklen_t slen;
int sock; /**< persistent socket */
- bool active;
- bool connected;
+ int flags; /**< see enum rdns_io_channel_flags */
void *async_io; /** async opaque ptr */
struct rdns_request *requests; /**< requests in flight */
uint64_t uses;
struct rdns_resolver {
struct rdns_server *servers;
- struct rdns_io_channel *io_channels; /**< hash of io chains indexed by socket */
struct rdns_async_context *async; /** async callbacks */
void *periodic; /** periodic event for resolver */
struct rdns_upstream_context *ups;
}
if (resolver->curve_plugin == NULL) {
- if (!req->io->connected) {
+ if (!IS_CHANNEL_CONNECTED(req->io)) {
r = sendto (fd, req->packet, req->pos, 0,
req->io->saddr,
req->io->slen);
}
}
else {
- if (!req->io->connected) {
+ if (!IS_CHANNEL_CONNECTED(req->io)) {
r = resolver->curve_plugin->cb.curve_plugin.send_cb (req,
resolver->curve_plugin->data,
req->io->saddr,
return -1;
}
}
- else if (!req->io->connected) {
+ else if (!IS_CHANNEL_CONNECTED(req->io)) {
/* Connect socket */
r = connect (fd, req->io->saddr, req->io->slen);
strerror (errno), serv->name);
}
else {
- req->io->connected = true;
+ req->io->flags |= RDNS_CHANNEL_CONNECTED;
}
}
return;
}
- if (!req->io->active || req->retransmits == 1) {
+ if (!IS_CHANNEL_ACTIVE(req->io) || req->retransmits == 1) {
if (resolver->ups) {
cnt = resolver->ups->count (resolver->ups->data);
}
}
- if (!req->io->active || cnt > 1) {
+ if (!IS_CHANNEL_ACTIVE(req->io) || cnt > 1) {
/* Do not reschedule IO requests on inactive sockets */
rdns_debug ("reschedule request with id: %d", (int)req->id);
rdns_request_unschedule (req);
continue;
}
nioc->srv = serv;
- nioc->active = true;
+ nioc->flags = RDNS_CHANNEL_ACTIVE;
nioc->resolver = resolver;
nioc->async_io = resolver->async->add_read (resolver->async->data,
nioc->sock, nioc);
serv->io_channels[i] = nioc;
rdns_debug ("scheduled io channel for server %s to be refreshed after "
"%lu usages", serv->name, (unsigned long)ioc->uses);
- ioc->active = false;
+ ioc->flags &= ~RDNS_CHANNEL_ACTIVE;
REF_RELEASE (ioc);
}
}
&ioc->saddr, &ioc->slen);
if (ioc->sock == -1) {
- ioc->active = false;
rdns_err ("cannot open socket to %s:%d %s",
serv->name, serv->port, strerror (errno));
free (ioc);
+
return false;
}
else {