-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b161e49
commit b7e412a
Showing
6 changed files
with
62 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// | ||
// Created by david on 12/3/24. | ||
// | ||
#include <cerrno> | ||
#include <unistd.h> | ||
#include <sys/socket.h> | ||
#include "unix_platform.h" | ||
|
||
int unix_make_socket(int domain, int type, int protocol) { | ||
int sockfd; | ||
int err; | ||
|
||
#if defined(SOCK_NONBLOCK) && defined(SOCK_CLOEXEC) | ||
sockfd = socket(domain, type | SOCK_NONBLOCK | SOCK_CLOEXEC, protocol); | ||
if (sockfd != -1) | ||
return sockfd; | ||
|
||
if (errno != EINVAL) | ||
return errno; | ||
#endif | ||
|
||
sockfd = socket(domain, type, protocol); | ||
if (sockfd == -1) | ||
return errno; | ||
|
||
err = unix_nonblock(sockfd, 1); | ||
if (err == 0) | ||
err = unix_cloexec(sockfd, 1); | ||
|
||
if (err) { | ||
close(sockfd); | ||
return err; | ||
} | ||
|
||
#if defined(SO_NOSIGPIPE) | ||
{ | ||
int on = 1; | ||
setsockopt(sockfd, SOL_SOCKET, SO_NOSIGPIPE, &on, sizeof(on)); | ||
} | ||
#endif | ||
|
||
return sockfd; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters