Skip to content

Commit 81ed8d0

Browse files
committed
More debug info, better error message.
1 parent d2927d6 commit 81ed8d0

File tree

1 file changed

+40
-28
lines changed

1 file changed

+40
-28
lines changed

src/igate.c

Lines changed: 40 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ static struct s_server {
174174

175175
} is_server[MAX_IS_HOSTS];
176176

177-
int num_is_servers = 0; // Number of element used above for CWOP mode.
177+
static int num_is_servers = 0; // Number of elements used above for CWOP mode.
178178
// Should be 1 for normal ham APRS-IS.
179179

180180

@@ -371,6 +371,7 @@ int igate_get_dnl_cnt (void) {
371371
* 1 plus packets sent TO server or why not.
372372
* 2 plus duplicate detection overview.
373373
* 3 plus duplicate detection details.
374+
* 4 plus DNS details.
374375
*
375376
* Description: Originally: This starts two threads:
376377
*
@@ -572,21 +573,20 @@ static void setup_cwop_connect_threads(void)
572573
freeaddrinfo(ai_head);
573574
}
574575

575-
#if DEBUG_DNS
576-
text_color_set(DW_COLOR_DEBUG);
577-
dw_printf ("cwop getaddrinfo returns:\n");
578-
#endif
576+
if (s_debug >= 4) {
577+
text_color_set(DW_COLOR_DEBUG);
578+
dw_printf ("cwop getaddrinfo returns:\n");
579+
}
579580
num_is_servers = 0;
580581
for (ai = ai_head; ai != NULL; ai = ai->ai_next) {
581-
#if DEBUG_DNS
582-
text_color_set(DW_COLOR_DEBUG);
583582
dwsock_ia_to_text (ai->ai_family, ai->ai_addr,
584583
is_server[num_is_servers].ipaddr_str,
585584
sizeof(is_server[num_is_servers].ipaddr_str));
586585
strlcpy (is_server[num_is_servers].server_port_str, server_port_str,
587586
sizeof(is_server[num_is_servers].server_port_str));
588-
dw_printf (" %s\n", is_server[num_is_servers].ipaddr_str);
589-
#endif
587+
if (s_debug >= 4) {
588+
dw_printf (" [%d] %s\n", num_is_servers, is_server[num_is_servers].ipaddr_str);
589+
}
590590

591591
// Don't run off end if too many.
592592
if (num_is_servers < MAX_IS_HOSTS) num_is_servers++;
@@ -757,17 +757,17 @@ static void * connnect_thread_aprs (void *arg)
757757
continue;
758758
}
759759

760-
#if DEBUG_DNS
761-
text_color_set(DW_COLOR_DEBUG);
762-
dw_printf ("getaddrinfo returns:\n");
763-
#endif
760+
if (s_debug >= 4) {
761+
text_color_set(DW_COLOR_DEBUG);
762+
dw_printf ("getaddrinfo returns:\n");
763+
}
764764
num_hosts = 0;
765765
for (ai = ai_head; ai != NULL; ai = ai->ai_next) {
766-
#if DEBUG_DNS
767-
text_color_set(DW_COLOR_DEBUG);
768-
dwsock_ia_to_text (ai->ai_family, ai->ai_addr, ipaddr_str, sizeof(ipaddr_str));
769-
dw_printf (" %s\n", ipaddr_str);
770-
#endif
766+
if (s_debug >= 4) {
767+
text_color_set(DW_COLOR_DEBUG);
768+
dwsock_ia_to_text (ai->ai_family, ai->ai_addr, ipaddr_str, sizeof(ipaddr_str));
769+
dw_printf (" [%d] %s\n", num_hosts, ipaddr_str);
770+
}
771771
hosts[num_hosts] = ai;
772772
if (num_hosts < MAX_IS_HOSTS) num_hosts++;
773773
}
@@ -780,14 +780,14 @@ static void * connnect_thread_aprs (void *arg)
780780

781781
shuffle (hosts, num_hosts);
782782

783-
#if DEBUG_DNS
784-
text_color_set(DW_COLOR_DEBUG);
785-
dw_printf ("after shuffling:\n");
786-
for (n=0; n<num_hosts; n++) {
787-
dwsock_ia_to_text (hosts[n]->ai_family, hosts[n]->ai_addr, ipaddr_str, sizeof(ipaddr_str));
788-
dw_printf (" %s\n", ipaddr_str);
783+
if (s_debug >= 4) {
784+
text_color_set(DW_COLOR_DEBUG);
785+
dw_printf ("after shuffling:\n");
786+
for (n=0; n<num_hosts; n++) {
787+
dwsock_ia_to_text (hosts[n]->ai_family, hosts[n]->ai_addr, ipaddr_str, sizeof(ipaddr_str));
788+
dw_printf (" [%d] %s\n", n, ipaddr_str);
789+
}
789790
}
790-
#endif
791791

792792
// Try each address until we find one that is successful.
793793

@@ -822,7 +822,8 @@ static void * connnect_thread_aprs (void *arg)
822822
}
823823
#endif
824824

825-
#ifndef DEBUG_DNS
825+
//#ifndef DEBUG_DNS
826+
#if 1
826827
err = connect(is, ai->ai_addr, (int)ai->ai_addrlen);
827828
#if __WIN32__
828829
if (err == SOCKET_ERROR) {
@@ -1670,7 +1671,7 @@ static int get1ch (int my_server_index)
16701671

16711672
n = SOCK_RECV (is_server[my_server_index].igate_sock, (char*)(&ch), 1);
16721673

1673-
if (n == 1) {
1674+
if (n == 1) { // Success
16741675
#if DEBUG9
16751676
dw_printf (log_fp, "%02x %c %c", ch,
16761677
isprint(ch) ? ch : '.' ,
@@ -1682,8 +1683,19 @@ static int get1ch (int my_server_index)
16821683
return(ch);
16831684
}
16841685

1686+
// Linux man page: "These calls return the number of bytes received, or -1 if an error occurred
1687+
// The return value will be 0 when the peer has performed an orderly shutdown.
1688+
1689+
// I saw 0 when two different clients were logged in with same callsign-ssid.
1690+
16851691
text_color_set(DW_COLOR_ERROR);
1686-
dw_printf ("\nError reading from IGate server. Closing connection.\n\n");
1692+
if (n == 0) {
1693+
dw_printf ("\nServer %s has closed connection.\n\n",
1694+
is_server[my_server_index].ipaddr_str);
1695+
}
1696+
else {
1697+
dw_printf ("\nError reading from server %s. Closing connection.\n\n", is_server[my_server_index].ipaddr_str);
1698+
}
16871699
#if __WIN32__
16881700
closesocket (is_server[my_server_index].igate_sock);
16891701
#else

0 commit comments

Comments
 (0)