|
|
|
|
@ -86,7 +86,8 @@ static void* test_server_thread(void* arg) {
|
|
|
|
|
fd_set fds; |
|
|
|
|
FD_ZERO(&fds); |
|
|
|
|
FD_SET(sock, &fds); |
|
|
|
|
tv.tv_sec = 1; tv.tv_usec = 0; |
|
|
|
|
// Таймаут select нужен только для быстрой остановки тестового сервера.
|
|
|
|
|
tv.tv_sec = 0; tv.tv_usec = 10000; |
|
|
|
|
int r = select((int)(sock + 1), &fds, NULL, NULL, &tv); |
|
|
|
|
if (r <= 0) continue; |
|
|
|
|
|
|
|
|
|
@ -172,7 +173,7 @@ static void* dns_server_thread(void* arg) {
|
|
|
|
|
uint8_t buf[512]; |
|
|
|
|
while (g_dns_running) { |
|
|
|
|
fd_set fds; FD_ZERO(&fds); FD_SET(sock, &fds); |
|
|
|
|
struct timeval tv = {1, 0}; |
|
|
|
|
struct timeval tv = {0, 10000}; |
|
|
|
|
int r = select((int)(sock + 1), &fds, NULL, NULL, &tv); |
|
|
|
|
if (r <= 0) continue; |
|
|
|
|
struct sockaddr_in client; socklen_t cl = sizeof(client); |
|
|
|
|
@ -243,6 +244,7 @@ int main(void) {
|
|
|
|
|
debug_config_init(); |
|
|
|
|
debug_set_level(DEBUG_LEVEL_WARN); |
|
|
|
|
debug_set_categories(DEBUG_CATEGORY_GENERAL); |
|
|
|
|
debug_set_category_level(DEBUG_CATEGORY_GENERAL, DEBUG_LEVEL_INFO); |
|
|
|
|
|
|
|
|
|
DEBUG_INFO(DEBUG_CATEGORY_GENERAL, "=== NTP Test ==="); |
|
|
|
|
|
|
|
|
|
@ -297,7 +299,11 @@ int main(void) {
|
|
|
|
|
DEBUG_INFO(DEBUG_CATEGORY_GENERAL, "NTP Test PASSED"); |
|
|
|
|
|
|
|
|
|
cleanup: |
|
|
|
|
if (server_started) { g_server_running = 0; pthread_join(server_thread, NULL); } |
|
|
|
|
if (dns_started) { g_dns_running = 0; pthread_join(dns_thread, NULL); } |
|
|
|
|
g_server_running = g_dns_running = 0; |
|
|
|
|
uint64_t stop_started = get_time_us(); |
|
|
|
|
if (server_started) pthread_join(server_thread, NULL); |
|
|
|
|
if (dns_started) pthread_join(dns_thread, NULL); |
|
|
|
|
DEBUG_INFO(DEBUG_CATEGORY_GENERAL, "test NTP servers stopped: ntp=%d dns=%d elapsed_us=%llu", |
|
|
|
|
server_started, dns_started, (unsigned long long)(get_time_us() - stop_started)); |
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
|