fix timeout in msec
authorLaurent Mazet <mazet@softndesign.org>
Sun, 8 Jun 2025 21:38:21 +0000 (23:38 +0200)
committerLaurent Mazet <mazet@softndesign.org>
Sun, 8 Jun 2025 21:38:21 +0000 (23:38 +0200)
morep.c

diff --git a/morep.c b/morep.c
index b86a6bd6b25be51411e0b7e3ce7471a3114fa2b8..11be582468f8d452a12b0dc218347cb57f534f36 100644 (file)
--- a/morep.c
+++ b/morep.c
@@ -531,17 +531,21 @@ int MOREP_Receive_timeout (int index, uint8_t *msgtype, uint8_t *buffer, int *le
 
     VERBOSE (morep, TRACE, PRINTF ("MOREP_Receive_timeout\n"));
 
-    if (MOREP_list[index]->used) {
+    if ((index < 0) || (index >= MAX_MOREP_NUMBER) ||
+        (MOREP_list[index] == NULL) || (!MOREP_list[index]->used)) {
+        VERBOSE (morep, ERROR, PRINTF ("incorrect MOREP descriptor (%d)\n", index));
         return -1;
     }
+    VERBOSE (morep, DEBUG, PRINTF ("working with MOREP descriptor %d (%d)\n", index, MOREP_list[index]->sock));
     int fid = MOREP_list[index]->sock;
 
     fd_set rfds;
-    struct timeval tv = { 0, ms };
+    struct timeval tv = { 0, ms * 1000};
     FD_ZERO (&rfds);
     FD_SET (fid, &rfds);
 
     int retval = select (fid + 1, &rfds, NULL, NULL, &tv);
+    VERBOSE (morep, TRACE, PRINTF ("select: %d (%ld, %ld)\n", retval, tv.tv_sec, tv.tv_usec));
     if (retval != 1) {
         return retval;
     }