Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
qnet_unix_p.h
Go to the documentation of this file.
1
// Copyright (C) 2016 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
// Qt-Security score:significant reason:default
4
5
#
ifndef
QNET_UNIX_P_H
6
#
define
QNET_UNIX_P_H
7
8
//
9
// W A R N I N G
10
// -------------
11
//
12
// This file is not part of the Qt API. It exists for the convenience
13
// of Qt code on Unix. This header file may change from version to
14
// version to version without notice, or even be removed.
15
//
16
// We mean it.
17
//
18
19
#
include
<
QtNetwork
/
private
/
qtnetworkglobal_p
.
h
>
20
#
include
"private/qcore_unix_p.h"
21
22
#
include
<
sys
/
types
.
h
>
23
#
include
<
sys
/
socket
.
h
>
24
#
include
<
netinet
/
in
.
h
>
25
26
#
if
defined
(
Q_OS_VXWORKS
)
27
#
include
<
sockLib
.
h
>
28
#
endif
29
30
// for inet_addr
31
#
include
<
netdb
.
h
>
32
#
include
<
arpa
/
inet
.
h
>
33
#
if
defined
(
Q_OS_VXWORKS
)
34
#
include
<
hostLib
.
h
>
35
#
else
36
#
include
<
resolv
.
h
>
37
#
endif
38
39
QT_BEGIN_NAMESPACE
40
41
// Almost always the same. If not, specify in qplatformdefs.h.
42
#
if
!
defined
(
QT_SOCKOPTLEN_T
)
43
#
define
QT_SOCKOPTLEN_T
QT_SOCKLEN_T
44
#
endif
45
46
static
inline
int
qt_safe_socket
(
int
domain,
int
type,
int
protocol,
int
flags = 0)
47
{
48
Q_ASSERT((flags & ~O_NONBLOCK) == 0);
49
50
int
fd;
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);
56
return
fd;
57
#
else
58
fd = ::socket(domain, type, protocol);
59
if
(fd == -1)
60
return
-1;
61
62
::fcntl(fd, F_SETFD, FD_CLOEXEC);
63
64
// set non-block too?
65
if
(flags & O_NONBLOCK)
66
::fcntl(fd, F_SETFL, ::fcntl(fd, F_GETFL) | O_NONBLOCK);
67
68
return
fd;
69
#
endif
70
}
71
72
static
inline
int
qt_safe_accept
(
int
s,
struct
sockaddr *addr, QT_SOCKLEN_T *addrlen,
int
flags = 0)
73
{
74
Q_ASSERT((flags & ~O_NONBLOCK) == 0);
75
76
int
fd;
77
#
if
QT_CONFIG
(
accept4
)
78
// use accept4
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);
84
#
else
85
fd = ::accept4(s, addr,
static_cast
<QT_SOCKLEN_T *>(addrlen), sockflags);
86
#
endif
87
return
fd;
88
#
else
89
fd = ::accept(s, addr,
static_cast
<QT_SOCKLEN_T *>(addrlen));
90
if
(fd == -1)
91
return
-1;
92
93
::fcntl(fd, F_SETFD, FD_CLOEXEC);
94
95
// set non-block too?
96
if
(flags & O_NONBLOCK)
97
::fcntl(fd, F_SETFL, ::fcntl(fd, F_GETFL) | O_NONBLOCK);
98
99
return
fd;
100
#
endif
101
}
102
103
static
inline
int
qt_safe_listen
(
int
s,
int
backlog)
104
{
105
return
::listen(s, backlog);
106
}
107
108
static
inline
int
qt_safe_connect
(
int
sockfd,
const
struct
sockaddr *addr, QT_SOCKLEN_T addrlen)
109
{
110
int
ret;
111
#
ifdef
Q_OS_WASM
112
errno = 0;
113
#
endif
114
// Solaris e.g. expects a non-const 2nd parameter
115
QT_EINTR_LOOP(ret, QT_SOCKET_CONNECT(sockfd,
const_cast
<
struct
sockaddr *>(addr), addrlen));
116
#
ifdef
Q_OS_WASM
117
// ::connect on wasm returns 0 when it shouldn't so use errno instead
118
if
(errno != 0)
119
ret = -1;
120
#
endif
121
return
ret;
122
}
123
#
undef
QT_SOCKET_CONNECT
124
#
define
QT_SOCKET_CONNECT
qt_safe_connect
125
126
#
if
defined
(
socket
)
127
#
undef
socket
128
#
endif
129
#
if
defined
(
accept
)
130
#
undef
accept
131
#
endif
132
#
if
defined
(
listen
)
133
#
undef
listen
134
#
endif
135
136
template
<
typename
T>
137
static
inline
int
qt_safe_ioctl
(
int
sockfd,
unsigned
long
request, T arg)
138
{
139
return
::ioctl(sockfd, request, arg);
140
}
141
142
static
inline
int
qt_safe_sendmsg
(
int
sockfd,
const
struct
msghdr *msg,
int
flags)
143
{
144
#
ifdef
MSG_NOSIGNAL
145
flags |= MSG_NOSIGNAL;
146
#
else
147
qt_ignore_sigpipe();
148
#
endif
149
150
int
ret;
151
QT_EINTR_LOOP(ret, ::sendmsg(sockfd, msg, flags));
152
return
ret;
153
}
154
155
static
inline
int
qt_safe_recvmsg
(
int
sockfd,
struct
msghdr *msg,
int
flags)
156
{
157
int
ret;
158
159
QT_EINTR_LOOP(ret, ::recvmsg(sockfd, msg, flags));
160
return
ret;
161
}
162
163
QT_END_NAMESPACE
164
165
#
endif
// QNET_UNIX_P_H
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
qt_safe_ioctl
static int qt_safe_ioctl(int sockfd, unsigned long request, T arg)
Definition
qnet_unix_p.h:137
qt_safe_listen
static int qt_safe_listen(int s, int backlog)
Definition
qnet_unix_p.h:103
qt_safe_sendmsg
static int qt_safe_sendmsg(int sockfd, const struct msghdr *msg, int flags)
Definition
qnet_unix_p.h:142
qt_safe_socket
static int qt_safe_socket(int domain, int type, int protocol, int flags=0)
Definition
qnet_unix_p.h:46
qt_safe_accept
static int qt_safe_accept(int s, struct sockaddr *addr, QT_SOCKLEN_T *addrlen, int flags=0)
Definition
qnet_unix_p.h:72
qt_safe_recvmsg
static int qt_safe_recvmsg(int sockfd, struct msghdr *msg, int flags)
Definition
qnet_unix_p.h:155
qt_safe_connect
static int qt_safe_connect(int sockfd, const struct sockaddr *addr, QT_SOCKLEN_T addrlen)
Definition
qnet_unix_p.h:108
qtbase
src
network
socket
qnet_unix_p.h
Generated on
for Qt by
1.18.0