Lines Matching refs:channel

54 static void        write_tcp_data(ares_channel_t *channel, fd_set *write_fds,
56 static void read_packets(ares_channel_t *channel, fd_set *read_fds,
58 static void process_timeouts(ares_channel_t *channel, struct timeval *now);
59 static ares_status_t process_answer(ares_channel_t *channel,
70 static void end_query(ares_channel_t *channel, struct query *query,
77 const ares_channel_t *channel = server->channel;
79 node = ares__slist_node_find(channel->servers, server);
90 const ares_channel_t *channel = server->channel;
96 node = ares__slist_node_find(channel->servers, server);
139 static void processfds(ares_channel_t *channel, fd_set *read_fds,
145 if (channel == NULL) {
149 ares__channel_lock(channel);
152 read_packets(channel, read_fds, read_fd, &now);
153 process_timeouts(channel, &now);
155 write_tcp_data(channel, write_fds, write_fd);
157 ares__channel_unlock(channel);
163 void ares_process(ares_channel_t *channel, fd_set *read_fds, fd_set *write_fds)
165 processfds(channel, read_fds, ARES_SOCKET_BAD, write_fds, ARES_SOCKET_BAD);
171 void ares_process_fd(ares_channel_t *channel,
176 processfds(channel, NULL, read_fd, NULL, write_fd);
210 static void write_tcp_data(ares_channel_t *channel, fd_set *write_fds,
220 for (node = ares__slist_node_first(channel->servers); node != NULL;
253 count = ares__socket_write(channel, server->tcp_conn->fd, data, data_len);
266 SOCK_STATE_CALLBACK(channel, server->tcp_conn->fd, 1, 0);
275 static void read_tcp_data(ares_channel_t *channel,
294 count = ares__socket_recv(channel, conn->fd, ptr, ptr_len);
340 status = process_answer(channel, data, data_len, conn, ARES_TRUE, now);
350 ares__check_cleanup_conn(channel, conn);
372 static ares_socket_t *channel_socket_list(const ares_channel_t *channel,
385 for (snode = ares__slist_node_first(channel->servers); snode != NULL;
413 static void read_udp_packets_fd(ares_channel_t *channel,
443 read_len = ares__socket_recvfrom(channel, conn->fd, (void *)buf,
468 process_answer(channel, buf, (size_t)read_len, conn, ARES_FALSE, now);
473 } while (read_len >= 0 && channel->sock_funcs == NULL);
475 ares__check_cleanup_conn(channel, conn);
478 static void read_packets(ares_channel_t *channel, fd_set *read_fds,
494 node = ares__htable_asvp_get_direct(channel->connnode_by_socket, read_fd);
502 read_tcp_data(channel, conn, now);
504 read_udp_packets_fd(channel, conn, now);
513 socketlist = channel_socket_list(channel, &num_sockets);
528 ares__htable_asvp_get_direct(channel->connnode_by_socket, socketlist[i]);
536 read_tcp_data(channel, conn, now);
538 read_udp_packets_fd(channel, conn, now);
546 static void process_timeouts(ares_channel_t *channel, struct timeval *now)
549 ares__slist_node_first(channel->queries_by_timeout);
567 ares__check_cleanup_conn(channel, conn);
616 static ares_status_t process_answer(ares_channel_t *channel,
640 query = ares__htable_szvp_get_direct(channel->queries_by_qid,
651 end_query(channel, query, status, NULL, 0);
677 end_query(channel, query, status, NULL, 0);
691 !(channel->flags & ARES_FLAG_IGNTC)) {
701 if (!(channel->flags & ARES_FLAG_NOCHECKRESP)) {
731 if (ares_qcache_insert(channel, now, query, rdnsrec) == ARES_SUCCESS) {
736 end_query(channel, query, ARES_SUCCESS, abuf, alen);
763 ares_channel_t *channel = query->channel;
764 size_t max_tries = ares__slist_len(channel->servers) * channel->tries;
777 end_query(channel, query, query->error_status, NULL, 0);
784 static struct server_state *ares__random_server(ares_channel_t *channel)
790 size_t num_servers = ares__slist_len(channel->servers);
797 ares__rand_bytes(channel->rand_state, &c, 1);
803 for (node = ares__slist_node_first(channel->servers); node != NULL;
829 const ares_channel_t *channel = query->channel;
830 size_t timeplus = channel->timeout;
832 size_t num_servers = ares__slist_len(channel->servers);
845 if (channel->maxtimeout && timeplus > channel->maxtimeout) {
846 timeplus = channel->maxtimeout;
862 ares__rand_bytes(channel->rand_state, (unsigned char *)&r, sizeof(r));
868 * specified in channel options. */
869 if (timeplus < channel->timeout) {
870 timeplus = channel->timeout;
878 ares_channel_t *channel = query->channel;
888 if (channel->rotate) {
889 server = ares__random_server(channel);
892 server = ares__slist_first_val(channel->servers);
896 end_query(channel, query, ARES_ENOSERVER /* ? */, NULL, 0);
907 status = ares__open_connection(channel, server, ARES_TRUE);
923 end_query(channel, query, status, NULL, 0);
934 end_query(channel, query, status, NULL, 0);
945 SOCK_STATE_CALLBACK(channel, conn->fd, 1, 1);
958 } else if (channel->udp_max_queries > 0 &&
959 conn->total_queries >= channel->udp_max_queries) {
966 status = ares__open_connection(channel, server, ARES_FALSE);
982 end_query(channel, query, status, NULL, 0);
989 if (ares__socket_write(channel, conn->fd, query->qbuf, query->qlen) == -1) {
1012 ares__slist_insert(channel->queries_by_timeout, query);
1014 end_query(channel, query, ARES_ENOMEM, NULL, 0);
1030 end_query(channel, query, ARES_ENOMEM, NULL, 0);
1117 ares__htable_szvp_remove(query->channel->queries_by_qid, query->qid);
1126 static void end_query(ares_channel_t *channel, struct query *query,
1137 /* Check and notify if no other queries are enqueued on the channel. This
1142 ares_queue_notify_empty(channel);