Commit e2c9f5fd4f6e94effdec1938c3f2e37bdc604e84

Authored by Stéphane Raimbault
1 parent 1a6b2b9f

Fix flush function of TCP backend on Windows

Showing 1 changed file with 4 additions and 1 deletions
src/modbus-tcp.c
@@ -346,7 +346,10 @@ int _modbus_tcp_flush(modbus_t *ctx) @@ -346,7 +346,10 @@ int _modbus_tcp_flush(modbus_t *ctx)
346 return -1; 346 return -1;
347 } 347 }
348 348
349 - rc = recv(ctx->s, devnull, MODBUS_TCP_MAX_ADU_LENGTH, 0); 349 + if (rc == 1) {
  350 + /* There is data to flush */
  351 + rc = recv(ctx->s, devnull, MODBUS_TCP_MAX_ADU_LENGTH, 0);
  352 + }
350 #endif 353 #endif
351 if (ctx->debug && rc != -1) { 354 if (ctx->debug && rc != -1) {
352 printf("\n%d bytes flushed\n", rc); 355 printf("\n%d bytes flushed\n", rc);