46static inline int qt_safe_socket(
int domain,
int type,
int protocol,
int flags = 0)
48 Q_ASSERT((flags & ~O_NONBLOCK) == 0);
51#ifdef QT_THREADSAFE_CLOEXEC
52 int newtype = type | SOCK_CLOEXEC;
53 if (flags & O_NONBLOCK)
54 newtype |= SOCK_NONBLOCK;
55 fd = ::socket(domain, newtype, protocol);
58 fd = ::socket(domain, type, protocol);
62 ::fcntl(fd, F_SETFD, FD_CLOEXEC);
65 if (flags & O_NONBLOCK)
66 ::fcntl(fd, F_SETFL, ::fcntl(fd, F_GETFL) | O_NONBLOCK);
72static inline int qt_safe_accept(
int s,
struct sockaddr *addr, QT_SOCKLEN_T *addrlen,
int flags = 0)
74 Q_ASSERT((flags & ~O_NONBLOCK) == 0);
79 int sockflags = SOCK_CLOEXEC;
80 if (flags & O_NONBLOCK)
81 sockflags |= SOCK_NONBLOCK;
82# if defined(Q_OS_NETBSD)
83 fd = ::paccept(s, addr,
static_cast<QT_SOCKLEN_T *>(addrlen), NULL, sockflags);
85 fd = ::accept4(s, addr,
static_cast<QT_SOCKLEN_T *>(addrlen), sockflags);
89 fd = ::accept(s, addr,
static_cast<QT_SOCKLEN_T *>(addrlen));
93 ::fcntl(fd, F_SETFD, FD_CLOEXEC);
96 if (flags & O_NONBLOCK)
97 ::fcntl(fd, F_SETFL, ::fcntl(fd, F_GETFL) | O_NONBLOCK);