Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qtcpserver.h
Go to the documentation of this file.
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
4#ifndef QTCPSERVER_H
5#define QTCPSERVER_H
6
7#include <QtNetwork/qtnetworkglobal.h>
8#include <QtCore/qobject.h>
9#include <QtNetwork/qabstractsocket.h>
10#include <QtNetwork/qhostaddress.h>
11
12QT_BEGIN_NAMESPACE
13
14
15class QTcpServerPrivate;
16#ifndef QT_NO_NETWORKPROXY
17class QNetworkProxy;
18#endif
19class QTcpSocket;
20
21class Q_NETWORK_EXPORT QTcpServer : public QObject
22{
23 Q_OBJECT
24public:
25 explicit QTcpServer(QObject *parent = nullptr);
26 virtual ~QTcpServer();
27
28 bool listen(const QHostAddress &address = QHostAddress::Any, quint16 port = 0);
29 void close();
30
31 bool isListening() const;
32
33 void setMaxPendingConnections(int numConnections);
34 int maxPendingConnections() const;
35
36 void setListenBacklogSize(int size);
37 int listenBacklogSize() const;
38
39 quint16 serverPort() const;
40 QHostAddress serverAddress() const;
41
42 qintptr socketDescriptor() const;
43 bool setSocketDescriptor(qintptr socketDescriptor);
44
45 bool waitForNewConnection(int msec = 0, bool *timedOut = nullptr);
46 virtual bool hasPendingConnections() const;
47 virtual QTcpSocket *nextPendingConnection();
48
49 QAbstractSocket::SocketError serverError() const;
50 QString errorString() const;
51
52 void pauseAccepting();
53 void resumeAccepting();
54
55#ifndef QT_NO_NETWORKPROXY
56 void setProxy(const QNetworkProxy &networkProxy);
57 QNetworkProxy proxy() const;
58#endif
59
60protected:
61 virtual void incomingConnection(qintptr handle);
62 void addPendingConnection(QTcpSocket* socket);
63
64 QTcpServer(QAbstractSocket::SocketType socketType, QTcpServerPrivate &dd,
65 QObject *parent = nullptr);
66
67Q_SIGNALS:
68 void newConnection();
69 void pendingConnectionAvailable(QPrivateSignal);
70 void acceptError(QAbstractSocket::SocketError socketError);
71
72private:
73 Q_DISABLE_COPY(QTcpServer)
74 Q_DECLARE_PRIVATE(QTcpServer)
75};
76
77QT_END_NAMESPACE
78
79#endif // QTCPSERVER_H
bool event(QEvent *) override
This virtual function receives events to an object and should return true if the event e was recogniz...
QExceptionNotifier(qintptr fd, QNativeSocketEngine *parent)
QNativeSocketEngine * engine
bool createNewSocket(QAbstractSocket::SocketType type, QAbstractSocket::NetworkLayerProtocol &protocol)
QNetworkInterface nativeMulticastInterface() const
qint64 nativeWrite(const char *data, qint64 length)
int option(QNativeSocketEngine::SocketOption option) const
bool nativeJoinMulticastGroup(const QHostAddress &groupAddress, const QNetworkInterface &iface)
bool setOption(QNativeSocketEngine::SocketOption option, int value)
int nativeSelect(QDeadlineTimer deadline, bool selectForRead) const
void setError(QAbstractSocket::SocketError error, ErrorString errorString) const
bool nativeSetMulticastInterface(const QNetworkInterface &iface)
bool checkProxy(const QHostAddress &address)
bool fetchConnectionParameters()
Fetches information about both ends of the connection: whatever is available.
bool nativeBind(const QHostAddress &address, quint16 port)
qint64 nativeSendDatagram(const char *data, qint64 length, const QIpPacketHeader &header)
bool nativeConnect(const QHostAddress &address, quint16 port)
int nativeSelect(QDeadlineTimer deadline, bool checkRead, bool checkWrite, bool *selectForRead, bool *selectForWrite) const
void setPortAndAddress(quint16 port, const QHostAddress &address, qt_sockaddr *aa, QT_SOCKLEN_T *sockAddrSize)
bool nativeLeaveMulticastGroup(const QHostAddress &groupAddress, const QNetworkInterface &iface)
QHostAddress adjustAddressProtocol(const QHostAddress &address) const
qint64 nativeRead(char *data, qint64 maxLength)
qint64 nativeReceiveDatagram(char *data, qint64 maxLength, QIpPacketHeader *header, QAbstractSocketEngine::PacketHeaderOptions options)
The QNetworkProxyQuery class is used to query the proxy settings for a socket.
QNativeSocketEngine * engine
bool event(QEvent *) override
This virtual function receives events to an object and should return true if the event e was recogniz...
QReadNotifier(qintptr fd, QNativeSocketEngine *parent)
The QTcpServer class provides a TCP-based server.
Definition qtcpserver.h:22
QWriteNotifier(qintptr fd, QNativeSocketEngine *parent)
QNativeSocketEngine * engine
bool event(QEvent *) override
\reimp
Combined button and popup list for selecting options.
#define Q_CHECK_STATES3(function, state1, state2, state3, returnValue)
#define Q_CHECK_STATES(function, state1, state2, returnValue)
#define Q_CHECK_TYPES(function, type1, type2, returnValue)
#define Q_CHECK_VALID_SOCKETLAYER(function, returnValue)
#define Q_CHECK_NOT_STATE(function, checkState, returnValue)
#define Q_CHECK_TYPE(function, type, returnValue)
#define Q_CHECK_STATE(function, checkState, returnValue)