fd_util: add function socketpair_cloexec_nonblock()
This commit is contained in:
parent
531c0067ec
commit
08e2e2e791
@ -206,6 +206,29 @@ socketpair_cloexec(int domain, int type, int protocol, int sv[2])
|
||||
return ret;
|
||||
}
|
||||
|
||||
int
|
||||
socketpair_cloexec_nonblock(int domain, int type, int protocol, int sv[2])
|
||||
{
|
||||
int ret;
|
||||
|
||||
#if defined(SOCK_CLOEXEC) && defined(SOCK_NONBLOCK)
|
||||
ret = socketpair(domain, type | SOCK_CLOEXEC | SOCK_NONBLOCK, protocol,
|
||||
sv);
|
||||
if (ret >= 0 || errno != EINVAL)
|
||||
return ret;
|
||||
#endif
|
||||
|
||||
ret = socketpair(domain, type, protocol, sv);
|
||||
if (ret >= 0) {
|
||||
fd_set_cloexec(sv[0], true);
|
||||
fd_set_nonblock(sv[0]);
|
||||
fd_set_cloexec(sv[1], true);
|
||||
fd_set_nonblock(sv[1]);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
int
|
||||
|
@ -89,6 +89,13 @@ pipe_cloexec_nonblock(int fd[2]);
|
||||
int
|
||||
socketpair_cloexec(int domain, int type, int protocol, int sv[2]);
|
||||
|
||||
/**
|
||||
* Wrapper for socketpair(), which sets the flags CLOEXEC and NONBLOCK
|
||||
* (atomically if supported by the OS).
|
||||
*/
|
||||
int
|
||||
socketpair_cloexec_nonblock(int domain, int type, int protocol, int sv[2]);
|
||||
|
||||
#endif
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user