fd_util: add function socketpair_cloexec()
This commit is contained in:
parent
36782a977a
commit
c980fc653d
@ -174,6 +174,30 @@ pipe_cloexec_nonblock(int fd[2])
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef WIN32
|
||||||
|
|
||||||
|
int
|
||||||
|
socketpair_cloexec(int domain, int type, int protocol, int sv[2])
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
#ifdef SOCK_CLOEXEC
|
||||||
|
ret = socketpair(domain, type | SOCK_CLOEXEC, 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_cloexec(sv[1], true);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
int
|
int
|
||||||
socket_cloexec_nonblock(int domain, int type, int protocol)
|
socket_cloexec_nonblock(int domain, int type, int protocol)
|
||||||
{
|
{
|
||||||
|
@ -65,6 +65,17 @@ pipe_cloexec(int fd[2]);
|
|||||||
int
|
int
|
||||||
pipe_cloexec_nonblock(int fd[2]);
|
pipe_cloexec_nonblock(int fd[2]);
|
||||||
|
|
||||||
|
#ifndef WIN32
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wrapper for socketpair(), which sets the CLOEXEC flag (atomically
|
||||||
|
* if supported by the OS).
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
socketpair_cloexec(int domain, int type, int protocol, int sv[2]);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wrapper for socket(), which sets the CLOEXEC and the NONBLOCK flag
|
* Wrapper for socket(), which sets the CLOEXEC and the NONBLOCK flag
|
||||||
* (atomically if supported by the OS).
|
* (atomically if supported by the OS).
|
||||||
|
Loading…
Reference in New Issue
Block a user