89#define Q_CHECK_SOCKETENGINE(returnValue) do { \
90 if (!d->socketEngine) { \
112#ifndef QT_NO_NETWORKPROXY
156#if defined(Q_OS_UNIX)
176#if defined (QTCPSERVER_DEBUG)
177 qDebug(
"QTcpServerPrivate::_q_processIncomingConnection() too many connections");
185 if (descriptor == -1) {
194#if defined (QTCPSERVER_DEBUG)
195 qDebug(
"QTcpServerPrivate::_q_processIncomingConnection() accepted socket %i", descriptor);
198 q->incomingConnection(descriptor);
201 emit q->newConnection();
203 if (!that || !
q->isListening())
233#if defined(QTCPSERVER_DEBUG)
250#if defined(QTCPSERVER_DEBUG)
251 qDebug(
"QTcpServer::~QTcpServer()");
265#if defined(QTCPSERVER_DEBUG)
266 qDebug(
"QTcpServer::QTcpServer(%sSocket, QTcpServerPrivate == %p, parent == %p)",
270 :
"Unknown", &dd,
parent);
289 qWarning(
"QTcpServer::listen() called when already listening");
296#ifdef QT_NO_NETWORKPROXY
302 delete d->socketEngine;
304 if (!
d->socketEngine) {
306 d->serverSocketErrorString =
tr(
"Operation on socket is not supported");
309 if (!
d->socketEngine->initialize(
d->socketType, proto)) {
310 d->serverSocketError =
d->socketEngine->error();
311 d->serverSocketErrorString =
d->socketEngine->errorString();
314 proto =
d->socketEngine->protocol();
318 d->configureCreatedSocket();
320 if (!
d->socketEngine->bind(
addr,
port)) {
321 d->serverSocketError =
d->socketEngine->error();
322 d->serverSocketErrorString =
d->socketEngine->errorString();
326 if (!
d->socketEngine->listen(
d->listenBacklog)) {
327 d->serverSocketError =
d->socketEngine->error();
328 d->serverSocketErrorString =
d->socketEngine->errorString();
332 d->socketEngine->setReceiver(
d);
333 d->socketEngine->setReadNotificationEnabled(
true);
336 d->address =
d->socketEngine->localAddress();
337 d->port =
d->socketEngine->localPort();
339#if defined (QTCPSERVER_DEBUG)
340 qDebug(
"QTcpServer::listen(%i, \"%s\") == true (listening on port %i)",
port,
341 address.toString().toLatin1().constData(),
d->socketEngine->localPort());
370 d->pendingConnections.clear();
372 if (
d->socketEngine) {
373 d->socketEngine->close();
375 d->socketEngine->deleteLater();
376 }
QT_CATCH(
const std::bad_alloc &) {
380 d->socketEngine =
nullptr;
399 return d->socketEngine->socketDescriptor();
415 qWarning(
"QTcpServer::setSocketDescriptor() called when already listening");
420 delete d->socketEngine;
422 if (!
d->socketEngine) {
424 d->serverSocketErrorString =
tr(
"Operation on socket is not supported");
428 d->serverSocketError =
d->socketEngine->error();
429 d->serverSocketErrorString =
d->socketEngine->errorString();
430#if defined (QTCPSERVER_DEBUG)
432 d->serverSocketErrorString.toLatin1().constData());
437 d->socketEngine->setReceiver(
d);
438 d->socketEngine->setReadNotificationEnabled(
true);
440 d->state =
d->socketEngine->state();
441 d->address =
d->socketEngine->localAddress();
442 d->port =
d->socketEngine->localPort();
444#if defined (QTCPSERVER_DEBUG)
460 return d->socketEngine->localPort();
473 return d->socketEngine->localAddress();
501 if (!
d->socketEngine->waitForRead(msec, timedOut)) {
502 d->serverSocketError =
d->socketEngine->error();
503 d->serverSocketErrorString =
d->socketEngine->errorString();
507 if (timedOut && *timedOut)
510 d->readNotification();
523 return !d_func()->pendingConnections.isEmpty();
547 if (
d->pendingConnections.isEmpty())
550 if (!
d->socketEngine) {
551 qWarning(
"QTcpServer::nextPendingConnection() called while not listening");
552 }
else if (!
d->socketEngine->isReadNotificationEnabled()) {
553 d->socketEngine->setReadNotificationEnabled(
true);
556 return d->pendingConnections.takeFirst();
588#if defined (QTCPSERVER_DEBUG)
612 d_func()->pendingConnections.append(
socket);
633 d_func()->maxConnections = numConnections;
644 return d_func()->maxConnections;
660 d_func()->listenBacklog =
size;
672 return d_func()->listenBacklog;
682 return d_func()->serverSocketError;
693 return d_func()->serverSocketErrorString;
705 d_func()->socketEngine->setReadNotificationEnabled(
false);
717 d_func()->socketEngine->setReadNotificationEnabled(
true);
720#ifndef QT_NO_NETWORKPROXY
736 d->proxy = networkProxy;
756#include "moc_qtcpserver.cpp"
QAbstractSocket::SocketError error() const
virtual bool isReadNotificationEnabled() const =0
virtual qintptr accept()=0
virtual void setReadNotificationEnabled(bool enable)=0
static QAbstractSocketEngine * createSocketEngine(QAbstractSocket::SocketType socketType, const QNetworkProxy &, QObject *parent)
virtual bool setOption(SocketOption option, int value)=0
QString errorString() const
The QAbstractSocket class provides the base functionality common to all socket types.
static constexpr auto IPv4Protocol
static constexpr auto AnyIPProtocol
SocketError
This enum describes the socket errors that can occur.
@ UnsupportedSocketOperationError
SocketType
This enum describes the transport layer protocol.
virtual bool setSocketDescriptor(qintptr socketDescriptor, SocketState state=ConnectedState, OpenMode openMode=ReadWrite)
Initializes QAbstractSocket with the native socket descriptor socketDescriptor.
The QHostAddress class provides an IP address.
qsizetype size() const noexcept
static QList< QNetworkProxy > proxyForQuery(const QNetworkProxyQuery &query)
This function takes the query request, query, examines the details of the type of socket or request a...
The QNetworkProxyQuery class is used to query the proxy settings for a socket.
The QNetworkProxy class provides a network layer proxy.
QNetworkProxy::ProxyType type() const
Returns the proxy type for this instance.
@ SctpListeningCapability
QObject * parent() const
Returns a pointer to the parent object.
\macro QT_RESTRICTED_CAST_FROM_ASCII
QAbstractSocket::SocketError serverSocketError
QAbstractSocketEngine * socketEngine
QNetworkProxy resolveProxy(const QHostAddress &address, quint16 port)
QString serverSocketErrorString
virtual void configureCreatedSocket()
virtual int totalPendingConnections() const
QAbstractSocket::SocketType socketType
void readNotification() override
QList< QTcpSocket * > pendingConnections
The QTcpServer class provides a TCP-based server.
void addPendingConnection(QTcpSocket *socket)
This function is called by QTcpServer::incomingConnection() to add the socket to the list of pending ...
void setListenBacklogSize(int size)
Sets the backlog queue size of to be accepted connections to size.
void setProxy(const QNetworkProxy &networkProxy)
virtual bool hasPendingConnections() const
Returns true if the server has a pending connection; otherwise returns false.
qintptr socketDescriptor() const
Returns the native socket descriptor the server uses to listen for incoming instructions,...
QTcpServer(QObject *parent=nullptr)
Constructs a QTcpServer object.
virtual void incomingConnection(qintptr handle)
This virtual function is called by QTcpServer when a new connection is available.
QHostAddress serverAddress() const
Returns the server's address if the server is listening for connections; otherwise returns QHostAddre...
QString errorString() const
Returns a human readable description of the last error that occurred.
bool setSocketDescriptor(qintptr socketDescriptor)
Sets the socket descriptor this server should use when listening for incoming connections to socketDe...
int listenBacklogSize() const
Returns the backlog queue size of to be accepted connections.
virtual QTcpSocket * nextPendingConnection()
Returns the next pending connection as a connected QTcpSocket object.
int maxPendingConnections() const
Returns the maximum number of pending accepted connections.
bool listen(const QHostAddress &address=QHostAddress::Any, quint16 port=0)
Tells the server to listen for incoming connections on address address and port port.
virtual ~QTcpServer()
Destroys the QTcpServer object.
bool isListening() const
Returns true if the server is currently listening for incoming connections; otherwise returns false.
quint16 serverPort() const
Returns the server's port if the server is listening for connections; otherwise returns 0.
void pendingConnectionAvailable(QPrivateSignal)
This signal is emitted every time a new connection has been added to the pending connections queue.
void setMaxPendingConnections(int numConnections)
Sets the maximum number of pending accepted connections to numConnections.
QAbstractSocket::SocketError serverError() const
Returns an error code for the last error that occurred.
QNetworkProxy proxy() const
bool waitForNewConnection(int msec=0, bool *timedOut=nullptr)
Waits for at most msec milliseconds or until an incoming connection is available.
void close()
Closes the server.
The QTcpSocket class provides a TCP socket.
qDeleteAll(list.begin(), list.end())
Combined button and popup list for selecting options.
#define Q_CHECK_SOCKETENGINE(returnValue)
static QT_BEGIN_NAMESPACE const char * socketType(QSocketNotifier::Type type)
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLuint GLuint64EXT address
GLdouble GLdouble GLdouble GLdouble q
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent