429#include <QtNetwork/private/qtnetworkglobal_p.h>
434#include "private/qhostinfo_p.h"
446#include <private/qthread_p.h>
448#ifdef QABSTRACTSOCKET_DEBUG
450#include <private/qdebug_p.h>
455#define Q_CHECK_SOCKETENGINE(returnValue) do { \
456 if (!d->socketEngine) { \
457 return returnValue; \
460#ifndef QABSTRACTSOCKET_BUFFERSIZE
461#define QABSTRACTSOCKET_BUFFERSIZE 32768
463#define QT_TRANSFER_TIMEOUT 120000
513#if defined (QABSTRACTSOCKET_DEBUG)
514 qDebug(
"QAbstractSocketPrivate::resetSocketLayer()");
537#ifdef QT_NO_NETWORKPROXY
543#if defined (QABSTRACTSOCKET_DEBUG)
548 else typeStr =
"UnknownSocketType"_L1;
552 else protocolStr =
"UnknownNetworkLayerProtocol"_L1;
559 QAbstractSocket::tr(
"Operation on socket is not supported"));
563#if defined (QABSTRACTSOCKET_DEBUG)
564 qDebug(
"QAbstractSocketPrivate::initSocketLayer(%s, %s) failed (%s)",
577#if defined (QABSTRACTSOCKET_DEBUG)
578 qDebug(
"QAbstractSocketPrivate::initSocketLayer(%s, %s) success",
605#if defined (QABSTRACTSOCKET_DEBUG)
606 qDebug(
"QAbstractSocketPrivate::canReadNotification()");
616#if defined (QABSTRACTSOCKET_DEBUG)
617 qDebug(
"QAbstractSocketPrivate::canReadNotification() buffer is full");
625#if defined (QABSTRACTSOCKET_DEBUG)
626 qDebug(
"QAbstractSocketPrivate::canReadNotification() disconnecting socket");
628 q->disconnectFromHost();
633 if (
buffer.size() == oldBufferSize) {
636 return !
q->isReadable();
648#if defined (QABSTRACTSOCKET_DEBUG)
651 qDebug(
"QAbstractSocketPrivate::canReadNotification() socket is closing - returning");
667#if defined (QABSTRACTSOCKET_DEBUG)
668 qDebug(
"QAbstractSocketPrivate::canCloseNotification()");
679 if (!hadReadFromSocket) {
680 q->disconnectFromHost();
683 newBytes =
buffer.size() - newBytes;
708#if defined (QABSTRACTSOCKET_DEBUG)
709 qDebug(
"QAbstractSocketPrivate::canWriteNotification() flushing");
725#if defined (QABSTRACTSOCKET_DEBUG)
726 qDebug(
"QAbstractSocketPrivate::connectionNotification() testing connection");
746#if defined (QABSTRACTSOCKET_DEBUG)
747 qDebug(
"QAbstractSocketPrivate::writeToSocket() nothing to do: valid ? %s, writeBuffer.isEmpty() ? %s",
753 q->disconnectFromHost();
768#if defined (QABSTRACTSOCKET_DEBUG)
769 qDebug() <<
"QAbstractSocketPrivate::writeToSocket() write error, aborting."
778#if defined (QABSTRACTSOCKET_DEBUG)
779 qDebug(
"QAbstractSocketPrivate::writeToSocket() %lld bytes written to the network",
794 q->disconnectFromHost();
807 bool dataWasWritten =
false;
810 dataWasWritten =
true;
812 return dataWasWritten;
815#ifndef QT_NO_NETWORKPROXY
862#if !defined(QT_NO_NETWORKPROXY)
875#if defined(QABSTRACTSOCKET_DEBUG)
921 qWarning(
"QAbstractSocketPrivate::_q_startConnecting() received hostInfo for wrong lookup ID %d expected %d", hostInfo.
lookupId(),
hostLookupId);
929 const auto candidates = hostInfo.
addresses();
937#if defined(QABSTRACTSOCKET_DEBUG)
940 if (
i != 0)
s +=
", "_L1;
944 qDebug(
"QAbstractSocketPrivate::_q_startConnecting(hostInfo == %s)",
s.toLatin1().constData());
953#if defined(QABSTRACTSOCKET_DEBUG)
954 qDebug(
"QAbstractSocketPrivate::_q_startConnecting(), host not found");
991#if defined(QABSTRACTSOCKET_DEBUG)
992 qDebug(
"QAbstractSocketPrivate::_q_connectToNextAddress(), all addresses failed.");
1004 QAbstractSocket::tr(
"Connection refused"));
1019#if defined(QABSTRACTSOCKET_DEBUG)
1020 qDebug(
"QAbstractSocketPrivate::_q_connectToNextAddress(), connecting to %s:%i, %d left to try",
1026#if defined(QABSTRACTSOCKET_DEBUG)
1027 qDebug(
"QAbstractSocketPrivate::_q_connectToNextAddress(), failed to initialize sock layer");
1045#if defined(QABSTRACTSOCKET_DEBUG)
1046 qDebug(
"QAbstractSocketPrivate::_q_connectToNextAddress(), connection failed (%s)",
1087 q_func()->disconnectFromHost();
1098#if defined(QABSTRACTSOCKET_DEBUG)
1099 qDebug(
"QAbstractSocketPrivate::_q_testConnection() connection failed,"
1100 " checking for alternative addresses");
1115#if defined(QABSTRACTSOCKET_DEBUG)
1116 qDebug(
"QAbstractSocketPrivate::_q_abortConnectionAttempt() (timed out)");
1126 QAbstractSocket::tr(
"Connection timed out"));
1144 if (bytesToRead == 0) {
1155 if (
q->isReadable()) {
1159#if defined(QABSTRACTSOCKET_DEBUG)
1160 qDebug(
"QAbstractSocketPrivate::readFromSocket() about to read %lld bytes",
1165 char *
ptr =
buffer.reserve(bytesToRead);
1167 if (readBytes == -2) {
1169 buffer.chop(bytesToRead);
1172 buffer.chop(bytesToRead - (readBytes < 0 ?
qint64(0) : readBytes));
1173#if defined(QABSTRACTSOCKET_DEBUG)
1174 qDebug(
"QAbstractSocketPrivate::readFromSocket() got %lld bytes, buffer size = %lld",
1175 readBytes,
buffer.size());
1181#if defined(QABSTRACTSOCKET_DEBUG)
1182 qDebug(
"QAbstractSocketPrivate::readFromSocket() about to discard %lld bytes",
1189#if defined(QABSTRACTSOCKET_DEBUG)
1190 qDebug(
"QAbstractSocketPrivate::readFromSocket() read failed: %s",
1212 emit q->readyRead();
1229 emit q->bytesWritten(bytes);
1245 if (
q->isReadable()) {
1248 if (inboundStreamCount == 0)
1251 if (
q->isWritable()) {
1254 if (outboundStreamCount == 0)
1267#if defined(QABSTRACTSOCKET_DEBUG)
1268 qDebug(
"QAbstractSocketPrivate::fetchConnectionParameters() connection to %s:%i established",
1272 emit q->connected();
1282 if (!
d->socketEngine || !
d->socketEngine->isValid()
1303#ifdef QABSTRACTSOCKET_DEBUG
1305 <<
"pause notifiers, storing 'true' states, currently read:" <<
read
1306 <<
"write:" <<
write <<
"except:" << except;
1311 socket->d_func()->prePauseReadSocketNotifierState =
true;
1315 socket->d_func()->prePauseWriteSocketNotifierState =
true;
1319 socket->d_func()->prePauseExceptionSocketNotifierState =
true;
1330#ifdef QABSTRACTSOCKET_DEBUG
1332 <<
"Maybe resume notifiers, read:" <<
priv->prePauseReadSocketNotifierState
1333 <<
"write:" <<
priv->prePauseWriteSocketNotifierState
1334 <<
"exception:" <<
priv->prePauseExceptionSocketNotifierState;
1336 if (std::exchange(
priv->prePauseReadSocketNotifierState,
false))
1338 if (std::exchange(
priv->prePauseWriteSocketNotifierState,
false))
1340 if (std::exchange(
priv->prePauseExceptionSocketNotifierState,
false))
1346 return socket->d_func()->socketEngine;
1372 emit q->errorOccurred(errorCode);
1385#if defined(QABSTRACTSOCKET_DEBUG)
1386 qDebug(
"QAbstractSocket::QAbstractSocket(%sSocket, QAbstractSocketPrivate == %p, parent == %p)",
1410#if defined(QABSTRACTSOCKET_DEBUG)
1411 qDebug(
"QAbstractSocket::~QAbstractSocket()");
1443 return d_func()->pauseMode;
1570#if QT_VERSION < QT_VERSION_CHECK(7, 0, 0)
1588 return d_func()->socketEngine ? d_func()->socketEngine->isValid() :
isOpen();
1619#if defined(QABSTRACTSOCKET_DEBUG)
1626 qWarning(
"QAbstractSocket::connectToHost() called when already looking up or connecting/connected to \"%s\"",
qPrintable(hostName));
1627 d->setErrorAndEmit(
OperationError,
tr(
"Trying to connect while connection is in progress"));
1631 d->preferredNetworkLayerProtocol = protocol;
1632 d->hostName = hostName;
1634 d->setReadChannelCount(0);
1635 d->setWriteChannelCount(0);
1636 d->abortCalled =
false;
1637 d->pendingClose =
false;
1641 d->localAddress.clear();
1644 d->peerAddress.clear();
1645 d->peerName = hostName;
1646 if (
d->hostLookupId != -1) {
1648 d->hostLookupId = -1;
1651#ifndef QT_NO_NETWORKPROXY
1653 d->resolveProxy(hostName,
port);
1657 tr(
"Operation on socket is not supported"));
1665 d->isBuffered =
false;
1666 else if (!d_func()->isBuffered)
1670 d->readChannelCount =
d->writeChannelCount = 0;
1679 d->_q_startConnecting(
info);
1680#ifndef QT_NO_NETWORKPROXY
1683 d->startConnectingByName(hostName);
1687 if (
d->threadData.loadRelaxed()->hasEventDispatcher()) {
1690 bool immediateResultValid =
false;
1694 &immediateResultValid,
1696 if (immediateResultValid) {
1697 d->hostLookupId = -1;
1698 d->_q_startConnecting(hostInfo);
1703#if defined(QABSTRACTSOCKET_DEBUG)
1707 ?
" (connection in progress)" :
"");
1718#if defined(QABSTRACTSOCKET_DEBUG)
1719 qDebug(
"QAbstractSocket::connectToHost([%s], %i, %i)...",
1735#if defined(QABSTRACTSOCKET_DEBUG)
1736 qDebug(
"QAbstractSocket::bytesToWrite() == %lld", pendingBytes);
1738 return pendingBytes;
1751 if (!
d->isBuffered &&
d->socketEngine &&
d->socketEngine->isValid())
1752 available +=
d->socketEngine->bytesAvailable();
1754#if defined(QABSTRACTSOCKET_DEBUG)
1755 qDebug(
"QAbstractSocket::bytesAvailable() == %lld", available);
1769 return d->localPort;
1785 return d->localAddress;
1809 return d->peerAddress;
1821 return d->peerName.isEmpty() ?
d->hostName :
d->peerName;
1839 return d->cachedSocketDescriptor;
1860 d->resetSocketLayer();
1861 d->setReadChannelCount(0);
1862 d->setWriteChannelCount(0);
1864 if (!
d->socketEngine) {
1870 d->setError(
d->socketEngine->error(),
d->socketEngine->errorString());
1876 if (
d->threadData.loadRelaxed()->hasEventDispatcher())
1877 d->socketEngine->setReceiver(
d);
1883 const int inboundStreamCount =
d->socketEngine->inboundStreamCount();
1884 d->setReadChannelCount(
qMax(1, inboundStreamCount));
1885 if (inboundStreamCount == 0)
1886 d->readChannelCount = 0;
1889 const int outboundStreamCount =
d->socketEngine->outboundStreamCount();
1890 d->setWriteChannelCount(
qMax(1, outboundStreamCount));
1891 if (outboundStreamCount == 0)
1892 d->writeChannelCount = 0;
1895 d->readChannelCount =
d->writeChannelCount = 0;
1898 if (
d->state != socketState) {
1899 d->state = socketState;
1903 d->pendingClose =
false;
1904 d->socketEngine->setReadNotificationEnabled(
true);
1905 d->localPort =
d->socketEngine->localPort();
1906 d->peerPort =
d->socketEngine->peerPort();
1907 d->localAddress =
d->socketEngine->localAddress();
1908 d->peerAddress =
d->socketEngine->peerAddress();
1926 if (!d_func()->socketEngine)
1972 if (!d_func()->socketEngine)
2042#if defined (QABSTRACTSOCKET_DEBUG)
2043 qDebug(
"QAbstractSocket::waitForConnected(%i)", msecs);
2047#if defined (QABSTRACTSOCKET_DEBUG)
2048 qDebug(
"QAbstractSocket::waitForConnected(%i) already connected", msecs);
2053 bool wasPendingClose =
d->pendingClose;
2054 d->pendingClose =
false;
2059#if defined (QABSTRACTSOCKET_DEBUG)
2060 qDebug(
"QAbstractSocket::waitForConnected(%i) doing host name lookup", msecs);
2063 d->hostLookupId = -1;
2068 d->_q_startConnecting(
info);
2077 bool timedOut =
true;
2078#if defined (QABSTRACTSOCKET_DEBUG)
2083 if (msecs != -1 &&
timeout > connectTimeout)
2085#if defined (QABSTRACTSOCKET_DEBUG)
2086 qDebug(
"QAbstractSocket::waitForConnected(%i) waiting %.2f secs for connection attempt #%i",
2087 msecs,
timeout / 1000.0, attempt++);
2091 if (
d->socketEngine &&
d->socketEngine->waitForWrite(
timeout, &timedOut) && !timedOut) {
2092 d->_q_testConnection();
2094 d->_q_connectToNextAddress();
2102 d->resetSocketLayer();
2105#if defined (QABSTRACTSOCKET_DEBUG)
2106 qDebug(
"QAbstractSocket::waitForConnected(%i) == %s", msecs,
2111 if (wasPendingClose)
2134#if defined (QABSTRACTSOCKET_DEBUG)
2135 qDebug(
"QAbstractSocket::waitForReadyRead(%i)", msecs);
2160 bool readyToRead =
false;
2161 bool readyToWrite =
false;
2162 if (!
d->socketEngine->waitForReadOrWrite(&readyToRead, &readyToWrite,
true, !
d->writeBuffer.isEmpty(),
2164#if defined (QABSTRACTSOCKET_DEBUG)
2165 qDebug(
"QAbstractSocket::waitForReadyRead(%i) failed (%i, %s)",
2166 msecs,
d->socketEngine->error(),
d->socketEngine->errorString().toLatin1().constData());
2168 d->setErrorAndEmit(
d->socketEngine->error(),
d->socketEngine->errorString());
2175 if (
d->canReadNotification())
2180 d->canWriteNotification();
2204#if defined (QABSTRACTSOCKET_DEBUG)
2205 qDebug(
"QAbstractSocket::waitForBytesWritten(%i)", msecs);
2210 qWarning(
"QAbstractSocket::waitForBytesWritten() is not allowed in UnconnectedState");
2214 if (
d->writeBuffer.isEmpty())
2227 bool readyToRead =
false;
2228 bool readyToWrite =
false;
2229 if (!
d->socketEngine->waitForReadOrWrite(&readyToRead, &readyToWrite,
2230 !
d->readBufferMaxSize ||
d->buffer.size() <
d->readBufferMaxSize,
2231 !
d->writeBuffer.isEmpty(),
2233#if defined (QABSTRACTSOCKET_DEBUG)
2234 qDebug(
"QAbstractSocket::waitForBytesWritten(%i) failed (%i, %s)",
2235 msecs,
d->socketEngine->error(),
d->socketEngine->errorString().toLatin1().constData());
2237 d->setErrorAndEmit(
d->socketEngine->error(),
d->socketEngine->errorString());
2244#if defined (QABSTRACTSOCKET_DEBUG)
2245 qDebug(
"QAbstractSocket::waitForBytesWritten calls canReadNotification");
2247 d->canReadNotification();
2252 if (
d->canWriteNotification()) {
2253#if defined (QABSTRACTSOCKET_DEBUG)
2254 qDebug(
"QAbstractSocket::waitForBytesWritten returns true");
2292 qWarning(
"QAbstractSocket::waitForDisconnected() is not allowed in UnconnectedState");
2308 bool readyToRead =
false;
2309 bool readyToWrite =
false;
2310 if (!
d->socketEngine->waitForReadOrWrite(&readyToRead, &readyToWrite,
state() ==
ConnectedState,
2311 !
d->writeBuffer.isEmpty(),
2313#if defined (QABSTRACTSOCKET_DEBUG)
2314 qDebug(
"QAbstractSocket::waitForReadyRead(%i) failed (%i, %s)",
2315 msecs,
d->socketEngine->error(),
d->socketEngine->errorString().toLatin1().constData());
2317 d->setErrorAndEmit(
d->socketEngine->error(),
d->socketEngine->errorString());
2324 d->canReadNotification();
2326 d->canWriteNotification();
2344#if defined (QABSTRACTSOCKET_DEBUG)
2345 qDebug(
"QAbstractSocket::abort()");
2347 d->setWriteChannelCount(0);
2348 d->abortCalled =
true;
2375 return d_func()->flush();
2388 qint64 readBytes = (maxSize && !
d->isBuffered) ?
d->socketEngine->read(
data, maxSize)
2390 if (readBytes == -2) {
2394 if (readBytes < 0) {
2395 d->setError(
d->socketEngine->error(),
d->socketEngine->errorString());
2396 d->resetSocketLayer();
2400 d->hasPendingData =
false;
2401 d->socketEngine->setReadNotificationEnabled(
true);
2404#if defined (QABSTRACTSOCKET_DEBUG)
2405 qDebug(
"QAbstractSocket::readData(%p \"%s\", %lli) == %lld [engine]",
data,
2424 || (!
d->socketEngine &&
d->socketType !=
TcpSocket && !
d->isBuffered)) {
2430 &&
d->socketEngine &&
d->writeBuffer.isEmpty()) {
2434 d->setError(
d->socketEngine->error(),
d->socketEngine->errorString());
2435 }
else if (written <
size) {
2437 d->writeBuffer.append(
data + written,
size - written);
2439 d->socketEngine->setWriteNotificationEnabled(
true);
2442#if defined (QABSTRACTSOCKET_DEBUG)
2443 qDebug(
"QAbstractSocket::writeData(%p \"%s\", %lli) == %lli",
data,
2447 }
else if (!
d->isBuffered &&
d->socketType !=
TcpSocket) {
2451 d->setError(
d->socketEngine->error(),
d->socketEngine->errorString());
2453#if defined (QABSTRACTSOCKET_DEBUG)
2454 qDebug(
"QAbstractSocket::writeData(%p \"%s\", %lli) == %lli",
data,
2458 d->emitBytesWritten(written);
2471 if (
d->socketEngine && !
d->writeBuffer.isEmpty())
2472 d->socketEngine->setWriteNotificationEnabled(
true);
2474#if defined (QABSTRACTSOCKET_DEBUG)
2475 qDebug(
"QAbstractSocket::writeData(%p \"%s\", %lli) == %lli",
data,
2499 d->localPort =
port;
2592#if defined(QABSTRACTSOCKET_DEBUG)
2593 qDebug(
"QAbstractSocket::close()");
2611#if defined(QABSTRACTSOCKET_DEBUG)
2612 qDebug(
"QAbstractSocket::disconnectFromHost()");
2616#if defined(QABSTRACTSOCKET_DEBUG)
2617 qDebug(
"QAbstractSocket::disconnectFromHost() was called on an unconnected socket");
2623#if defined(QABSTRACTSOCKET_DEBUG)
2624 qDebug(
"QAbstractSocket::disconnectFromHost() but we're still connecting");
2626 d->pendingClose =
true;
2631 if (
d->socketEngine)
2632 d->socketEngine->setReadNotificationEnabled(
false);
2634 if (
d->abortCalled) {
2635#if defined(QABSTRACTSOCKET_DEBUG)
2636 qDebug(
"QAbstractSocket::disconnectFromHost() aborting immediately");
2640 d->hostLookupId = -1;
2646#if defined(QABSTRACTSOCKET_DEBUG)
2647 qDebug(
"QAbstractSocket::disconnectFromHost() emits stateChanged()(ClosingState)");
2651#if defined(QABSTRACTSOCKET_DEBUG)
2652 qDebug(
"QAbstractSocket::disconnectFromHost() return from delayed close");
2657 if (
d->socketEngine &&
d->socketEngine->isValid() && (!
d->allWriteBuffersEmpty()
2658 ||
d->socketEngine->bytesToWrite() > 0)) {
2659 d->socketEngine->setWriteNotificationEnabled(
true);
2661#if defined(QABSTRACTSOCKET_DEBUG)
2662 qDebug(
"QAbstractSocket::disconnectFromHost() delaying disconnect");
2666#if defined(QABSTRACTSOCKET_DEBUG)
2667 qDebug(
"QAbstractSocket::disconnectFromHost() disconnecting immediately");
2673 d->resetSocketLayer();
2684 d->localAddress.clear();
2685 d->peerAddress.clear();
2686 d->peerName.clear();
2687 d->setWriteChannelCount(0);
2689#if defined(QABSTRACTSOCKET_DEBUG)
2690 qDebug(
"QAbstractSocket::disconnectFromHost() disconnected!");
2707 return d_func()->readBufferMaxSize;
2736 if (
d->readBufferMaxSize ==
size)
2738 d->readBufferMaxSize =
size;
2744 d->socketEngine->setReadNotificationEnabled(
size == 0 ||
d->buffer.size() <
size);
2755 return d_func()->state;
2765 d_func()->state =
state;
2775 return d_func()->socketType;
2785 return d_func()->socketError;
2795 d_func()->socketError = socketError;
2798#ifndef QT_NO_NETWORKPROXY
2821 d->proxy = networkProxy;
2853 return d->protocolTag;
2867 d->protocolTag =
tag;
2872#ifndef QT_NO_DEBUG_STREAM
2876 debug.resetFormat().nospace();
2879 debug <<
"QAbstractSocket::ConnectionRefusedError";
2882 debug <<
"QAbstractSocket::RemoteHostClosedError";
2885 debug <<
"QAbstractSocket::HostNotFoundError";
2888 debug <<
"QAbstractSocket::SocketAccessError";
2891 debug <<
"QAbstractSocket::SocketResourceError";
2894 debug <<
"QAbstractSocket::SocketTimeoutError";
2897 debug <<
"QAbstractSocket::DatagramTooLargeError";
2900 debug <<
"QAbstractSocket::NetworkError";
2903 debug <<
"QAbstractSocket::AddressInUseError";
2906 debug <<
"QAbstractSocket::SocketAddressNotAvailableError";
2909 debug <<
"QAbstractSocket::UnsupportedSocketOperationError";
2912 debug <<
"QAbstractSocket::UnfinishedSocketOperationError";
2915 debug <<
"QAbstractSocket::ProxyAuthenticationRequiredError";
2918 debug <<
"QAbstractSocket::UnknownSocketError";
2921 debug <<
"QAbstractSocket::ProxyConnectionRefusedError";
2924 debug <<
"QAbstractSocket::ProxyConnectionClosedError";
2927 debug <<
"QAbstractSocket::ProxyConnectionTimeoutError";
2930 debug <<
"QAbstractSocket::ProxyNotFoundError";
2933 debug <<
"QAbstractSocket::ProxyProtocolError";
2936 debug <<
"QAbstractSocket::SocketError(" << int(
error) <<
')';
2945 debug.resetFormat().nospace();
2948 debug <<
"QAbstractSocket::UnconnectedState";
2951 debug <<
"QAbstractSocket::HostLookupState";
2954 debug <<
"QAbstractSocket::ConnectingState";
2957 debug <<
"QAbstractSocket::ConnectedState";
2960 debug <<
"QAbstractSocket::BoundState";
2963 debug <<
"QAbstractSocket::ListeningState";
2966 debug <<
"QAbstractSocket::ClosingState";
2969 debug <<
"QAbstractSocket::SocketState(" << int(
state) <<
')';
2978#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 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.
qint64 elapsed() const noexcept
Returns the number of milliseconds since this QElapsedTimer was last started.
void start() noexcept
Starts this timer.
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().
static QHostInfo fromName(const QString &name)
Looks up the IP address(es) for the given host name.
QList< QHostAddress > addresses() const
Returns the list of IP addresses associated with hostName().
int lookupId() const
Returns the ID of this lookup.
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()
constexpr const char * constData() const noexcept
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 start(int msec)
Starts or restarts the timer with a timeout interval of msec 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 const int 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)
int qt_subtract_from_timeout(int timeout, int elapsed)
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)
QFileInfo info(fileName)
[8]
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent