]> git.rkrishnan.org Git - pihpsdr.git/commitdiff
serial_server: handle the case where read returns a 0 (eof)
authorRamakrishnan Muthukrishnan <ram@rkrishnan.org>
Fri, 1 Dec 2023 16:34:17 +0000 (22:04 +0530)
committerRamakrishnan Muthukrishnan <ram@rkrishnan.org>
Fri, 1 Dec 2023 16:34:17 +0000 (22:04 +0530)
rigctl.c
rigctl_menu.c

index f7e819ca5f1cf8d1bce557c1a4a500b3cf8767c3..2c360665f5067985046bed7db191f6c89221e9d8 100644 (file)
--- a/rigctl.c
+++ b/rigctl.c
@@ -4372,15 +4372,14 @@ static gpointer serial_server(gpointer data) {
                 command_index++;
                 if (cmd_input[i] == ';') {
                     command[command_index] = '\0';
-                    if (rigctl_debug)
+                    if (rigctl_debug) {
                         g_print("RIGCTL: command=%s\n", command);
+                   }
                     COMMAND *info = g_new(COMMAND, 1);
                     info->client = client;
                     info->command = command;
                     g_mutex_lock(&mutex_busy->m);
-                   if (client->fd != -1) {
-                       g_idle_add(parse_cmd, info);
-                   }
+                   g_idle_add(parse_cmd, info);
                     g_mutex_unlock(&mutex_busy->m);
 
                     command = g_new(char, MAXDATASIZE);
@@ -4388,9 +4387,14 @@ static gpointer serial_server(gpointer data) {
                 }
             }
         } else if (numbytes < 0) {
+           perror("serial_server");
             break;
-        }
-        // usleep(100L);
+        } else if (numbytes == 0) {
+           // don't continue in the loop, the other side has closed
+           // the connection, so no point trying to read from it.
+           perror("serial_server: connection closed by the client");
+           break;
+       }
     }
     close(client->fd);
     cat_control--;
index 2ee075047d937e195576d588e63f585ded097aff..d036fb444f5862027610b7af929cfcec8acc2a73 100644 (file)
@@ -36,7 +36,7 @@ gboolean  serial_enable = TRUE; // edit (enable serial at startup)
 char ser_port[64]="/dev/ttyACM0";
 int serial_baud_rate = B9600;
 int serial_parity = 0; // 0=none, 1=even, 2=odd
-gboolean rigctl_debug=FALSE;
+gboolean rigctl_debug = TRUE;
 
 static GtkWidget *parent_window=NULL;
 static GtkWidget *dialog=NULL;