summaryrefslogtreecommitdiffstats
path: root/src/network/doc/snippets/network/tcpwait.cpp
blob: b3afa84a8a40e2b99e5aa0ba51e687d0765333de (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause

#include <QTcpSocket>

int test_tcpwait()
{
    QTcpSocket socket;
    socket.connectToHost("localhost", 1025);

//! [0]
    int numRead = 0, numReadTotal = 0;
    char buffer[50];

    forever {
        numRead  = socket.read(buffer, 50);

        // do whatever with array

        numReadTotal += numRead;
        if (numRead == 0 && !socket.waitForReadyRead())
            break;
    }
//! [0]
    return numReadTotal;
}