소스 검색

set SOCK_CLOEXEC (#268)

Co-authored-by: 管培喆 <guanpeizhe@minieye.cc>
MrSen 3 년 전
부모
커밋
158cff2fce
1개의 변경된 파일4개의 추가작업 그리고 0개의 파일을 삭제
  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);
 }