Skip to content

Commit

Permalink
fix ithewei#304: SOCK_CLOEXEC
Browse files Browse the repository at this point in the history
  • Loading branch information
ithewei committed Nov 14, 2022
1 parent 08b0766 commit 2fe8be4
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions base/hsocket.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,9 @@ const char* sockaddr_str(sockaddr_u* addr, char* buf, int len) {

static int sockaddr_bind(sockaddr_u* localaddr, int type) {
// socket -> setsockopt -> bind
#ifdef SOCK_CLOEXEC
type |= SOCK_CLOEXEC;
#endif
int sockfd = socket(localaddr->sa.sa_family, type, 0);
if (sockfd < 0) {
perror("socket");
Expand Down Expand Up @@ -266,11 +269,7 @@ 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);
}
Expand Down

0 comments on commit 2fe8be4

Please sign in to comment.