Coverage Report

Created: 2026-04-29 07:00

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/qtbase/src/network/socket/qabstractsocket_p.h
Line
Count
Source
1
// Copyright (C) 2022 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 QABSTRACTSOCKET_P_H
6
#define QABSTRACTSOCKET_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 the QAbstractSocket class.  This header file may change from
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 "QtNetwork/qabstractsocket.h"
21
#include "QtCore/qbytearray.h"
22
#include "QtCore/qlist.h"
23
#include "QtCore/qtimer.h"
24
#include "private/qiodevice_p.h"
25
#include "private/qabstractsocketenginereceiver_p.h"
26
#include "qnetworkproxy.h"
27
28
QT_BEGIN_NAMESPACE
29
30
class QAbstractSocketEngine;
31
class QHostInfo;
32
class QNetworkInterface;
33
34
class Q_NETWORK_EXPORT QAbstractSocketPrivate : public QIODevicePrivate,
35
                                                public QAbstractSocketEngineReceiver
36
{
37
0
    Q_DECLARE_PUBLIC(QAbstractSocket)
Unexecuted instantiation: QAbstractSocketPrivate::q_func()
Unexecuted instantiation: QAbstractSocketPrivate::q_func() const
38
0
public:
39
0
    QAbstractSocketPrivate(decltype(QObjectPrivateVersion) version = QObjectPrivateVersion);
40
0
    virtual ~QAbstractSocketPrivate();
41
0
42
0
    // from QAbstractSocketEngineReceiver
43
0
    inline void readNotification() override { canReadNotification(); }
44
0
    inline void writeNotification() override { canWriteNotification(); }
45
0
    inline void exceptionNotification() override {}
46
0
    inline void closeNotification() override { canCloseNotification(); }
47
    void connectionNotification() override;
48
#ifndef QT_NO_NETWORKPROXY
49
0
    inline void proxyAuthenticationRequired(const QNetworkProxy &proxy, QAuthenticator *authenticator) override {
50
0
        Q_Q(QAbstractSocket);
51
0
        emit q->proxyAuthenticationRequired(proxy, authenticator);
52
0
    }
53
#endif
54
55
    virtual bool bind(const QHostAddress &address, quint16 port, QAbstractSocket::BindMode mode,
56
                      const QNetworkInterface *iface = nullptr);
57
58
    virtual bool canReadNotification();
59
    bool canWriteNotification();
60
    void canCloseNotification();
61
62
    // slots
63
    void _q_connectToNextAddress();
64
    void _q_startConnecting(const QHostInfo &hostInfo);
65
    void _q_testConnection();
66
    void _q_abortConnectionAttempt();
67
68
    bool emittedReadyRead = false;
69
    bool emittedBytesWritten = false;
70
71
    bool abortCalled = false;
72
    bool pendingClose = false;
73
74
    QAbstractSocket::PauseModes pauseMode = QAbstractSocket::PauseNever;
75
76
    QString hostName;
77
    quint16 port = 0;
78
    QHostAddress host;
79
    QList<QHostAddress> addresses;
80
81
    quint16 localPort = 0;
82
    quint16 peerPort = 0;
83
    QHostAddress localAddress;
84
    QHostAddress peerAddress;
85
    QString peerName;
86
87
    QAbstractSocketEngine *socketEngine = nullptr;
88
    qintptr cachedSocketDescriptor = -1;
89
90
#ifndef QT_NO_NETWORKPROXY
91
    QNetworkProxy proxy;
92
    QNetworkProxy proxyInUse;
93
    QString protocolTag;
94
    void resolveProxy(const QString &hostName, quint16 port);
95
#else
96
    inline void resolveProxy(const QString &, quint16) { }
97
#endif
98
0
    inline void resolveProxy(quint16 port) { resolveProxy(QString(), port); }
99
100
    void resetSocketLayer();
101
    virtual bool flush();
102
103
    bool initSocketLayer(QAbstractSocket::NetworkLayerProtocol protocol);
104
    virtual void configureCreatedSocket();
105
    void startConnectingByName(const QString &host);
106
    void fetchConnectionParameters();
107
    bool readFromSocket();
108
    virtual bool writeToSocket();
109
    void emitReadyRead(int channel = 0);
110
    void emitBytesWritten(qint64 bytes, int channel = 0);
111
112
    void setError(QAbstractSocket::SocketError errorCode, const QString &errorString);
113
    void setErrorAndEmit(QAbstractSocket::SocketError errorCode, const QString &errorString);
114
115
    qint64 readBufferMaxSize = 0;
116
    bool isBuffered = false;
117
    bool hasPendingData = false;
118
    bool hasPendingDatagram = false;
119
120
    quint32 bytesWrittenEmissionCount = 0;
121
122
    QTimer *connectTimer = nullptr;
123
124
    int hostLookupId = -1;
125
126
    QAbstractSocket::SocketType socketType = QAbstractSocket::UnknownSocketType;
127
    QAbstractSocket::SocketState state = QAbstractSocket::UnconnectedState;
128
129
    // Must be kept in sync with QIODevicePrivate::errorString.
130
    QAbstractSocket::SocketError socketError = QAbstractSocket::UnknownSocketError;
131
132
    QAbstractSocket::NetworkLayerProtocol preferredNetworkLayerProtocol =
133
            QAbstractSocket::UnknownNetworkLayerProtocol;
134
135
    bool prePauseReadSocketNotifierState = false;
136
    bool prePauseWriteSocketNotifierState = false;
137
    bool prePauseExceptionSocketNotifierState = false;
138
    static void pauseSocketNotifiers(QAbstractSocket*);
139
    static void resumeSocketNotifiers(QAbstractSocket*);
140
    static QAbstractSocketEngine* getSocketEngine(QAbstractSocket*);
141
};
142
143
QT_END_NAMESPACE
144
145
#endif // QABSTRACTSOCKET_P_H