Explorar o código

set SOCK_CLOEXEC (#268)

Co-authored-by: 管培喆 <guanpeizhe@minieye.cc>
MrSen %!s(int64=3) %!d(string=hai) anos
pai
achega
158cff2fce
Modificáronse 1 ficheiros con 4 adicións e 0 borrados
  1. 4 0
      base/hsocket.c

+ 4 - 0
base/hsocket.c

@@ -266,7 +266,11 @@ int Bind(int port, const char* host, int type) {
 }
 
 int Listen(int port, const char* host) {
+#ifdef OS_LINUX
+    int sockfd = Bind(port, host, SOCK_STREAM|SOCK_CLOEXEC);
+#else
     int sockfd = Bind(port, host, SOCK_STREAM);
+#endif
     if (sockfd < 0) return sockfd;
     return ListenFD(sockfd);
 }