Browse Source

support SOCK_CLOEXEC on macOS

OPENBSD_6_2
Zero King 6 years ago
parent
commit
e3106f50ac
2 changed files with 24 additions and 0 deletions
  1. +22
    -0
      compat/socket.c
  2. +2
    -0
      include/sys/socket.h

+ 22
- 0
compat/socket.c View File

@ -26,4 +26,26 @@ _socket(int domain, int type, int protocol)
return s;
}
int
_socketpair(int domain, int type, int protocol, int socket_vector[2])
{
int rc = socketpair(domain, type & ~(SOCK_CLOEXEC | SOCK_NONBLOCK), protocol, socket_vector);
int flags, i;
if (rc == -1)
return rc;
for (i = 0; i < 2; i++) {
if (type & SOCK_CLOEXEC) {
flags = fcntl(socket_vector[i], F_GETFD);
fcntl(socket_vector[i], F_SETFD, flags | FD_CLOEXEC);
}
if (type & SOCK_NONBLOCK) {
flags = fcntl(socket_vector[i], F_GETFL);
fcntl(socket_vector[i], F_SETFL, flags | O_NONBLOCK);
}
}
return rc;
}
#endif

+ 2
- 0
include/sys/socket.h View File

@ -16,8 +16,10 @@
#if !defined(SOCK_NONBLOCK) || !defined(SOCK_CLOEXEC)
#define NEED_SOCKET_FLAGS
int _socket(int domain, int type, int protocol);
int _socketpair(int domain, int type, int protocol, int socket_vector[2]);
#ifndef SOCKET_FLAGS_PRIV
#define socket(d, t, p) _socket(d, t, p)
#define socketpair(d, t, p, s) _socketpair(d, t, p, s)
#endif
#endif


Loading…
Cancel
Save