87#include <private/qthread_p.h>
88#include <private/qobject_p.h>
90#if !defined(QT_NO_NETWORKPROXY)
96#if !defined(QT_NO_SCTP)
109#define Q_CHECK_VALID_SOCKETLAYER(function, returnValue) do { \
111 qWarning(""#function" was called on an uninitialized socket device"); \
112 return returnValue; \
114#define Q_CHECK_INVALID_SOCKETLAYER(function, returnValue) do { \
116 qWarning(""#function" was called on an already initialized socket device"); \
117 return returnValue; \
119#define Q_CHECK_STATE(function, checkState, returnValue) do { \
120 if (d->socketState != (checkState)) { \
121 qWarning(""#function" was not called in "#checkState); \
122 return (returnValue); \
124#define Q_CHECK_NOT_STATE(function, checkState, returnValue) do { \
125 if (d->socketState == (checkState)) { \
126 qWarning(""#function" was called in "#checkState); \
127 return (returnValue); \
129#define Q_CHECK_STATES(function, state1, state2, returnValue) do { \
130 if (d->socketState != (state1) && d->socketState != (state2)) { \
131 qWarning(""#function" was called" \
132 " not in "#state1" or "#state2); \
133 return (returnValue); \
135#define Q_CHECK_STATES3(function, state1, state2, state3, returnValue) do { \
136 if (d->socketState != (state1) && d->socketState != (state2) && d->socketState != (state3)) { \
137 qWarning(""#function" was called" \
138 " not in "#state1" or "#state2); \
139 return (returnValue); \
141#define Q_CHECK_TYPE(function, type, returnValue) do { \
142 if (d->socketType != (type)) { \
143 qWarning(#function" was called by a" \
144 " socket other than "#type""); \
145 return (returnValue); \
147#define Q_CHECK_TYPES(function, type1, type2, returnValue) do { \
148 if (d->socketType != (type1) && d->socketType != (type2)) { \
149 qWarning(#function" was called by a" \
150 " socket other than "#type1" or "#type2); \
151 return (returnValue); \
153#define Q_TR(a) QT_TRANSLATE_NOOP(QNativeSocketEngine, a)
159 socketDescriptor(-1),
199 switch (errorString) {
201 socketErrorString = QNativeSocketEngine::tr(
"Unable to initialize non-blocking socket");
204 socketErrorString = QNativeSocketEngine::tr(
"Unable to initialize broadcast socket");
208 socketErrorString = QNativeSocketEngine::tr(
"Attempt to use IPv6 socket on a platform with no IPv6 support");
211 socketErrorString = QNativeSocketEngine::tr(
"The remote host closed the connection");
244 socketErrorString = QNativeSocketEngine::tr(
"The bound address is already in use");
268 socketErrorString = QNativeSocketEngine::tr(
"Another socket is already listening on the same port");
274 socketErrorString = QNativeSocketEngine::tr(
"The proxy type is invalid for this operation");
280 socketErrorString = QNativeSocketEngine::tr(
"Network dropped connection on reset");
328#if !defined(QT_NO_NETWORKPROXY)
349 if (qobject_cast<QSctpServer *>(
server))
363 query.setQueryType(queryType);
416#if defined (QNATIVESOCKETENGINE_DEBUG)
421 QString protocolStr =
"UnknownProtocol"_L1;
424 qDebug(
"QNativeSocketEngine::initialize(type == %s, protocol == %s) failed: %s",
449 qWarning(
"QNativeSocketEngine::initialize unable to inline out-of-band data");
490 if (!
d->fetchConnectionParameters()) {
491#if defined (QNATIVESOCKETENGINE_DEBUG)
492 qDebug() <<
"QNativeSocketEngine::initialize(socketDescriptor) failed:"
495 d->socketDescriptor = -1;
518 d->socketState = socketState;
530 return d->socketDescriptor != -1;
540 return d->socketDescriptor;
580 d->fetchConnectionParameters();
641 d->fetchConnectionParameters();
672 return d->nativeListen(backlog);
694 return d->nativeAccept();
711 return d->nativeBytesAvailable();
714#ifndef QT_NO_UDPSOCKET
715#ifndef QT_NO_NETWORKINTERFACE
735 qWarning(
"QAbstractSocket: cannot bind to QHostAddress::Any (or an IPv6 address) and join an IPv4 multicast group;"
736 " bind to QHostAddress::AnyIPv4 instead if you want to do this");
740 return d->nativeJoinMulticastGroup(groupAddress, iface);
753 return d->nativeLeaveMulticastGroup(groupAddress, iface);
764 return d->nativeMulticastInterface();
775 return d->nativeSetMulticastInterface(iface);
792 return d->nativeHasPendingDatagrams();
807 return d->nativePendingDatagramSize();
827 PacketHeaderOptions options)
834 return d->nativeReceiveDatagram(
data, maxSize,
header, options);
913 }
else if (readBytes == -1) {
914 if (!
d->hasSetSocketError) {
915 d->hasSetSocketError =
true;
933 d->readNotifier->setEnabled(
false);
934 if (
d->writeNotifier)
935 d->writeNotifier->setEnabled(
false);
936 if (
d->exceptNotifier)
937 d->exceptNotifier->setEnabled(
false);
939 if (
d->socketDescriptor != -1) {
941 d->socketDescriptor = -1;
944 d->hasSetSocketError =
false;
946 d->localAddress.clear();
948 d->peerAddress.clear();
949 d->inboundStreamCount =
d->outboundStreamCount = 0;
950 if (
d->readNotifier) {
952 d->readNotifier =
nullptr;
954 if (
d->writeNotifier) {
956 d->writeNotifier =
nullptr;
958 if (
d->exceptNotifier) {
960 d->exceptNotifier =
nullptr;
989 int ret =
d->nativeSelect(msecs,
true);
995 d->hasSetSocketError =
false;
1029 int ret =
d->nativeSelect(msecs,
false);
1033#if defined (Q_OS_WIN)
1037 d_func()->fetchConnectionParameters();
1041 int valueSize =
sizeof(
value);
1042 if (::getsockopt(
d->socketDescriptor, SOL_SOCKET, SO_ERROR, (
char *) &
value, &valueSize) == 0) {
1043 if (
value == WSAECONNREFUSED) {
1047 }
else if (
value == WSAETIMEDOUT) {
1051 }
else if (
value == WSAEHOSTUNREACH) {
1066 d->hasSetSocketError =
false;
1076 bool checkRead,
bool checkWrite,
1077 int msecs,
bool *timedOut)
1084 int ret =
d->nativeSelect(msecs, checkRead, checkWrite, readyToRead, readyToWrite);
1088#if defined (Q_OS_WIN)
1090 if (checkWrite && ((readyToWrite && *readyToWrite) || !readyToWrite) &&
ret > 0) {
1092 d_func()->fetchConnectionParameters();
1096 int valueSize =
sizeof(
value);
1097 if (::getsockopt(
d->socketDescriptor, SOL_SOCKET, SO_ERROR, (
char *) &
value, &valueSize) == 0) {
1098 if (
value == WSAECONNREFUSED) {
1102 }
else if (
value == WSAETIMEDOUT) {
1106 }
else if (
value == WSAEHOSTUNREACH) {
1120 d->hasSetSocketError =
false;
1136qint64 QNativeSocketEngine::receiveBufferSize()
const
1157void QNativeSocketEngine::setReceiveBufferSize(
qint64 size)
1168qint64 QNativeSocketEngine::sendBufferSize()
const
1183void QNativeSocketEngine::setSendBufferSize(
qint64 size)
1205 return d->option(socketOption);
1211 return d->readNotifier &&
d->readNotifier->isEnabled();
1306 if (
d->readNotifier) {
1307 d->readNotifier->setEnabled(
enable);
1308 }
else if (
enable &&
d->threadData.loadRelaxed()->hasEventDispatcher()) {
1310 d->readNotifier->setEnabled(
true);
1317 return d->writeNotifier &&
d->writeNotifier->isEnabled();
1323 if (
d->writeNotifier) {
1324 d->writeNotifier->setEnabled(
enable);
1325 }
else if (
enable &&
d->threadData.loadRelaxed()->hasEventDispatcher()) {
1327 d->writeNotifier->setEnabled(
true);
1334 return d->exceptNotifier &&
d->exceptNotifier->isEnabled();
1340 if (
d->exceptNotifier) {
1341 d->exceptNotifier->setEnabled(
enable);
1342 }
else if (
enable &&
d->threadData.loadRelaxed()->hasEventDispatcher()) {
1344 d->exceptNotifier->setEnabled(
true);
1350#include "moc_qnativesocketengine_p.cpp"
QAbstractSocket::NetworkLayerProtocol socketProtocol
QAbstractSocket::SocketError socketError
QString socketErrorString
QAbstractSocket::NetworkLayerProtocol protocol() const
void setState(QAbstractSocket::SocketState state)
QAbstractSocket::SocketType socketType() const
void exceptionNotification()
@ NonBlockingSocketOption
@ ReceiveBufferSocketOption
@ ReceivePacketInformation
QAbstractSocket::SocketState state() const
void connectionNotification()
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.
static constexpr auto IPv4Protocol
QNetworkProxy proxy() const
static constexpr auto UnknownNetworkLayerProtocol
static constexpr auto AnyIPProtocol
SocketType socketType() const
Returns the socket type (TCP, UDP, or other).
SocketError
This enum describes the socket errors that can occur.
@ UnsupportedSocketOperationError
static constexpr auto IPv6Protocol
SocketType
This enum describes the transport layer protocol.
const char * constData() const noexcept
Returns a pointer to the const data stored in the byte array.
QNativeSocketEngine * engine
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)
The QHostAddress class provides an IP address.
NetworkLayerProtocol protocol() const
Returns the network layer protocol of the host address.
constexpr const char * constData() const noexcept
const T & constFirst() const noexcept
QNativeSocketEnginePrivate()
~QNativeSocketEnginePrivate()
void setError(QAbstractSocket::SocketError error, ErrorString errorString) const
bool checkProxy(const QHostAddress &address)
QHostAddress adjustAddressProtocol(const QHostAddress &address) const
@ NetworkUnreachableErrorString
@ DatagramTooLargeErrorString
@ HostUnreachableErrorString
@ AddressProtectedErrorString
@ OperationUnsupportedErrorString
@ NetworkDroppedConnectionErrorString
@ ConnectionResetErrorString
@ ReceiveDatagramErrorString
@ AddressNotAvailableErrorString
@ NonBlockingInitFailedErrorString
@ RemoteHostClosedErrorString
@ InvalidSocketErrorString
@ ConnectionTimeOutErrorString
@ ConnectionRefusedErrorString
@ AddressInuseErrorString
@ ProtocolUnsupportedErrorString
@ SendDatagramErrorString
@ UnknownSocketErrorString
@ BroadcastingInitFailedErrorString
The QNativeSocketEngine class provides low level access to a socket.
void connectionNotification()
If there's a connection activity on the socket, process it.
bool waitForRead(int msecs=30000, bool *timedOut=nullptr) override
Waits for msecs milliseconds or until the socket is ready for reading.
bool waitForReadOrWrite(bool *readyToRead, bool *readyToWrite, bool checkRead, bool checkWrite, int msecs=30000, bool *timedOut=nullptr) override
bool isReadNotificationEnabled() const override
bool waitForWrite(int msecs=30000, bool *timedOut=nullptr) override
Waits for msecs milliseconds or until the socket is ready for writing.
bool isWriteNotificationEnabled() const override
void close() override
Closes the socket.
qint64 readDatagram(char *data, qint64 maxlen, QIpPacketHeader *=nullptr, PacketHeaderOptions=WantNone) override
Reads up to maxSize bytes of a datagram from the socket, stores it in data and returns the number of ...
qintptr accept() override
Accepts a pending connection from the socket, which must be in ListeningState, and returns its socket...
bool listen(int backlog) override
Prepares a TCP server for accepting incoming connections.
QNativeSocketEngine(QObject *parent=nullptr)
Constructs a QNativeSocketEngine.
qintptr socketDescriptor() const override
Returns the native socket descriptor.
bool connectToHost(const QHostAddress &address, quint16 port) override
Connects to the IP address and port specified by address and port.
bool setOption(SocketOption option, int value) override
Sets the option option to the value value.
qint64 bytesAvailable() const override
Returns the number of bytes that are currently available for reading.
int option(SocketOption option) const override
Returns the value of the option socketOption.
bool leaveMulticastGroup(const QHostAddress &groupAddress, const QNetworkInterface &iface) override
void setExceptionNotificationEnabled(bool enable) override
bool hasPendingDatagrams() const override
Returns true if there is at least one datagram pending.
qint64 writeDatagram(const char *data, qint64 len, const QIpPacketHeader &) override
Writes a datagram of size size bytes to the socket from data to the destination contained in header,...
~QNativeSocketEngine()
Destructs a QNativeSocketEngine.
bool isValid() const override
Returns true if the socket is valid; otherwise returns false.
bool bind(const QHostAddress &address, quint16 port) override
Binds the socket to the address address and port port.
qint64 pendingDatagramSize() const override
Returns the size of the pending datagram, or -1 if no datagram is pending.
qint64 write(const char *data, qint64 len) override
Writes a block of size bytes from data to the socket.
bool joinMulticastGroup(const QHostAddress &groupAddress, const QNetworkInterface &iface) override
bool isExceptionNotificationEnabled() const override
qint64 bytesToWrite() const override
bool setMulticastInterface(const QNetworkInterface &iface) override
QNetworkInterface multicastInterface() const override
bool connectToHostByName(const QString &name, quint16 port) override
Connects to the remote host name given by name on port port.
qint64 read(char *data, qint64 maxlen) override
Reads up to maxSize bytes into data from the socket.
bool initialize(QAbstractSocket::SocketType type, QAbstractSocket::NetworkLayerProtocol protocol=QAbstractSocket::IPv4Protocol) override
Initializes a QNativeSocketEngine by creating a new socket of type socketType and network layer proto...
void setReadNotificationEnabled(bool enable) override
void setWriteNotificationEnabled(bool enable) override
The QNetworkInterface class provides a listing of the host's IP addresses and network interfaces.
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.
QueryType
Describes the type of one QNetworkProxyQuery query.
The QNetworkProxy class provides a network layer proxy.
QNetworkProxy::ProxyType type() const
Returns the proxy type for this instance.
QObject * parent() const
Returns a pointer to the parent object.
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)
bool event(QEvent *) override
\reimp
\macro QT_RESTRICTED_CAST_FROM_ASCII
QByteArray toLatin1() const &
static QString machineHostName()
The QTcpServer class provides a TCP-based server.
QNativeSocketEngine * engine
QWriteNotifier(qintptr fd, QNativeSocketEngine *parent)
bool event(QEvent *) override
\reimp
Combined button and popup list for selecting options.
DBusConnection const char DBusError DBusBusType DBusError return DBusConnection DBusHandleMessageFunction void DBusFreeFunction return DBusConnection return DBusConnection return const char DBusError return DBusConnection DBusMessage dbus_uint32_t return DBusConnection dbus_bool_t DBusConnection DBusAddWatchFunction DBusRemoveWatchFunction DBusWatchToggledFunction void DBusFreeFunction return DBusConnection DBusDispatchStatusFunction void DBusFreeFunction DBusTimeout return DBusTimeout return DBusWatch return DBusWatch unsigned int return DBusError const DBusError return const DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessageIter int const void return DBusMessageIter DBusMessageIter return DBusMessageIter void DBusMessageIter void int return DBusMessage DBusMessageIter return DBusMessageIter return DBusMessageIter DBusMessageIter const char const char const char const char return DBusMessage return DBusMessage const char return DBusMessage dbus_bool_t return DBusMessage dbus_uint32_t return DBusMessage return DBusPendingCall DBusPendingCall return DBusPendingCall return dbus_int32_t return DBusServer * server
DBusConnection const char DBusError * error
static QString header(const QString &name)
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
static QT_BEGIN_NAMESPACE const char * socketType(QSocketNotifier::Type type)
Q_DECL_COLD_FUNCTION Q_CORE_EXPORT QString qt_error_string(int errorCode=-1)
#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)
void qDeleteInEventHandler(QObject *o)
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLuint GLuint64EXT address
static QLatin1StringView typeStr(QShaderDescription::VariableType t)
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent