| 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 QTCPSERVER_H |
| 6 | #define QTCPSERVER_H |
| 7 | |
| 8 | #include <QtNetwork/qtnetworkglobal.h> |
| 9 | #include <QtCore/qobject.h> |
| 10 | #include <QtNetwork/qabstractsocket.h> |
| 11 | #include <QtNetwork/qhostaddress.h> |
| 12 | |
| 13 | QT_BEGIN_NAMESPACE |
| 14 | |
| 15 | |
| 16 | class QTcpServerPrivate; |
| 17 | #ifndef QT_NO_NETWORKPROXY |
| 18 | class QNetworkProxy; |
| 19 | #endif |
| 20 | class QTcpSocket; |
| 21 | |
| 22 | class Q_NETWORK_EXPORT QTcpServer : public QObject |
| 23 | { |
| 24 | Q_OBJECT |
| 25 | public: |
| 26 | explicit QTcpServer(QObject *parent = nullptr); |
| 27 | virtual ~QTcpServer(); |
| 28 | |
| 29 | bool listen(const QHostAddress &address = QHostAddress::Any, quint16 port = 0); |
| 30 | void close(); |
| 31 | |
| 32 | bool isListening() const; |
| 33 | |
| 34 | void setMaxPendingConnections(int numConnections); |
| 35 | int maxPendingConnections() const; |
| 36 | |
| 37 | void setListenBacklogSize(int size); |
| 38 | int listenBacklogSize() const; |
| 39 | |
| 40 | quint16 serverPort() const; |
| 41 | QHostAddress serverAddress() const; |
| 42 | |
| 43 | qintptr socketDescriptor() const; |
| 44 | bool setSocketDescriptor(qintptr socketDescriptor); |
| 45 | |
| 46 | bool waitForNewConnection(int msec = 0, bool *timedOut = nullptr); |
| 47 | virtual bool hasPendingConnections() const; |
| 48 | virtual QTcpSocket *nextPendingConnection(); |
| 49 | |
| 50 | QAbstractSocket::SocketError serverError() const; |
| 51 | QString errorString() const; |
| 52 | |
| 53 | void pauseAccepting(); |
| 54 | void resumeAccepting(); |
| 55 | |
| 56 | #ifndef QT_NO_NETWORKPROXY |
| 57 | void setProxy(const QNetworkProxy &networkProxy); |
| 58 | QNetworkProxy proxy() const; |
| 59 | #endif |
| 60 | |
| 61 | protected: |
| 62 | virtual void incomingConnection(qintptr handle); |
| 63 | void addPendingConnection(QTcpSocket* socket); |
| 64 | |
| 65 | QTcpServer(QAbstractSocket::SocketType socketType, QTcpServerPrivate &dd, |
| 66 | QObject *parent = nullptr); |
| 67 | |
| 68 | Q_SIGNALS: |
| 69 | void newConnection(); |
| 70 | void pendingConnectionAvailable(QPrivateSignal); |
| 71 | void acceptError(QAbstractSocket::SocketError socketError); |
| 72 | |
| 73 | private: |
| 74 | Q_DISABLE_COPY(QTcpServer) |
| 75 | Q_DECLARE_PRIVATE(QTcpServer) |
| 76 | }; |
| 77 | |
| 78 | QT_END_NAMESPACE |
| 79 | |
| 80 | #endif // QTCPSERVER_H |
| 81 | |