Commit 00e068eb59837b299adaaf34805a47dfc94bf58a

Authored by Stéphane Raimbault
1 parent f9358460

tcp_modbus_accept mustn't close socket on error (closes #333)

The socket management belongs to the application.

The return code was missing in modbus_tcp_pi_accept().
Showing 1 changed file with 2 additions and 4 deletions
src/modbus-tcp.c
... ... @@ -661,8 +661,6 @@ int modbus_tcp_accept(modbus_t *ctx, int *s)
661 661 #endif
662 662  
663 663 if (ctx->s == -1) {
664   - close(*s);
665   - *s = -1;
666 664 return -1;
667 665 }
668 666  
... ... @@ -691,9 +689,9 @@ int modbus_tcp_pi_accept(modbus_t *ctx, int *s)
691 689 #else
692 690 ctx->s = accept(*s, (struct sockaddr *)&addr, &addrlen);
693 691 #endif
  692 +
694 693 if (ctx->s == -1) {
695   - close(*s);
696   - *s = -1;
  694 + return -1;
697 695 }
698 696  
699 697 if (ctx->debug) {
... ...