瀏覽代碼

Apply CLOEXEC flag for TCP protocol independent too (IPv6)

Stéphane Raimbault 13 年之前
父節點
當前提交
e90f906b55
共有 1 個文件被更改,包括 6 次插入1 次删除
  1. 6 1
      src/modbus-tcp.c

+ 6 - 1
src/modbus-tcp.c

@@ -310,9 +310,14 @@ static int _modbus_tcp_pi_connect(modbus_t *ctx)
         return rc;
 
     for (ai_ptr = ai_list; ai_ptr != NULL; ai_ptr = ai_ptr->ai_next) {
+        int flags = ai_ptr->ai_socktype;
         int s;
 
-        s = socket(ai_ptr->ai_family, ai_ptr->ai_socktype, ai_ptr->ai_protocol);
+#ifdef SOCK_CLOEXEC
+        flags |= SOCK_CLOEXEC;
+#endif
+
+        s = socket(ai_ptr->ai_family, flags, ai_ptr->ai_protocol);
         if (s < 0)
             continue;