int dns_main_loop() { struct timeval tv; fd_set active_rfds; int retval; dns_request_t m; dns_request_t *ptr, *next; //int purge_time = config.purge_time / 60; int purge_time = CACHE_CHECK_TIME / DNS_TICK_TIME; //(30sec) modified by CMC 8/4/2001 while( !dns_main_quit ){ /* set the one second time out */ tv.tv_sec = DNS_TICK_TIME; //modified by CMC 8/3/2001 tv.tv_usec = 0; /* now copy the main rfds in the active one as it gets modified by select*/ active_rfds = rfds; retval = select( FD_SETSIZE, &active_rfds, NULL, NULL, &tv ); if (retval){ /* data is now available */ dns_read_packet( dns_sock, &m ); dns_handle_request( &m ); }else{ /* select time out */ ptr = dns_request_list; while( ptr ){ next = ptr->next; ptr->time_pending++; if( ptr->time_pending > DNS_TIMEOUT/DNS_TICK_TIME ){ /* CMC: ptr->time_pending= DNS_TIMEOUT ~ DNS_TIMEOUT+DNS_TICK_TIME */ debug("Request timed out\n"); /* send error back */ dns_construct_error_reply(ptr); dns_write_packet( dns_sock, ptr->src_addr, ptr->src_port, ptr ); dns_request_list = dns_list_remove( dns_request_list, ptr ); } ptr = next; } /* while(ptr) */ /* purge cache */ purge_time--; if( purge_time <= 0 ){ //modified by CMC 8/4/2001 cache_purge( config.purge_time ); //purge_time = config.purge_time / 60; purge_time = CACHE_CHECK_TIME / DNS_TICK_TIME; //(30sec) modified by CMC 8/3/2001 } } /* if (retval) */ } return 0; }
int dns_main_loop() { struct timeval tv; fd_set active_rfds; int retval; dns_request_t m; dns_request_t *ptr, *next; int purge_time = config.purge_time / 60; int next_server_index = 0; struct in_addr in; while( !dns_main_quit ){ /* set the one second time out */ tv.tv_sec = 1; tv.tv_usec = 0; /* now copy the main rfds in the active one as it gets modified by select*/ active_rfds = rfds; retval = select( FD_SETSIZE, &active_rfds, NULL, NULL, &tv ); if (retval){ /* data is now available */ dns_read_packet( dns_sock, &m ); m.time_pending = 0; dns_handle_request( &m ); }else{ /* select time out */ ptr = dns_request_list; while( ptr ){ next = ptr->next; /* Resend query to a new nameserver if response * has not been received from the current nameserver */ ptr->time_pending++; if( ptr->time_pending > DNS_TIMEOUT ){ debug("Request timed out\n"); /* send error back */ dns_construct_error_reply(ptr); dns_write_packet( dns_sock, ptr->src_addr, ptr->src_port, ptr ); dns_request_list = dns_list_remove( dns_request_list, ptr ); } if( ( ptr->time_pending % DNS_SERVER_TIMEOUT == 0) && ( ptr->time_pending < DNS_TIMEOUT) ) { /* Send a request to the next nameserver */ next_server_index = ptr->time_pending/DNS_SERVER_TIMEOUT; /* If already the maximum number of supported servers have been tried out then remove the request from the list and send a response back */ if(next_server_index >= MAX_NAME_SERVER || (config.name_server[next_server_index] == NULL )) { /* send error back */ debug("All Servers Tried: No Response\n"); dns_construct_error_reply(ptr); dns_write_packet( dns_sock, ptr->src_addr, ptr->src_port, ptr ); dns_request_list = dns_list_remove( dns_request_list, ptr ); debug("Sent a DNS error message to Client \n"); } else { /* Create the new server IP address and relay the query untouched */ inet_aton( config.name_server[next_server_index], &in ); /*!!!*/ debug("Didn't get a response from last server\n"); debug("Sending a new request to %s\n", config.name_server[next_server_index]); /* Send the new request to the next name server */ dns_write_packet( dns_sock, in, PORT, ptr ); } } ptr = next; } /* while(ptr) */ /* purge cache */ purge_time--; if( !purge_time ){ cache_purge( config.purge_time ); purge_time = config.purge_time / 60; } } /* if (retval) */ } return 0; }