Quellcode durchsuchen

Fix flush function of TCP backend on Windows

Stéphane Raimbault vor 14 Jahren
Ursprung
Commit
e2c9f5fd4f
1 geänderte Dateien mit 4 neuen und 1 gelöschten Zeilen
  1. 4 1
      src/modbus-tcp.c

+ 4 - 1
src/modbus-tcp.c

@@ -346,7 +346,10 @@ int _modbus_tcp_flush(modbus_t *ctx)
             return -1;
             return -1;
         }
         }
 
 
-        rc = recv(ctx->s, devnull, MODBUS_TCP_MAX_ADU_LENGTH, 0);
+        if (rc == 1) {
+            /* There is data to flush */
+            rc = recv(ctx->s, devnull, MODBUS_TCP_MAX_ADU_LENGTH, 0);
+        }
 #endif
 #endif
         if (ctx->debug && rc != -1) {
         if (ctx->debug && rc != -1) {
             printf("\n%d bytes flushed\n", rc);
             printf("\n%d bytes flushed\n", rc);