]> 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>
Sat, 2 Dec 2023 15:15:02 +0000 (20:45 +0530)
rigctl.c
rigctl_menu.c

index cd46a5176bc1f0c7bd00bf56282d7bff0eed19cf..3203d810b8f8d46ca6e1e4f6adb85464bde588be 100644 (file)
--- a/rigctl.c
+++ b/rigctl.c
@@ -4370,15 +4370,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);
@@ -4386,9 +4385,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;