From df6a6ce06621cc14fe5d20232fb017c76159179a Mon Sep 17 00:00:00 2001 From: lwvmobile Date: Thu, 14 Mar 2024 19:32:07 -0400 Subject: [PATCH] M17 - Persistent TCP Retry When M17 Decoding Enabled; --- src/dsd_main.c | 6 ++++++ src/dsd_symbol.c | 8 +++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/dsd_main.c b/src/dsd_main.c index 646a374..2c86af7 100644 --- a/src/dsd_main.c +++ b/src/dsd_main.c @@ -2637,6 +2637,7 @@ main (int argc, char **argv) if (curr != NULL) opts.tcp_portno = atoi (curr); TCPEND: + if (exitflag == 1) cleanupAndExit(&opts, &state); //needed to break the loop on ctrl+c fprintf (stderr, "%s:", opts.tcp_hostname); fprintf (stderr, "%d \n", opts.tcp_portno); opts.tcp_sockfd = Connect(opts.tcp_hostname, opts.tcp_portno); @@ -2653,6 +2654,11 @@ main (int argc, char **argv) sprintf (opts.audio_in_dev, "%s", "/dev/dsp"); opts.audio_in_type = 5; #else + if (opts.frame_m17 == 1) + { + sleep(1); + goto TCPEND; //try again if using M17 encoder / decoder over TCP + } sprintf (opts.audio_in_dev, "%s", "pulse"); fprintf (stderr, "TCP Connection Failure - Using %s Audio Input.\n", opts.audio_in_dev); opts.audio_in_type = 0; diff --git a/src/dsd_symbol.c b/src/dsd_symbol.c index 036343f..32c9e63 100644 --- a/src/dsd_symbol.c +++ b/src/dsd_symbol.c @@ -222,6 +222,8 @@ getSymbol (dsd_opts * opts, dsd_state * state, int have_sync) #else result = sf_read_short(opts->tcp_file_in, &sample, 1); if(result == 0) { + TCP_RETRY: + if (exitflag == 1) cleanupAndExit(opts, state); //needed to break the loop on ctrl+c fprintf (stderr, "\nConnection to TCP Server Interrupted. Trying again in 3 seconds.\n"); sample = 0; sf_close(opts->tcp_file_in); //close current connection on this end @@ -246,7 +248,11 @@ getSymbol (dsd_opts * opts, dsd_state * state, int have_sync) } else fprintf (stderr, "TCP Socket Reconnected Successfully.\n"); } - else fprintf (stderr, "TCP Socket Connection Error.\n"); + else + { + fprintf (stderr, "TCP Socket Connection Error.\n"); + if (opts->frame_m17 == 1) goto TCP_RETRY; //if using m17 encoder/decoder, just keep looping to keep alive + } //now retry reading sample result = sf_read_short(opts->tcp_file_in, &sample, 1);