socket/qlocalserver_unix.cpp

Switch to Source codePreprocessed file
LineSource CodeCoverage
1 -
2 -
3 -
4 -
5 -
6 -
7 -
8 -
9 -
10 -
11 -
12 -
13void QLocalServerPrivate::init() -
14{ -
15} -
16 -
17bool QLocalServerPrivate::removeServer(const QString &name) -
18{ -
19 QString fileName; -
20 if (name.startsWith(QLatin1Char('/'))) {
partially evaluated: name.startsWith(QLatin1Char('/'))
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:37
0-37
21 fileName = name; -
22 } else {
never executed: }
0
23 fileName = QDir::cleanPath(QDir::tempPath()); -
24 fileName += QLatin1Char('/') + name; -
25 }
executed: }
Execution Count:37
37
26 if (QFile::exists(fileName))
evaluated: QFile::exists(fileName)
TRUEFALSE
yes
Evaluation Count:11
yes
Evaluation Count:26
11-26
27 return QFile::remove(fileName);
executed: return QFile::remove(fileName);
Execution Count:11
11
28 else -
29 return true;
executed: return true;
Execution Count:26
26
30} -
31 -
32bool QLocalServerPrivate::listen(const QString &requestedServerName) -
33{ -
34 QLocalServer * const q = q_func(); -
35 -
36 -
37 if (requestedServerName.startsWith(QLatin1Char('/'))) {
evaluated: requestedServerName.startsWith(QLatin1Char('/'))
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:43
1-43
38 fullServerName = requestedServerName; -
39 } else {
executed: }
Execution Count:1
1
40 fullServerName = QDir::cleanPath(QDir::tempPath()); -
41 fullServerName += QLatin1Char('/') + requestedServerName; -
42 }
executed: }
Execution Count:43
43
43 serverName = requestedServerName; -
44 -
45 QString tempPath; -
46 QScopedPointer<QTemporaryDir> tempDir; -
47 -
48 -
49 if (socketOptions & QLocalServer::WorldAccessOption) {
evaluated: socketOptions & QLocalServer::WorldAccessOption
TRUEFALSE
yes
Evaluation Count:4
yes
Evaluation Count:40
4-40
50 tempDir.reset(new QTemporaryDir(fullServerName)); -
51 if (!tempDir->isValid()) {
partially evaluated: !tempDir->isValid()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:4
0-4
52 setError(QLatin1String("QLocalServer::listen")); -
53 return false;
never executed: return false;
0
54 } -
55 tempPath = tempDir->path(); -
56 tempPath += QLatin1Char('/') + requestedServerName; -
57 }
executed: }
Execution Count:4
4
58 -
59 -
60 listenSocket = qt_safe_socket(1, SOCK_STREAM, 0); -
61 if (-1 == listenSocket) {
partially evaluated: -1 == listenSocket
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:44
0-44
62 setError(QLatin1String("QLocalServer::listen")); -
63 closeServer(); -
64 return false;
never executed: return false;
0
65 } -
66 -
67 -
68 struct ::sockaddr_un addr; -
69 addr.sun_family = 1; -
70 if (sizeof(addr.sun_path) < (uint)fullServerName.toLatin1().size() + 1) {
evaluated: sizeof(addr.sun_path) < (uint)fullServerName.toLatin1().size() + 1
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:43
1-43
71 setError(QLatin1String("QLocalServer::listen")); -
72 closeServer(); -
73 return false;
executed: return false;
Execution Count:1
1
74 } -
75 -
76 if (socketOptions & QLocalServer::WorldAccessOption) {
evaluated: socketOptions & QLocalServer::WorldAccessOption
TRUEFALSE
yes
Evaluation Count:4
yes
Evaluation Count:39
4-39
77 if (sizeof(addr.sun_path) < (uint)tempPath.toLatin1().size() + 1) {
partially evaluated: sizeof(addr.sun_path) < (uint)tempPath.toLatin1().size() + 1
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:4
0-4
78 setError(QLatin1String("QLocalServer::listen")); -
79 closeServer(); -
80 return false;
never executed: return false;
0
81 } -
82 ::memcpy(addr.sun_path, tempPath.toLatin1().data(), -
83 tempPath.toLatin1().size() + 1); -
84 -
85 if (-1 == ::fchmod(listenSocket, 0)) {
partially evaluated: -1 == ::fchmod(listenSocket, 0)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:4
0-4
86 setError(QLatin1String("QLocalServer::listen")); -
87 closeServer(); -
88 return false;
never executed: return false;
0
89 } -
90 -
91 } else {
executed: }
Execution Count:4
4
92 ::memcpy(addr.sun_path, fullServerName.toLatin1().data(), -
93 fullServerName.toLatin1().size() + 1); -
94 }
executed: }
Execution Count:39
39
95 -
96 -
97 if(-1 == ::bind(listenSocket, (sockaddr *)&addr, sizeof(sockaddr_un))) {
evaluated: -1 == ::bind(listenSocket, (sockaddr *)&addr, sizeof(sockaddr_un))
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:42
1-42
98 setError(QLatin1String("QLocalServer::listen")); -
99 -
100 if((*__errno_location ()) == 98)
partially evaluated: (*__errno_location ()) == 98
TRUEFALSE
yes
Evaluation Count:1
no
Evaluation Count:0
0-1
101 qt_safe_close(listenSocket);
executed: qt_safe_close(listenSocket);
Execution Count:1
1
102 -
103 else -
104 closeServer();
never executed: closeServer();
0
105 listenSocket = -1; -
106 return false;
executed: return false;
Execution Count:1
1
107 } -
108 -
109 -
110 if (-1 == qt_safe_listen(listenSocket, 50)) {
partially evaluated: -1 == qt_safe_listen(listenSocket, 50)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:42
0-42
111 setError(QLatin1String("QLocalServer::listen")); -
112 closeServer(); -
113 listenSocket = -1; -
114 if (error != QAbstractSocket::AddressInUseError)
never evaluated: error != QAbstractSocket::AddressInUseError
0
115 QFile::remove(fullServerName);
never executed: QFile::remove(fullServerName);
0
116 return false;
never executed: return false;
0
117 } -
118 -
119 if (socketOptions & QLocalServer::WorldAccessOption) {
evaluated: socketOptions & QLocalServer::WorldAccessOption
TRUEFALSE
yes
Evaluation Count:4
yes
Evaluation Count:38
4-38
120 mode_t mode = 000; -
121 -
122 if (socketOptions & QLocalServer::UserAccessOption) {
evaluated: socketOptions & QLocalServer::UserAccessOption
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:2
2
123 mode |= (0400|0200|0100); -
124 }
executed: }
Execution Count:2
2
125 if (socketOptions & QLocalServer::GroupAccessOption) {
evaluated: socketOptions & QLocalServer::GroupAccessOption
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:2
2
126 mode |= ((0400|0200|0100) >> 3); -
127 }
executed: }
Execution Count:2
2
128 if (socketOptions & QLocalServer::OtherAccessOption) {
evaluated: socketOptions & QLocalServer::OtherAccessOption
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:2
2
129 mode |= (((0400|0200|0100) >> 3) >> 3); -
130 }
executed: }
Execution Count:2
2
131 -
132 if (mode) {
partially evaluated: mode
TRUEFALSE
yes
Evaluation Count:4
no
Evaluation Count:0
0-4
133 if (-1 == ::chmod(tempPath.toLatin1(), mode)) {
partially evaluated: -1 == ::chmod(tempPath.toLatin1(), mode)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:4
0-4
134 setError(QLatin1String("QLocalServer::listen")); -
135 closeServer(); -
136 return false;
never executed: return false;
0
137 } -
138 }
executed: }
Execution Count:4
4
139 if (-1 == ::rename(tempPath.toLatin1(), fullServerName.toLatin1())){
partially evaluated: -1 == ::rename(tempPath.toLatin1(), fullServerName.toLatin1())
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:4
0-4
140 setError(QLatin1String("QLocalServer::listen")); -
141 closeServer(); -
142 return false;
never executed: return false;
0
143 } -
144 }
executed: }
Execution Count:4
4
145 -
146 qt_noop(); -
147 socketNotifier = new QSocketNotifier(listenSocket, -
148 QSocketNotifier::Read, q); -
149 q->connect(socketNotifier, "2""activated(int)", -
150 q, "1""_q_onNewConnection()"); -
151 socketNotifier->setEnabled(maxPendingConnections > 0); -
152 return true;
executed: return true;
Execution Count:42
42
153} -
154 -
155bool QLocalServerPrivate::listen(qintptr socketDescriptor) -
156{ -
157 QLocalServer * const q = q_func(); -
158 -
159 -
160 listenSocket = socketDescriptor; -
161 -
162 ::fcntl(listenSocket, 2, 1); -
163 ::fcntl(listenSocket, 4, ::fcntl(listenSocket, 3) | 04000); -
164 -
165 -
166 struct ::sockaddr_un addr; -
167 socklen_t len = sizeof(addr); -
168 memset(&addr, 0, sizeof(addr)); -
169 if (0 == ::getsockname(listenSocket, (sockaddr *)&addr, &len)) {
partially evaluated: 0 == ::getsockname(listenSocket, (sockaddr *)&addr, &len)
TRUEFALSE
yes
Evaluation Count:4
no
Evaluation Count:0
0-4
170 -
171 if (addr.sun_family == 1 && addr.sun_path[0] == 0) {
partially evaluated: addr.sun_family == 1
TRUEFALSE
yes
Evaluation Count:4
no
Evaluation Count:0
evaluated: addr.sun_path[0] == 0
TRUEFALSE
yes
Evaluation Count:3
yes
Evaluation Count:1
0-4
172 addr.sun_path[0] = '@'; -
173 }
executed: }
Execution Count:3
3
174 QString name = QString::fromLatin1(addr.sun_path); -
175 if (!name.isEmpty()) {
partially evaluated: !name.isEmpty()
TRUEFALSE
yes
Evaluation Count:4
no
Evaluation Count:0
0-4
176 fullServerName = name; -
177 serverName = fullServerName.mid(fullServerName.lastIndexOf(QLatin1String("/"))+1); -
178 if (serverName.isEmpty()) {
partially evaluated: serverName.isEmpty()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:4
0-4
179 serverName = fullServerName; -
180 }
never executed: }
0
181 }
executed: }
Execution Count:4
4
182 }
executed: }
Execution Count:4
4
183 -
184 -
185 -
186 -
187 -
188 qt_noop(); -
189 socketNotifier = new QSocketNotifier(listenSocket, -
190 QSocketNotifier::Read, q); -
191 q->connect(socketNotifier, "2""activated(int)", -
192 q, "1""_q_onNewConnection()"); -
193 socketNotifier->setEnabled(maxPendingConnections > 0); -
194 return true;
executed: return true;
Execution Count:4
4
195} -
196 -
197 -
198 -
199 -
200 -
201 -
202void QLocalServerPrivate::closeServer() -
203{ -
204 if (socketNotifier) {
evaluated: socketNotifier
TRUEFALSE
yes
Evaluation Count:46
yes
Evaluation Count:1
1-46
205 socketNotifier->setEnabled(false); -
206 socketNotifier->deleteLater(); -
207 socketNotifier = 0; -
208 }
executed: }
Execution Count:46
46
209 -
210 if (-1 != listenSocket)
partially evaluated: -1 != listenSocket
TRUEFALSE
yes
Evaluation Count:47
no
Evaluation Count:0
0-47
211 qt_safe_close(listenSocket);
executed: qt_safe_close(listenSocket);
Execution Count:47
47
212 listenSocket = -1; -
213 -
214 if (!fullServerName.isEmpty())
partially evaluated: !fullServerName.isEmpty()
TRUEFALSE
yes
Evaluation Count:47
no
Evaluation Count:0
0-47
215 QFile::remove(fullServerName);
executed: QFile::remove(fullServerName);
Execution Count:47
47
216}
executed: }
Execution Count:47
47
217 -
218 -
219 -
220 -
221 -
222 -
223 -
224void QLocalServerPrivate::_q_onNewConnection() -
225{ -
226 QLocalServer * const q = q_func(); -
227 if (-1 == listenSocket)
partially evaluated: -1 == listenSocket
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:71
0-71
228 return;
never executed: return;
0
229 -
230 ::sockaddr_un addr; -
231 socklen_t length = sizeof(sockaddr_un); -
232 int connectedSocket = qt_safe_accept(listenSocket, (sockaddr *)&addr, &length); -
233 if(-1 == connectedSocket) {
partially evaluated: -1 == connectedSocket
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:71
0-71
234 setError(QLatin1String("QLocalSocket::activated")); -
235 closeServer(); -
236 } else {
never executed: }
0
237 socketNotifier->setEnabled(pendingConnections.size() -
238 <= maxPendingConnections); -
239 q->incomingConnection(connectedSocket); -
240 }
executed: }
Execution Count:71
71
241} -
242 -
243void QLocalServerPrivate::waitForNewConnection(int msec, bool *timedOut) -
244{ -
245 fd_set readfds; -
246 do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&readfds)->fds_bits)[0]) : "memory"); } while (0);
executed: }
Execution Count:73
partially evaluated: 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:73
0-73
247 (((&readfds)->fds_bits)[((listenSocket) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) 1 << ((listenSocket) % (8 * (int) sizeof (__fd_mask))))); -
248 -
249 timeval timeout; -
250 timeout.tv_sec = msec / 1000; -
251 timeout.tv_usec = (msec % 1000) * 1000; -
252 -
253 int result = -1; -
254 result = qt_safe_select(listenSocket + 1, &readfds, 0, 0, (msec == -1) ? 0 : &timeout); -
255 if (-1 == result) {
partially evaluated: -1 == result
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:73
0-73
256 setError(QLatin1String("QLocalServer::waitForNewConnection")); -
257 closeServer(); -
258 }
never executed: }
0
259 if (result > 0)
evaluated: result > 0
TRUEFALSE
yes
Evaluation Count:71
yes
Evaluation Count:2
2-71
260 _q_onNewConnection();
executed: _q_onNewConnection();
Execution Count:71
71
261 if (timedOut)
evaluated: timedOut
TRUEFALSE
yes
Evaluation Count:54
yes
Evaluation Count:19
19-54
262 *timedOut = (result == 0);
executed: *timedOut = (result == 0);
Execution Count:54
54
263}
executed: }
Execution Count:73
73
264 -
265void QLocalServerPrivate::setError(const QString &function) -
266{ -
267 if (11 == (*__errno_location ()))
partially evaluated: 11 == (*__errno_location ())
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2
0-2
268 return;
never executed: return;
0
269 -
270 switch ((*__errno_location ())) { -
271 case 13: -
272 errorString = QLocalServer::tr("%1: Permission denied").arg(function); -
273 error = QAbstractSocket::SocketAccessError; -
274 break;
never executed: break;
0
275 case 40: -
276 case 2: -
277 case 36: -
278 case 30: -
279 case 20: -
280 errorString = QLocalServer::tr("%1: Name error").arg(function); -
281 error = QAbstractSocket::HostNotFoundError; -
282 break;
executed: break;
Execution Count:1
1
283 case 98: -
284 errorString = QLocalServer::tr("%1: Address in use").arg(function); -
285 error = QAbstractSocket::AddressInUseError; -
286 break;
executed: break;
Execution Count:1
1
287 -
288 default: -
289 errorString = QLocalServer::tr("%1: Unknown error %2") -
290 .arg(function).arg((*__errno_location ())); -
291 error = QAbstractSocket::UnknownSocketError; -
292 -
293 -
294 -
295 }
never executed: }
0
296}
executed: }
Execution Count:2
2
297 -
298 -
299 -
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial