430#include <QtNetwork/private/qtnetworkglobal_p.h>
435#include "private/qhostinfo_p.h"
447#include <private/qthread_p.h>
449#ifdef QABSTRACTSOCKET_DEBUG
451#include <private/qdebug_p.h>
456#define Q_CHECK_SOCKETENGINE(returnValue) do { \
457 if (!d->socketEngine) { \
458 return returnValue; \
461#ifndef QABSTRACTSOCKET_BUFFERSIZE
462#define QABSTRACTSOCKET_BUFFERSIZE 32768
464#define QT_TRANSFER_TIMEOUT 120000
469using namespace std::chrono_literals;
515#if defined (QABSTRACTSOCKET_DEBUG)
516 qDebug(
"QAbstractSocketPrivate::resetSocketLayer()");
539#ifdef QT_NO_NETWORKPROXY
545#if defined (QABSTRACTSOCKET_DEBUG)
550 else typeStr =
"UnknownSocketType"_L1;
554 else protocolStr =
"UnknownNetworkLayerProtocol"_L1;
561 QAbstractSocket::tr(
"Operation on socket is not supported"));
565#if defined (QABSTRACTSOCKET_DEBUG)
566 qDebug(
"QAbstractSocketPrivate::initSocketLayer(%s, %s) failed (%s)",
567 typeStr.toLatin1().constData(), protocolStr.toLatin1().constData(),
579#if defined (QABSTRACTSOCKET_DEBUG)
580 qDebug(
"QAbstractSocketPrivate::initSocketLayer(%s, %s) success",
581 typeStr.toLatin1().constData(), protocolStr.toLatin1().constData());
607#if defined (QABSTRACTSOCKET_DEBUG)
608 qDebug(
"QAbstractSocketPrivate::canReadNotification()");
618#if defined (QABSTRACTSOCKET_DEBUG)
619 qDebug(
"QAbstractSocketPrivate::canReadNotification() buffer is full");
627#if defined (QABSTRACTSOCKET_DEBUG)
628 qDebug(
"QAbstractSocketPrivate::canReadNotification() disconnecting socket");
630 q->disconnectFromHost();
635 if (
buffer.size() == oldBufferSize) {
638 return !
q->isReadable();
658#if defined (QABSTRACTSOCKET_DEBUG)
661 qDebug(
"QAbstractSocketPrivate::canReadNotification() socket is closing - returning");
677#if defined (QABSTRACTSOCKET_DEBUG)
678 qDebug(
"QAbstractSocketPrivate::canCloseNotification()");
689 if (!hadReadFromSocket) {
690 q->disconnectFromHost();
693 newBytes =
buffer.size() - newBytes;
718#if defined (QABSTRACTSOCKET_DEBUG)
719 qDebug(
"QAbstractSocketPrivate::canWriteNotification() flushing");
735#if defined (QABSTRACTSOCKET_DEBUG)
736 qDebug(
"QAbstractSocketPrivate::connectionNotification() testing connection");
756#if defined (QABSTRACTSOCKET_DEBUG)
757 qDebug(
"QAbstractSocketPrivate::writeToSocket() nothing to do: valid ? %s, writeBuffer.isEmpty() ? %s",
763 q->disconnectFromHost();
778#if defined (QABSTRACTSOCKET_DEBUG)
779 qDebug() <<
"QAbstractSocketPrivate::writeToSocket() write error, aborting."
788#if defined (QABSTRACTSOCKET_DEBUG)
789 qDebug(
"QAbstractSocketPrivate::writeToSocket() %lld bytes written to the network",
804 q->disconnectFromHost();
817 bool dataWasWritten =
false;
820 dataWasWritten =
true;
822 return dataWasWritten;
825#ifndef QT_NO_NETWORKPROXY
832 QList<QNetworkProxy> proxies;
872#if !defined(QT_NO_NETWORKPROXY)
885#if defined(QABSTRACTSOCKET_DEBUG)
931 qWarning(
"QAbstractSocketPrivate::_q_startConnecting() received hostInfo for wrong lookup ID %d expected %d", hostInfo.lookupId(),
hostLookupId);
939 const auto candidates = hostInfo.addresses();
947#if defined(QABSTRACTSOCKET_DEBUG)
950 if (
i != 0)
s +=
", "_L1;
954 qDebug(
"QAbstractSocketPrivate::_q_startConnecting(hostInfo == %s)",
s.toLatin1().constData());
963#if defined(QABSTRACTSOCKET_DEBUG)
964 qDebug(
"QAbstractSocketPrivate::_q_startConnecting(), host not found");
1001#if defined(QABSTRACTSOCKET_DEBUG)
1002 qDebug(
"QAbstractSocketPrivate::_q_connectToNextAddress(), all addresses failed.");
1014 QAbstractSocket::tr(
"Connection refused"));
1029#if defined(QABSTRACTSOCKET_DEBUG)
1030 qDebug(
"QAbstractSocketPrivate::_q_connectToNextAddress(), connecting to %s:%i, %d left to try",
1036#if defined(QABSTRACTSOCKET_DEBUG)
1037 qDebug(
"QAbstractSocketPrivate::_q_connectToNextAddress(), failed to initialize sock layer");
1055#if defined(QABSTRACTSOCKET_DEBUG)
1056 qDebug(
"QAbstractSocketPrivate::_q_connectToNextAddress(), connection failed (%s)",
1096 q_func()->disconnectFromHost();
1107#if defined(QABSTRACTSOCKET_DEBUG)
1108 qDebug(
"QAbstractSocketPrivate::_q_testConnection() connection failed,"
1109 " checking for alternative addresses");
1124#if defined(QABSTRACTSOCKET_DEBUG)
1125 qDebug(
"QAbstractSocketPrivate::_q_abortConnectionAttempt() (timed out)");
1135 QAbstractSocket::tr(
"Connection timed out"));
1153 if (bytesToRead == 0) {
1164 if (
q->isReadable()) {
1168#if defined(QABSTRACTSOCKET_DEBUG)
1169 qDebug(
"QAbstractSocketPrivate::readFromSocket() about to read %lld bytes",
1174 char *
ptr =
buffer.reserve(bytesToRead);
1176 if (readBytes == -2) {
1178 buffer.chop(bytesToRead);
1181 buffer.chop(bytesToRead - (readBytes < 0 ?
qint64(0) : readBytes));
1182#if defined(QABSTRACTSOCKET_DEBUG)
1183 qDebug(
"QAbstractSocketPrivate::readFromSocket() got %lld bytes, buffer size = %lld",
1184 readBytes,
buffer.size());
1188 QVarLengthArray<char, 4096> discardBuffer(bytesToRead);
1190#if defined(QABSTRACTSOCKET_DEBUG)
1191 qDebug(
"QAbstractSocketPrivate::readFromSocket() about to discard %lld bytes",
1198#if defined(QABSTRACTSOCKET_DEBUG)
1199 qDebug(
"QAbstractSocketPrivate::readFromSocket() read failed: %s",
1221 emit q->readyRead();
1238 emit q->bytesWritten(bytes);
1254 if (
q->isReadable()) {
1257 if (inboundStreamCount == 0)
1260 if (
q->isWritable()) {
1263 if (outboundStreamCount == 0)
1276#if defined(QABSTRACTSOCKET_DEBUG)
1277 qDebug(
"QAbstractSocketPrivate::fetchConnectionParameters() connection to %s:%i established",
1281 emit q->connected();
1291 if (!
d->socketEngine || !
d->socketEngine->isValid()
1312#ifdef QABSTRACTSOCKET_DEBUG
1314 <<
"pause notifiers, storing 'true' states, currently read:" <<
read
1315 <<
"write:" <<
write <<
"except:" << except;
1320 socket->d_func()->prePauseReadSocketNotifierState =
true;
1324 socket->d_func()->prePauseWriteSocketNotifierState =
true;
1328 socket->d_func()->prePauseExceptionSocketNotifierState =
true;
1339#ifdef QABSTRACTSOCKET_DEBUG
1341 <<
"Maybe resume notifiers, read:" <<
priv->prePauseReadSocketNotifierState
1342 <<
"write:" <<
priv->prePauseWriteSocketNotifierState
1343 <<
"exception:" <<
priv->prePauseExceptionSocketNotifierState;
1345 if (std::exchange(
priv->prePauseReadSocketNotifierState,
false))
1347 if (std::exchange(
priv->prePauseWriteSocketNotifierState,
false))
1349 if (std::exchange(
priv->prePauseExceptionSocketNotifierState,
false))
1355 return socket->d_func()->socketEngine;
1381 emit q->errorOccurred(errorCode);
1394#if defined(QABSTRACTSOCKET_DEBUG)
1395 qDebug(
"QAbstractSocket::QAbstractSocket(%sSocket, QAbstractSocketPrivate == %p, parent == %p)",
1419#if defined(QABSTRACTSOCKET_DEBUG)
1420 qDebug(
"QAbstractSocket::~QAbstractSocket()");
1452 return d_func()->pauseMode;
1512 protocol = nullAddress.protocol();
1579#if QT_VERSION < QT_VERSION_CHECK(7, 0, 0)
1597 return d_func()->socketEngine ? d_func()->socketEngine->isValid() :
isOpen();
1628#if defined(QABSTRACTSOCKET_DEBUG)
1635 qWarning(
"QAbstractSocket::connectToHost() called when already looking up or connecting/connected to \"%s\"",
qPrintable(hostName));
1636 d->setErrorAndEmit(
OperationError,
tr(
"Trying to connect while connection is in progress"));
1640 d->preferredNetworkLayerProtocol = protocol;
1641 d->hostName = hostName;
1643 d->setReadChannelCount(0);
1644 d->setWriteChannelCount(0);
1645 d->abortCalled =
false;
1646 d->pendingClose =
false;
1653 d->peerAddress.clear();
1654 d->peerName = hostName;
1655 if (
d->hostLookupId != -1) {
1657 d->hostLookupId = -1;
1660#ifndef QT_NO_NETWORKPROXY
1662 d->resolveProxy(hostName,
port);
1666 tr(
"Operation on socket is not supported"));
1674 d->isBuffered =
false;
1675 else if (!d_func()->isBuffered)
1679 d->readChannelCount =
d->writeChannelCount = 0;
1688 d->_q_startConnecting(
info);
1689#ifndef QT_NO_NETWORKPROXY
1692 d->startConnectingByName(hostName);
1696 if (
d->threadData.loadRelaxed()->hasEventDispatcher()) {
1699 bool immediateResultValid =
false;
1703 &immediateResultValid,
1705 if (immediateResultValid) {
1706 d->hostLookupId = -1;
1707 d->_q_startConnecting(hostInfo);
1712#if defined(QABSTRACTSOCKET_DEBUG)
1716 ?
" (connection in progress)" :
"");
1727#if defined(QABSTRACTSOCKET_DEBUG)
1728 qDebug(
"QAbstractSocket::connectToHost([%s], %i, %i)...",
1744#if defined(QABSTRACTSOCKET_DEBUG)
1745 qDebug(
"QAbstractSocket::bytesToWrite() == %lld", pendingBytes);
1747 return pendingBytes;
1760 if (!
d->isBuffered &&
d->socketEngine &&
d->socketEngine->isValid())
1761 available +=
d->socketEngine->bytesAvailable();
1763#if defined(QABSTRACTSOCKET_DEBUG)
1764 qDebug(
"QAbstractSocket::bytesAvailable() == %lld", available);
1778 return d->localPort;
1794 return d->localAddress;
1818 return d->peerAddress;
1830 return d->peerName.isEmpty() ?
d->hostName :
d->peerName;
1848 return d->cachedSocketDescriptor;
1869 d->resetSocketLayer();
1870 d->setReadChannelCount(0);
1871 d->setWriteChannelCount(0);
1873 if (!
d->socketEngine) {
1879 d->setError(
d->socketEngine->error(),
d->socketEngine->errorString());
1885 if (
d->threadData.loadRelaxed()->hasEventDispatcher())
1886 d->socketEngine->setReceiver(
d);
1892 const int inboundStreamCount =
d->socketEngine->inboundStreamCount();
1893 d->setReadChannelCount(
qMax(1, inboundStreamCount));
1894 if (inboundStreamCount == 0)
1895 d->readChannelCount = 0;
1898 const int outboundStreamCount =
d->socketEngine->outboundStreamCount();
1899 d->setWriteChannelCount(
qMax(1, outboundStreamCount));
1900 if (outboundStreamCount == 0)
1901 d->writeChannelCount = 0;
1904 d->readChannelCount =
d->writeChannelCount = 0;
1907 if (
d->state != socketState) {
1908 d->state = socketState;
1912 d->pendingClose =
false;
1913 d->socketEngine->setReadNotificationEnabled(
true);
1914 d->localPort =
d->socketEngine->localPort();
1915 d->peerPort =
d->socketEngine->peerPort();
1916 d->localAddress =
d->socketEngine->localAddress();
1917 d->peerAddress =
d->socketEngine->peerAddress();
1935 if (!d_func()->socketEngine)
1981 if (!d_func()->socketEngine)
2051#if defined (QABSTRACTSOCKET_DEBUG)
2052 qDebug(
"QAbstractSocket::waitForConnected(%i)", msecs);
2056#if defined (QABSTRACTSOCKET_DEBUG)
2057 qDebug(
"QAbstractSocket::waitForConnected(%i) already connected", msecs);
2062 bool wasPendingClose =
d->pendingClose;
2063 d->pendingClose =
false;
2067#if defined (QABSTRACTSOCKET_DEBUG)
2068 qDebug(
"QAbstractSocket::waitForConnected(%i) doing host name lookup", msecs);
2071 d->hostLookupId = -1;
2076 d->_q_startConnecting(
info);
2084 bool timedOut =
true;
2085#if defined (QABSTRACTSOCKET_DEBUG)
2092#if defined (QABSTRACTSOCKET_DEBUG)
2093 qDebug(
"QAbstractSocket::waitForConnected(%i) waiting %.2f secs for connection attempt #%i",
2098 if (
d->socketEngine &&
d->socketEngine->waitForWrite(
timer, &timedOut) && !timedOut) {
2099 d->_q_testConnection();
2101 d->_q_connectToNextAddress();
2109 d->resetSocketLayer();
2112#if defined (QABSTRACTSOCKET_DEBUG)
2113 qDebug(
"QAbstractSocket::waitForConnected(%i) == %s", msecs,
2118 if (wasPendingClose)
2141#if defined (QABSTRACTSOCKET_DEBUG)
2142 qDebug(
"QAbstractSocket::waitForReadyRead(%i)", msecs);
2166 bool readyToRead =
false;
2167 bool readyToWrite =
false;
2168 if (!
d->socketEngine->waitForReadOrWrite(&readyToRead, &readyToWrite,
true, !
d->writeBuffer.isEmpty(),
2170#if defined (QABSTRACTSOCKET_DEBUG)
2171 qDebug(
"QAbstractSocket::waitForReadyRead(%i) failed (%i, %s)",
2172 msecs,
d->socketEngine->error(),
d->socketEngine->errorString().toLatin1().constData());
2174 d->setErrorAndEmit(
d->socketEngine->error(),
d->socketEngine->errorString());
2181 if (
d->canReadNotification())
2186 d->canWriteNotification();
2210#if defined (QABSTRACTSOCKET_DEBUG)
2211 qDebug(
"QAbstractSocket::waitForBytesWritten(%i)", msecs);
2216 qWarning(
"QAbstractSocket::waitForBytesWritten() is not allowed in UnconnectedState");
2220 if (
d->writeBuffer.isEmpty())
2232 bool readyToRead =
false;
2233 bool readyToWrite =
false;
2234 if (!
d->socketEngine->waitForReadOrWrite(&readyToRead, &readyToWrite,
2235 !
d->readBufferMaxSize ||
d->buffer.size() <
d->readBufferMaxSize,
2236 !
d->writeBuffer.isEmpty(),
2238#if defined (QABSTRACTSOCKET_DEBUG)
2239 qDebug(
"QAbstractSocket::waitForBytesWritten(%i) failed (%i, %s)",
2240 msecs,
d->socketEngine->error(),
d->socketEngine->errorString().toLatin1().constData());
2242 d->setErrorAndEmit(
d->socketEngine->error(),
d->socketEngine->errorString());
2249#if defined (QABSTRACTSOCKET_DEBUG)
2250 qDebug(
"QAbstractSocket::waitForBytesWritten calls canReadNotification");
2252 d->canReadNotification();
2257 if (
d->canWriteNotification()) {
2258#if defined (QABSTRACTSOCKET_DEBUG)
2259 qDebug(
"QAbstractSocket::waitForBytesWritten returns true");
2297 qWarning(
"QAbstractSocket::waitForDisconnected() is not allowed in UnconnectedState");
2312 bool readyToRead =
false;
2313 bool readyToWrite =
false;
2314 if (!
d->socketEngine->waitForReadOrWrite(&readyToRead, &readyToWrite,
state() ==
ConnectedState,
2315 !
d->writeBuffer.isEmpty(),
2317#if defined (QABSTRACTSOCKET_DEBUG)
2318 qDebug(
"QAbstractSocket::waitForReadyRead(%i) failed (%i, %s)",
2319 msecs,
d->socketEngine->error(),
d->socketEngine->errorString().toLatin1().constData());
2321 d->setErrorAndEmit(
d->socketEngine->error(),
d->socketEngine->errorString());
2328 d->canReadNotification();
2330 d->canWriteNotification();
2348#if defined (QABSTRACTSOCKET_DEBUG)
2349 qDebug(
"QAbstractSocket::abort()");
2351 d->setWriteChannelCount(0);
2352 d->abortCalled =
true;
2379 return d_func()->flush();
2392 qint64 readBytes = (maxSize && !
d->isBuffered) ?
d->socketEngine->read(
data, maxSize)
2394 if (readBytes == -2) {
2398 if (readBytes < 0) {
2399 d->setError(
d->socketEngine->error(),
d->socketEngine->errorString());
2400 d->resetSocketLayer();
2404 d->hasPendingData =
false;
2405 d->socketEngine->setReadNotificationEnabled(
true);
2408#if defined (QABSTRACTSOCKET_DEBUG)
2409 qDebug(
"QAbstractSocket::readData(%p \"%s\", %lli) == %lld [engine]",
data,
2428 || (!
d->socketEngine &&
d->socketType !=
TcpSocket && !
d->isBuffered)) {
2434 &&
d->socketEngine &&
d->writeBuffer.isEmpty()) {
2438 d->setError(
d->socketEngine->error(),
d->socketEngine->errorString());
2439 }
else if (written <
size) {
2441 d->writeBuffer.append(
data + written,
size - written);
2443 d->socketEngine->setWriteNotificationEnabled(
true);
2446#if defined (QABSTRACTSOCKET_DEBUG)
2447 qDebug(
"QAbstractSocket::writeData(%p \"%s\", %lli) == %lli",
data,
2451 }
else if (!
d->isBuffered &&
d->socketType !=
TcpSocket) {
2455 d->setError(
d->socketEngine->error(),
d->socketEngine->errorString());
2457#if defined (QABSTRACTSOCKET_DEBUG)
2458 qDebug(
"QAbstractSocket::writeData(%p \"%s\", %lli) == %lli",
data,
2462 d->emitBytesWritten(written);
2475 if (
d->socketEngine && !
d->writeBuffer.isEmpty())
2476 d->socketEngine->setWriteNotificationEnabled(
true);
2478#if defined (QABSTRACTSOCKET_DEBUG)
2479 qDebug(
"QAbstractSocket::writeData(%p \"%s\", %lli) == %lli",
data,
2503 d->localPort =
port;
2596#if defined(QABSTRACTSOCKET_DEBUG)
2597 qDebug(
"QAbstractSocket::close()");
2615#if defined(QABSTRACTSOCKET_DEBUG)
2616 qDebug(
"QAbstractSocket::disconnectFromHost()");
2620#if defined(QABSTRACTSOCKET_DEBUG)
2621 qDebug(
"QAbstractSocket::disconnectFromHost() was called on an unconnected socket");
2627#if defined(QABSTRACTSOCKET_DEBUG)
2628 qDebug(
"QAbstractSocket::disconnectFromHost() but we're still connecting");
2630 d->pendingClose =
true;
2635 if (
d->socketEngine)
2636 d->socketEngine->setReadNotificationEnabled(
false);
2638 if (
d->abortCalled) {
2639#if defined(QABSTRACTSOCKET_DEBUG)
2640 qDebug(
"QAbstractSocket::disconnectFromHost() aborting immediately");
2644 d->hostLookupId = -1;
2650#if defined(QABSTRACTSOCKET_DEBUG)
2651 qDebug(
"QAbstractSocket::disconnectFromHost() emits stateChanged()(ClosingState)");
2655#if defined(QABSTRACTSOCKET_DEBUG)
2656 qDebug(
"QAbstractSocket::disconnectFromHost() return from delayed close");
2661 if (
d->socketEngine &&
d->socketEngine->isValid() && (!
d->allWriteBuffersEmpty()
2662 ||
d->socketEngine->bytesToWrite() > 0)) {
2663 d->socketEngine->setWriteNotificationEnabled(
true);
2665#if defined(QABSTRACTSOCKET_DEBUG)
2666 qDebug(
"QAbstractSocket::disconnectFromHost() delaying disconnect");
2670#if defined(QABSTRACTSOCKET_DEBUG)
2671 qDebug(
"QAbstractSocket::disconnectFromHost() disconnecting immediately");
2677 d->resetSocketLayer();
2688 d->localAddress.clear();
2689 d->peerAddress.clear();
2690 d->peerName.clear();
2691 d->setWriteChannelCount(0);
2693#if defined(QABSTRACTSOCKET_DEBUG)
2694 qDebug(
"QAbstractSocket::disconnectFromHost() disconnected!");
2711 return d_func()->readBufferMaxSize;
2740 if (
d->readBufferMaxSize ==
size)
2742 d->readBufferMaxSize =
size;
2748 d->socketEngine->setReadNotificationEnabled(
size == 0 ||
d->buffer.size() <
size);
2759 return d_func()->state;
2769 d_func()->state =
state;
2779 return d_func()->socketType;
2789 return d_func()->socketError;
2799 d_func()->socketError = socketError;
2802#ifndef QT_NO_NETWORKPROXY
2825 d->proxy = networkProxy;
2857 return d->protocolTag;
2871 d->protocolTag =
tag;
2876#ifndef QT_NO_DEBUG_STREAM
2880 debug.resetFormat().nospace();
2883 debug <<
"QAbstractSocket::ConnectionRefusedError";
2886 debug <<
"QAbstractSocket::RemoteHostClosedError";
2889 debug <<
"QAbstractSocket::HostNotFoundError";
2892 debug <<
"QAbstractSocket::SocketAccessError";
2895 debug <<
"QAbstractSocket::SocketResourceError";
2898 debug <<
"QAbstractSocket::SocketTimeoutError";
2901 debug <<
"QAbstractSocket::DatagramTooLargeError";
2904 debug <<
"QAbstractSocket::NetworkError";
2907 debug <<
"QAbstractSocket::AddressInUseError";
2910 debug <<
"QAbstractSocket::SocketAddressNotAvailableError";
2913 debug <<
"QAbstractSocket::UnsupportedSocketOperationError";
2916 debug <<
"QAbstractSocket::UnfinishedSocketOperationError";
2919 debug <<
"QAbstractSocket::ProxyAuthenticationRequiredError";
2922 debug <<
"QAbstractSocket::UnknownSocketError";
2925 debug <<
"QAbstractSocket::ProxyConnectionRefusedError";
2928 debug <<
"QAbstractSocket::ProxyConnectionClosedError";
2931 debug <<
"QAbstractSocket::ProxyConnectionTimeoutError";
2934 debug <<
"QAbstractSocket::ProxyNotFoundError";
2937 debug <<
"QAbstractSocket::ProxyProtocolError";
2940 debug <<
"QAbstractSocket::SocketError(" << int(
error) <<
')';
2949 debug.resetFormat().nospace();
2952 debug <<
"QAbstractSocket::UnconnectedState";
2955 debug <<
"QAbstractSocket::HostLookupState";
2958 debug <<
"QAbstractSocket::ConnectingState";
2961 debug <<
"QAbstractSocket::ConnectedState";
2964 debug <<
"QAbstractSocket::BoundState";
2967 debug <<
"QAbstractSocket::ListeningState";
2970 debug <<
"QAbstractSocket::ClosingState";
2973 debug <<
"QAbstractSocket::SocketState(" << int(
state) <<
')';
2982#include "moc_qabstractsocket.cpp"
IOBluetoothL2CAPChannel * channel
QAbstractSocket::SocketError error() const
virtual void setWriteNotificationEnabled(bool enable)=0
virtual bool bind(const QHostAddress &address, quint16 port)=0
virtual bool isValid() const =0
virtual bool isReadNotificationEnabled() const =0
void setReceiver(QAbstractSocketEngineReceiver *receiver)
virtual bool hasPendingDatagrams() const =0
virtual bool connectToHost(const QHostAddress &address, quint16 port)=0
int outboundStreamCount() const
virtual bool initialize(QAbstractSocket::SocketType type, QAbstractSocket::NetworkLayerProtocol protocol=QAbstractSocket::IPv4Protocol)=0
QAbstractSocket::SocketType socketType() const
virtual qint64 read(char *data, qint64 maxlen)=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
virtual qint64 write(const char *data, qint64 len)=0
@ MulticastLoopbackOption
@ ReceiveBufferSocketOption
QAbstractSocket::SocketState state() const
virtual qintptr socketDescriptor() const =0
virtual bool connectToHostByName(const QString &name, quint16 port)=0
int inboundStreamCount() const
virtual qint64 bytesAvailable() const =0
QString errorString() const
virtual qint64 bytesToWrite() const =0
quint16 localPort() const
virtual void setExceptionNotificationEnabled(bool enable)=0
virtual bool isWriteNotificationEnabled() const =0
QHostAddress peerAddress() const
virtual bool isExceptionNotificationEnabled() const =0
QHostAddress localAddress() const
bool canWriteNotification()
virtual ~QAbstractSocketPrivate()
QList< QHostAddress > addresses
void setError(QAbstractSocket::SocketError errorCode, const QString &errorString)
void emitBytesWritten(qint64 bytes, int channel=0)
QAbstractSocket::NetworkLayerProtocol preferredNetworkLayerProtocol
void emitReadyRead(int channel=0)
void canCloseNotification()
QAbstractSocket::SocketError socketError
qintptr cachedSocketDescriptor
QAbstractSocket::SocketType socketType
void fetchConnectionParameters()
static QAbstractSocketEngine * getSocketEngine(QAbstractSocket *)
void _q_startConnecting(const QHostInfo &hostInfo)
QAbstractSocketEngine * socketEngine
void startConnectingByName(const QString &host)
virtual bool canReadNotification()
void resolveProxy(const QString &hostName, quint16 port)
void _q_connectToNextAddress()
QHostAddress localAddress
virtual void configureCreatedSocket()
bool initSocketLayer(QAbstractSocket::NetworkLayerProtocol protocol)
static void pauseSocketNotifiers(QAbstractSocket *)
virtual bool writeToSocket()
virtual bool bind(const QHostAddress &address, quint16 port, QAbstractSocket::BindMode mode)
QAbstractSocket::SocketState state
void _q_abortConnectionAttempt()
static void resumeSocketNotifiers(QAbstractSocket *)
void connectionNotification() override
void setErrorAndEmit(QAbstractSocket::SocketError errorCode, const QString &errorString)
The QAbstractSocket class provides the base functionality common to all socket types.
SocketState
This enum describes the different states in which a socket can be.
bool flush()
This function writes as much as possible from the internal write buffer to the underlying network soc...
bool isSequential() const override
\reimp
QAbstractSocket(SocketType socketType, QObject *parent)
Creates a new abstract socket of type socketType.
void stateChanged(QAbstractSocket::SocketState)
This signal is emitted whenever QAbstractSocket's state changes.
virtual void setReadBufferSize(qint64 size)
Sets the size of QAbstractSocket's internal read buffer to be size bytes.
quint16 peerPort() const
Returns the port of the connected peer if the socket is in ConnectedState; otherwise returns 0.
static constexpr auto IPv4Protocol
void abort()
Aborts the current connection and resets the socket.
virtual void setSocketOption(QAbstractSocket::SocketOption option, const QVariant &value)
virtual QVariant socketOption(QAbstractSocket::SocketOption option)
void setPauseMode(PauseModes pauseMode)
bool waitForReadyRead(int msecs=30000) override
This function blocks until new data is available for reading and the \l{QIODevice::}{readyRead()} sig...
qint64 bytesToWrite() const override
Returns the number of bytes that are waiting to be written.
qint64 readLineData(char *data, qint64 maxlen) override
\reimp
bool waitForBytesWritten(int msecs=30000) override
\reimp
virtual qintptr socketDescriptor() const
Returns the native socket descriptor of the QAbstractSocket object if this is available; otherwise re...
virtual bool waitForDisconnected(int msecs=30000)
Waits until the socket has disconnected, up to msecs milliseconds.
QString protocolTag() const
void setSocketError(SocketError socketError)
Sets the type of error that last occurred to socketError.
void setPeerPort(quint16 port)
virtual ~QAbstractSocket()
Destroys the socket.
qint64 bytesAvailable() const override
Returns the number of incoming bytes that are waiting to be read.
QHostAddress localAddress() const
Returns the host address of the local socket if available; otherwise returns QHostAddress::Null.
QString peerName() const
Returns the name of the peer as specified by connectToHost(), or an empty QString if connectToHost() ...
qint64 skipData(qint64 maxSize) override
\reimp
QNetworkProxy proxy() const
virtual bool bind(const QHostAddress &address, quint16 port=0, BindMode mode=DefaultForPlatform)
virtual bool waitForConnected(int msecs=30000)
Waits until the socket is connected, up to msecs milliseconds.
PauseModes pauseMode() const
virtual void disconnectFromHost()
Attempts to close the socket.
void setPeerAddress(const QHostAddress &address)
static constexpr auto UnknownNetworkLayerProtocol
void setProxy(const QNetworkProxy &networkProxy)
@ ReceiveBufferSizeSocketOption
@ MulticastLoopbackOption
@ SendBufferSizeSocketOption
static constexpr auto AnyIPProtocol
qint64 writeData(const char *data, qint64 len) override
\reimp
qint64 readBufferSize() const
Returns the size of the internal read buffer.
void setLocalPort(quint16 port)
void setProtocolTag(const QString &tag)
SocketType socketType() const
Returns the socket type (TCP, UDP, or other).
bool isValid() const
Returns true if the socket is valid and ready for use; otherwise returns false.
void close() override
Closes the I/O device for the socket and calls disconnectFromHost() to close the socket's connection.
void setLocalAddress(const QHostAddress &address)
SocketState state() const
Returns the state of the socket.
SocketError
This enum describes the socket errors that can occur.
@ SocketAddressNotAvailableError
@ ProxyConnectionClosedError
@ ProxyConnectionRefusedError
@ ProxyConnectionTimeoutError
@ UnsupportedSocketOperationError
@ UnfinishedSocketOperationError
@ ProxyAuthenticationRequiredError
void setSocketState(SocketState state)
Sets the state of the socket to state.
static constexpr auto IPv6Protocol
SocketType
This enum describes the transport layer protocol.
virtual void connectToHost(const QString &hostName, quint16 port, OpenMode mode=ReadWrite, NetworkLayerProtocol protocol=AnyIPProtocol)
Attempts to make a connection to hostName on the given port.
quint16 localPort() const
Returns the host port number (in native byte order) of the local socket if available; otherwise retur...
void setPeerName(const QString &name)
void disconnected()
This signal is emitted when the socket has been disconnected.
SocketError error() const
Returns the type of error that last occurred.
QHostAddress peerAddress() const
Returns the address of the connected peer if the socket is in ConnectedState; otherwise returns QHost...
virtual bool setSocketDescriptor(qintptr socketDescriptor, SocketState state=ConnectedState, OpenMode openMode=ReadWrite)
Initializes QAbstractSocket with the native socket descriptor socketDescriptor.
qint64 readData(char *data, qint64 maxlen) override
\reimp
Type loadRelaxed() const noexcept
const char * constData() const noexcept
Returns a pointer to the const data stored in the byte array.
bool hasExpired() const noexcept
Returns true if this QDeadlineTimer object has expired, false if there remains time left.
constexpr bool isForever() const noexcept
Returns true if this QDeadlineTimer object never expires, false otherwise.
std::chrono::nanoseconds remainingTimeAsDuration() const noexcept
Returns the time remaining before the deadline.
The QHostAddress class provides an IP address.
void setAddress(quint32 ip4Addr)
Set the IPv4 address specified by ip4Addr.
QString toString() const
Returns the address as a string.
NetworkLayerProtocol protocol() const
Returns the network layer protocol of the host address.
The QHostInfo class provides static functions for host name lookups.
static void abortHostLookup(int lookupId)
Aborts the host lookup with the ID id, as returned by lookupHost().
void setAddresses(const QList< QHostAddress > &addresses)
Sets the list of addresses in this QHostInfo to addresses.
static QHostInfo fromName(const QString &name)
Looks up the IP address(es) for the given host name.
void write(const char *data, qint64 size)
bool allWriteBuffersEmpty() const
void setReadChannelCount(int count)
qint64 read(char *data, qint64 maxSize, bool peeking=false)
void setWriteChannelCount(int count)
\inmodule QtCore \reentrant
virtual bool open(QIODeviceBase::OpenMode mode)
Opens the device and sets its OpenMode to mode.
virtual qint64 size() const
For open random-access devices, this function returns the size of the device.
bool isOpen() const
Returns true if the device is open; otherwise returns false.
bool isReadable() const
Returns true if data can be read from the device; otherwise returns false.
QIODeviceBase::OpenMode openMode() const
Returns the mode in which the device has been opened; i.e.
virtual qint64 bytesAvailable() const
Returns the number of bytes that are available for reading.
virtual qint64 skipData(qint64 maxSize)
bool isWritable() const
Returns true if data can be written to the device; otherwise returns false.
virtual qint64 readLineData(char *data, qint64 maxlen)
Reads up to maxSize characters into data and returns the number of characters read.
virtual qint64 bytesToWrite() const
For buffered devices, this function returns the number of bytes waiting to be written.
virtual void close()
First emits aboutToClose(), then closes the device and sets its OpenMode to NotOpen.
void readChannelFinished()
bool isEmpty() const noexcept
const_reference at(qsizetype i) const noexcept
qsizetype count() 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.
@ SctpTunnelingCapability
@ HostNameLookupCapability
QAtomicPointer< QThreadData > threadData
QObject * parent() const
Returns a pointer to the parent object.
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
static bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *member)
\threadsafe
\macro QT_RESTRICTED_CAST_FROM_ASCII
QByteArray toLatin1() const &
void clear()
Clears the contents of the string and makes it null.
void start(int msec)
Starts or restarts the timer with a timeout interval of msec milliseconds.
int remainingTime
the remaining time in milliseconds
void stop()
Stops the timer.
Combined button and popup list for selecting options.
Q_CORE_EXPORT QByteArray toPrintable(const char *data, qint64 len, qsizetype maxSize)
static constexpr auto DefaultConnectTimeout
static bool isProxyError(QAbstractSocket::SocketError error)
Q_NETWORK_EXPORT QDebug operator<<(QDebug debug, QAbstractSocket::SocketError error)
#define QABSTRACTSOCKET_BUFFERSIZE
AudioChannelLayoutTag tag
DBusConnection const char DBusError * error
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
static QT_BEGIN_NAMESPACE const char * socketType(QSocketNotifier::Type type)
QHostInfo qt_qhostinfo_lookup(const QString &name, QObject *receiver, const char *member, bool *valid, int *id)
static ControlElement< T > * ptr(QWidget *widget)
constexpr const T & qMax(const T &a, const T &b)
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLbitfield GLuint64 timeout
[4]
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLuint GLuint64EXT address
GLdouble GLdouble GLdouble GLdouble q
static QLatin1StringView typeStr(QShaderDescription::VariableType t)
#define qPrintable(string)
#define QT_CONFIG(feature)
QDeadlineTimer deadline(30s)