Przeglądaj źródła

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().
Stéphane Raimbault 8 lat temu
rodzic
commit
00e068eb59
1 zmienionych plików z 2 dodań i 4 usunięć
  1. 2 4
      src/modbus-tcp.c

+ 2 - 4
src/modbus-tcp.c

@@ -661,8 +661,6 @@ int modbus_tcp_accept(modbus_t *ctx, int *s)
 #endif
 
     if (ctx->s == -1) {
-        close(*s);
-        *s = -1;
         return -1;
     }
 
@@ -691,9 +689,9 @@ int modbus_tcp_pi_accept(modbus_t *ctx, int *s)
 #else
     ctx->s = accept(*s, (struct sockaddr *)&addr, &addrlen);
 #endif
+
     if (ctx->s == -1) {
-        close(*s);
-        *s = -1;
+        return -1;
     }
 
     if (ctx->debug) {