56 #include "private/qcore_unix_p.h" 58 #include <sys/types.h> 59 #include <sys/socket.h> 60 #include <netinet/in.h> 62 #if defined(Q_OS_VXWORKS) 68 #include <arpa/inet.h> 69 #if defined(Q_OS_VXWORKS) 78 #if !defined(QT_SOCKOPTLEN_T) 79 # define QT_SOCKOPTLEN_T QT_SOCKLEN_T 85 Q_ASSERT((flags & ~O_NONBLOCK) == 0);
88 #if defined(SOCK_CLOEXEC) && defined(SOCK_NONBLOCK) 89 int newtype = type | SOCK_CLOEXEC;
90 if (flags & O_NONBLOCK)
91 newtype |= SOCK_NONBLOCK;
92 fd = ::socket(domain, newtype, protocol);
93 if (fd != -1 ||
errno != EINVAL)
97 fd = ::socket(domain, type, protocol);
101 ::fcntl(fd, F_SETFD, FD_CLOEXEC);
104 if (flags & O_NONBLOCK)
105 ::fcntl(fd, F_SETFL, ::
fcntl(fd, F_GETFL) | O_NONBLOCK);
113 Q_ASSERT((flags & ~O_NONBLOCK) == 0);
116 #if QT_UNIX_SUPPORTS_THREADSAFE_CLOEXEC && defined(SOCK_CLOEXEC) && defined(SOCK_NONBLOCK) 118 int sockflags = SOCK_CLOEXEC;
119 if (flags & O_NONBLOCK)
120 sockflags |= SOCK_NONBLOCK;
121 fd = ::accept4(s, addr, static_cast<QT_SOCKLEN_T *>(addrlen), sockflags);
122 if (fd != -1 || !(
errno == ENOSYS ||
errno == EINVAL))
126 fd = ::accept(s, addr, static_cast<QT_SOCKLEN_T *>(addrlen));
130 ::fcntl(fd, F_SETFD, FD_CLOEXEC);
133 if (flags & O_NONBLOCK)
134 ::fcntl(fd, F_SETFL, ::
fcntl(fd, F_GETFL) | O_NONBLOCK);
142 return ::listen(s, backlog);
152 #undef QT_SOCKET_CONNECT 153 #define QT_SOCKET_CONNECT qt_safe_connect 166 template <
typename T>
170 return ::ioctl(sockfd, request, (
int) arg);
172 return ::ioctl(sockfd, request, arg);
180 return ::inet_addr((
char *) cp);
182 return ::inet_addr(cp);
190 flags |= MSG_NOSIGNAL;
197 EINTR_LOOP(ret, ::sendto(sockfd, (
char *) buf, len, flags, (
struct sockaddr *) to, tolen));
199 EINTR_LOOP(ret, ::sendto(sockfd, buf, len, flags, to, tolen));
206 #endif // QNET_UNIX_P_H
#define QT_END_NAMESPACE
This macro expands to.
#define EINTR_LOOP(var, cmd)
static int qt_safe_ioctl(int sockfd, int request, T arg)
#define QT_BEGIN_NAMESPACE
This macro expands to.
static int qt_safe_connect(int sockfd, const struct sockaddr *addr, QT_SOCKLEN_T addrlen)
#define QT_SOCKET_CONNECT
static int qt_safe_socket(int domain, int type, int protocol, int flags=0)
static int qt_safe_sendto(int sockfd, const void *buf, size_t len, int flags, const struct sockaddr *to, QT_SOCKLEN_T tolen)
static int qt_safe_accept(int s, struct sockaddr *addr, QT_SOCKLEN_T *addrlen, int flags=0)
static in_addr_t qt_safe_inet_addr(const char *cp)
static int qt_safe_listen(int s, int backlog)