Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unix: use the presence of SOCK_* instead of OS macros for socketpair #4413

Merged
merged 1 commit into from
May 21, 2024

Conversation

panjf2000
Copy link
Contributor

Stuffing SOCK_NONBLOCK and SOCK_CLOEXEC into the type argument when calling socketpair() is widely supported across UNIX-like OS: Linux, BSD, Solaris, etc., as is the socket(). socket() and socketpair() share the SOCK_ flags under the hood.

Currently, we detect the presence of SOCK_NONBLOCK and SOCK_CLOEXEC for socket():

libuv/src/unix/core.c

Lines 494 to 499 in bf61390

int uv__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);

while checking the specific OS macros for socketpair(). We keep them in sync to expand the scope of SOCK_* flags for socketpair().

References

---------

Signed-off-by: Andy Pan <i@andypan.me>
@panjf2000
Copy link
Contributor Author

Hi @saghul, shall we move forward with this PR?

@saghul saghul merged commit ab3ecf6 into libuv:v1.x May 21, 2024
26 checks passed
@saghul
Copy link
Member

saghul commented May 21, 2024

Nice work!

@panjf2000 panjf2000 deleted the socketpair-flags branch May 21, 2024 07:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants