1 | // Copyright (C) 2016 The Qt Company Ltd. |
---|---|
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause |
3 | |
4 | #include <QTcpSocket> |
5 | |
6 | int test_tcpwait() |
7 | { |
8 | QTcpSocket socket; |
9 | socket.connectToHost(hostName: "localhost", port: 1025); |
10 | |
11 | //! [0] |
12 | int numRead = 0, numReadTotal = 0; |
13 | char buffer[50]; |
14 | |
15 | forever { |
16 | numRead = socket.read(data: buffer, maxlen: 50); |
17 | |
18 | // do whatever with array |
19 | |
20 | numReadTotal += numRead; |
21 | if (numRead == 0 && !socket.waitForReadyRead()) |
22 | break; |
23 | } |
24 | //! [0] |
25 | return numReadTotal; |
26 | } |
27 |