summaryrefslogtreecommitdiffstats
path: root/src/network/socket
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2015-07-10 22:09:15 -0700
committerThiago Macieira <thiago.macieira@intel.com>2015-07-17 17:36:19 +0000
commit85ff35126623e6f26c84d9fa8a35b6762aefb110 (patch)
treec4ddd4482f4d0f435612d4471ee0af311396cf00 /src/network/socket
parent61e621def380f28183b6ce7047e9a88a49f81f82 (diff)
Revamp the CLOEXEC support in Qt
The pipe2/dup3/accept4 functions and SOCK_CLOEXEC are quite old nowadays on Linux. They were introduced on Linux 2.6.28 and glibc 2.10, all from 2008. They were also picked up by uClibc in 2011 and FreeBSD as of version 10.0. So we no longer need the runtime detection of whether the feature is available. Instead, if the libc has support for it, use it unconditionally and fail at runtime if the syscall isn't implemented. Change-Id: Ib056b47dde3341ef9a52ffff13efcc39ef8dff7d Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>
Diffstat (limited to 'src/network/socket')
-rw-r--r--src/network/socket/qnet_unix_p.h18
1 files changed, 8 insertions, 10 deletions
diff --git a/src/network/socket/qnet_unix_p.h b/src/network/socket/qnet_unix_p.h
index cd118afd63..a5a87fc7c1 100644
--- a/src/network/socket/qnet_unix_p.h
+++ b/src/network/socket/qnet_unix_p.h
@@ -77,15 +77,13 @@ static inline int qt_safe_socket(int domain, int type, int protocol, int flags =
Q_ASSERT((flags & ~O_NONBLOCK) == 0);
int fd;
-#if defined(SOCK_CLOEXEC) && defined(SOCK_NONBLOCK)
+#ifdef QT_THREADSAFE_CLOEXEC
int newtype = type | SOCK_CLOEXEC;
if (flags & O_NONBLOCK)
newtype |= SOCK_NONBLOCK;
fd = ::socket(domain, newtype, protocol);
- if (fd != -1 || errno != EINVAL)
- return fd;
-#endif
-
+ return fd;
+#else
fd = ::socket(domain, type, protocol);
if (fd == -1)
return -1;
@@ -97,6 +95,7 @@ static inline int qt_safe_socket(int domain, int type, int protocol, int flags =
::fcntl(fd, F_SETFL, ::fcntl(fd, F_GETFL) | O_NONBLOCK);
return fd;
+#endif
}
// Tru64 redefines accept -> _accept with _XOPEN_SOURCE_EXTENDED
@@ -105,16 +104,14 @@ static inline int qt_safe_accept(int s, struct sockaddr *addr, QT_SOCKLEN_T *add
Q_ASSERT((flags & ~O_NONBLOCK) == 0);
int fd;
-#if QT_UNIX_SUPPORTS_THREADSAFE_CLOEXEC && defined(SOCK_CLOEXEC) && defined(SOCK_NONBLOCK)
+#ifdef QT_THREADSAFE_CLOEXEC
// use accept4
int sockflags = SOCK_CLOEXEC;
if (flags & O_NONBLOCK)
sockflags |= SOCK_NONBLOCK;
fd = ::accept4(s, addr, static_cast<QT_SOCKLEN_T *>(addrlen), sockflags);
- if (fd != -1 || !(errno == ENOSYS || errno == EINVAL))
- return fd;
-#endif
-
+ return fd;
+#else
fd = ::accept(s, addr, static_cast<QT_SOCKLEN_T *>(addrlen));
if (fd == -1)
return -1;
@@ -126,6 +123,7 @@ static inline int qt_safe_accept(int s, struct sockaddr *addr, QT_SOCKLEN_T *add
::fcntl(fd, F_SETFL, ::fcntl(fd, F_GETFL) | O_NONBLOCK);
return fd;
+#endif
}
// UnixWare 7 redefines listen -> _listen