Skip to content
This repository has been archived by the owner on May 4, 2018. It is now read-only.

Commit

Permalink
unix: simplify uv__make_pipe() and uv__make_socketpair()
Browse files Browse the repository at this point in the history
  • Loading branch information
bnoordhuis committed Jun 11, 2012
1 parent 5c30443 commit ddb5f55
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 25 deletions.
8 changes: 6 additions & 2 deletions src/unix/internal.h
Expand Up @@ -168,8 +168,12 @@ void uv__timer_close(uv_timer_t* handle);
void uv__udp_close(uv_udp_t* handle);
void uv__udp_finish_close(uv_udp_t* handle);

#define UV__F_IPC (1 << 0)
#define UV__F_NONBLOCK (1 << 1)
#ifdef UV__O_NONBLOCK
# define UV__F_NONBLOCK UV__O_NONBLOCK
#else
# define UV__F_NONBLOCK 1
#endif

int uv__make_socketpair(int fds[2], int flags);
int uv__make_pipe(int fds[2], int flags);

Expand Down
29 changes: 6 additions & 23 deletions src/unix/process.c
Expand Up @@ -68,25 +68,15 @@ static void uv__chld(EV_P_ ev_child* watcher, int revents) {


int uv__make_socketpair(int fds[2], int flags) {
#ifdef SOCK_NONBLOCK
int fl;

fl = SOCK_CLOEXEC;

if (flags & UV__F_NONBLOCK)
fl |= SOCK_NONBLOCK;

if (socketpair(AF_UNIX, SOCK_STREAM|fl, 0, fds) == 0)
#if __linux__
if (socketpair(AF_UNIX, SOCK_STREAM | UV__SOCK_CLOEXEC | flags, 0, fds) == 0)
return 0;

/* Retry on EINVAL, it means SOCK_CLOEXEC is not supported.
* Anything else is a genuine error.
*/
if (errno != EINVAL)
return -1;

/* errno == EINVAL so maybe the kernel headers lied about
* the availability of SOCK_NONBLOCK. This can happen if people
* build libuv against newer kernel headers than the kernel
* they actually run the software on.
*/
#endif

if (socketpair(AF_UNIX, SOCK_STREAM, 0, fds))
Expand All @@ -106,14 +96,7 @@ int uv__make_socketpair(int fds[2], int flags) {

int uv__make_pipe(int fds[2], int flags) {
#if __linux__
int fl;

fl = UV__O_CLOEXEC;

if (flags & UV__F_NONBLOCK)
fl |= UV__O_NONBLOCK;

if (uv__pipe2(fds, fl) == 0)
if (uv__pipe2(fds, flags | UV__O_CLOEXEC) == 0)
return 0;

if (errno != ENOSYS)
Expand Down

0 comments on commit ddb5f55

Please sign in to comment.