Qt 4.8
Macros | Functions
qnet_unix_p.h File Reference
#include "private/qcore_unix_p.h"
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <arpa/inet.h>
#include <resolv.h>

Go to the source code of this file.

Macros

#define QT_SOCKET_CONNECT   qt_safe_connect
 
#define QT_SOCKOPTLEN_T   QT_SOCKLEN_T
 

Functions

static int qt_safe_accept (int s, struct sockaddr *addr, QT_SOCKLEN_T *addrlen, int flags=0)
 
static int qt_safe_connect (int sockfd, const struct sockaddr *addr, QT_SOCKLEN_T addrlen)
 
static in_addr_t qt_safe_inet_addr (const char *cp)
 
template<typename T >
static int qt_safe_ioctl (int sockfd, int request, T arg)
 
static int qt_safe_listen (int s, int backlog)
 
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_socket (int domain, int type, int protocol, int flags=0)
 

Macro Definition Documentation

◆ QT_SOCKET_CONNECT

#define QT_SOCKET_CONNECT   qt_safe_connect

Definition at line 153 of file qnet_unix_p.h.

Referenced by qt_safe_connect().

◆ QT_SOCKOPTLEN_T

#define QT_SOCKOPTLEN_T   QT_SOCKLEN_T

Definition at line 79 of file qnet_unix_p.h.

Function Documentation

◆ qt_safe_accept()

static int qt_safe_accept ( int  s,
struct sockaddr *  addr,
QT_SOCKLEN_T addrlen,
int  flags = 0 
)
inlinestatic

Definition at line 111 of file qnet_unix_p.h.

Referenced by QNativeSocketEnginePrivate::nativeAccept().

112 {
113  Q_ASSERT((flags & ~O_NONBLOCK) == 0);
114 
115  register int fd;
116 #if QT_UNIX_SUPPORTS_THREADSAFE_CLOEXEC && defined(SOCK_CLOEXEC) && defined(SOCK_NONBLOCK)
117  // use accept4
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))
123  return fd;
124 #endif
125 
126  fd = ::accept(s, addr, static_cast<QT_SOCKLEN_T *>(addrlen));
127  if (fd == -1)
128  return -1;
129 
130  ::fcntl(fd, F_SETFD, FD_CLOEXEC);
131 
132  // set non-block too?
133  if (flags & O_NONBLOCK)
134  ::fcntl(fd, F_SETFL, ::fcntl(fd, F_GETFL) | O_NONBLOCK);
135 
136  return fd;
137 }
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
int fcntl(int, int,...)
int errno

◆ qt_safe_connect()

static int qt_safe_connect ( int  sockfd,
const struct sockaddr *  addr,
QT_SOCKLEN_T  addrlen 
)
inlinestatic

Definition at line 145 of file qnet_unix_p.h.

Referenced by QNativeSocketEnginePrivate::nativeConnect().

146 {
147  register int ret;
148  // Solaris e.g. expects a non-const 2nd parameter
149  EINTR_LOOP(ret, QT_SOCKET_CONNECT(sockfd, const_cast<struct sockaddr *>(addr), addrlen));
150  return ret;
151 }
#define EINTR_LOOP(var, cmd)
Definition: qcore_unix_p.h:96
#define QT_SOCKET_CONNECT
Definition: qnet_unix_p.h:153

◆ qt_safe_inet_addr()

static in_addr_t qt_safe_inet_addr ( const char *  cp)
inlinestatic

Definition at line 177 of file qnet_unix_p.h.

Referenced by QHostInfoAgent::fromName().

178 {
179 #ifdef Q_OS_VXWORKS
180  return ::inet_addr((char *) cp);
181 #else
182  return ::inet_addr(cp);
183 #endif
184 }

◆ qt_safe_ioctl()

template<typename T >
static int qt_safe_ioctl ( int  sockfd,
int  request,
arg 
)
inlinestatic

Definition at line 167 of file qnet_unix_p.h.

Referenced by convertFlags(), QNativeSocketEnginePrivate::nativeBytesAvailable(), and QNativeSocketEnginePrivate::setOption().

168 {
169 #ifdef Q_OS_VXWORKS
170  return ::ioctl(sockfd, request, (int) arg);
171 #else
172  return ::ioctl(sockfd, request, arg);
173 #endif
174 }

◆ qt_safe_listen()

static int qt_safe_listen ( int  s,
int  backlog 
)
inlinestatic

Definition at line 140 of file qnet_unix_p.h.

Referenced by QNativeSocketEnginePrivate::nativeListen().

141 {
142  return ::listen(s, backlog);
143 }

◆ qt_safe_sendto()

static int qt_safe_sendto ( int  sockfd,
const void *  buf,
size_t  len,
int  flags,
const struct sockaddr *  to,
QT_SOCKLEN_T  tolen 
)
inlinestatic

Definition at line 187 of file qnet_unix_p.h.

Referenced by QNativeSocketEnginePrivate::nativeSendDatagram().

188 {
189 #ifdef MSG_NOSIGNAL
190  flags |= MSG_NOSIGNAL;
191 #else
193 #endif
194 
195  register int ret;
196 #ifdef Q_OS_VXWORKS
197  EINTR_LOOP(ret, ::sendto(sockfd, (char *) buf, len, flags, (struct sockaddr *) to, tolen));
198 #else
199  EINTR_LOOP(ret, ::sendto(sockfd, buf, len, flags, to, tolen));
200 #endif
201  return ret;
202 }
#define EINTR_LOOP(var, cmd)
Definition: qcore_unix_p.h:96
void qt_ignore_sigpipe()
Definition: qcore_unix_p.h:148

◆ qt_safe_socket()

static int qt_safe_socket ( int  domain,
int  type,
int  protocol,
int  flags = 0 
)
inlinestatic

Definition at line 83 of file qnet_unix_p.h.

Referenced by convertFlags(), QNativeSocketEnginePrivate::createNewSocket(), and interfaceListing().

84 {
85  Q_ASSERT((flags & ~O_NONBLOCK) == 0);
86 
87  register int fd;
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)
94  return fd;
95 #endif
96 
97  fd = ::socket(domain, type, protocol);
98  if (fd == -1)
99  return -1;
100 
101  ::fcntl(fd, F_SETFD, FD_CLOEXEC);
102 
103  // set non-block too?
104  if (flags & O_NONBLOCK)
105  ::fcntl(fd, F_SETFL, ::fcntl(fd, F_GETFL) | O_NONBLOCK);
106 
107  return fd;
108 }
int type
Definition: qmetatype.cpp:239
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
int fcntl(int, int,...)
int errno