11#include <qabstracteventdispatcher.h>
12#include <qsocketnotifier.h>
15#include <qnetworkinterface.h>
16#include <qoperatingsystemversion.h>
17#include <qvarlengtharray.h>
23#if defined(QNATIVESOCKETENGINE_DEBUG)
24#include <private/qdebug_p.h>
41#define TCP_KEEPINTVL 17
47#if defined(QNATIVESOCKETENGINE_DEBUG)
49void verboseWSErrorDebug(
int r)
52 case WSANOTINITIALISED : qDebug(
"WSA error : WSANOTINITIALISED");
break;
53 case WSAEINTR: qDebug(
"WSA error : WSAEINTR");
break;
54 case WSAEBADF: qDebug(
"WSA error : WSAEBADF");
break;
55 case WSAEACCES: qDebug(
"WSA error : WSAEACCES");
break;
56 case WSAEFAULT: qDebug(
"WSA error : WSAEFAULT");
break;
57 case WSAEINVAL: qDebug(
"WSA error : WSAEINVAL");
break;
58 case WSAEMFILE: qDebug(
"WSA error : WSAEMFILE");
break;
59 case WSAEWOULDBLOCK: qDebug(
"WSA error : WSAEWOULDBLOCK");
break;
60 case WSAEINPROGRESS: qDebug(
"WSA error : WSAEINPROGRESS");
break;
61 case WSAEALREADY: qDebug(
"WSA error : WSAEALREADY");
break;
62 case WSAENOTSOCK: qDebug(
"WSA error : WSAENOTSOCK");
break;
63 case WSAEDESTADDRREQ: qDebug(
"WSA error : WSAEDESTADDRREQ");
break;
64 case WSAEMSGSIZE: qDebug(
"WSA error : WSAEMSGSIZE");
break;
65 case WSAEPROTOTYPE: qDebug(
"WSA error : WSAEPROTOTYPE");
break;
66 case WSAENOPROTOOPT: qDebug(
"WSA error : WSAENOPROTOOPT");
break;
67 case WSAEPROTONOSUPPORT: qDebug(
"WSA error : WSAEPROTONOSUPPORT");
break;
68 case WSAESOCKTNOSUPPORT: qDebug(
"WSA error : WSAESOCKTNOSUPPORT");
break;
69 case WSAEOPNOTSUPP: qDebug(
"WSA error : WSAEOPNOTSUPP");
break;
70 case WSAEPFNOSUPPORT: qDebug(
"WSA error : WSAEPFNOSUPPORT");
break;
71 case WSAEAFNOSUPPORT: qDebug(
"WSA error : WSAEAFNOSUPPORT");
break;
72 case WSAEADDRINUSE: qDebug(
"WSA error : WSAEADDRINUSE");
break;
73 case WSAEADDRNOTAVAIL: qDebug(
"WSA error : WSAEADDRNOTAVAIL");
break;
74 case WSAENETDOWN: qDebug(
"WSA error : WSAENETDOWN");
break;
75 case WSAENETUNREACH: qDebug(
"WSA error : WSAENETUNREACH");
break;
76 case WSAENETRESET: qDebug(
"WSA error : WSAENETRESET");
break;
77 case WSAECONNABORTED: qDebug(
"WSA error : WSAECONNABORTED");
break;
78 case WSAECONNRESET: qDebug(
"WSA error : WSAECONNRESET");
break;
79 case WSAENOBUFS: qDebug(
"WSA error : WSAENOBUFS");
break;
80 case WSAEISCONN: qDebug(
"WSA error : WSAEISCONN");
break;
81 case WSAENOTCONN: qDebug(
"WSA error : WSAENOTCONN");
break;
82 case WSAESHUTDOWN: qDebug(
"WSA error : WSAESHUTDOWN");
break;
83 case WSAETOOMANYREFS: qDebug(
"WSA error : WSAETOOMANYREFS");
break;
84 case WSAETIMEDOUT: qDebug(
"WSA error : WSAETIMEDOUT");
break;
85 case WSAECONNREFUSED: qDebug(
"WSA error : WSAECONNREFUSED");
break;
86 case WSAELOOP: qDebug(
"WSA error : WSAELOOP");
break;
87 case WSAENAMETOOLONG: qDebug(
"WSA error : WSAENAMETOOLONG");
break;
88 case WSAEHOSTDOWN: qDebug(
"WSA error : WSAEHOSTDOWN");
break;
89 case WSAEHOSTUNREACH: qDebug(
"WSA error : WSAEHOSTUNREACH");
break;
90 case WSAENOTEMPTY: qDebug(
"WSA error : WSAENOTEMPTY");
break;
91 case WSAEPROCLIM: qDebug(
"WSA error : WSAEPROCLIM");
break;
92 case WSAEUSERS: qDebug(
"WSA error : WSAEUSERS");
break;
93 case WSAEDQUOT: qDebug(
"WSA error : WSAEDQUOT");
break;
94 case WSAESTALE: qDebug(
"WSA error : WSAESTALE");
break;
95 case WSAEREMOTE: qDebug(
"WSA error : WSAEREMOTE");
break;
96 case WSAEDISCON: qDebug(
"WSA error : WSAEDISCON");
break;
97 default: qDebug(
"WSA error : Unknown");
break;
99 qErrnoWarning(r,
"more details");
102#define WS_ERROR_DEBUG(x) verboseWSErrorDebug(x)
106#define WS_ERROR_DEBUG(x) Q_UNUSED(x)
114#ifndef SO_EXCLUSIVEADDRUSE
115#define SO_EXCLUSIVEADDRUSE ((int)(~SO_REUSEADDR
))
119
120
121
125 const sockaddr_in6 *sa6 = &sa->a6;
127 for (
int i = 0; i < 16; ++i)
128 tmp.c[i] = sa6->sin6_addr.s6_addr[i];
132 if (sa6->sin6_scope_id)
133 a.setScopeId(QString::number(sa6->sin6_scope_id));
137 WSANtohs(socketDescriptor, sa6->sin6_port, port);
140 if (sa->a.sa_family == AF_INET) {
141 const sockaddr_in *sa4 = &sa->a4;
143 WSANtohl(socketDescriptor, sa4->sin_addr.s_addr, &addr);
149 WSANtohs(socketDescriptor, sa4->sin_port, port);
154 QAbstractSocket::NetworkLayerProtocol socketProtocol,
int &level,
int &n)
160 case QNativeSocketEngine::NonBlockingSocketOption:
161 case QNativeSocketEngine::TypeOfServiceOption:
162 case QNativeSocketEngine::MaxStreamsSocketOption:
165 case QNativeSocketEngine::BindInterfaceIndex:
168 case QNativeSocketEngine::ReceiveBufferSocketOption:
171 case QNativeSocketEngine::SendBufferSocketOption:
174 case QNativeSocketEngine::BroadcastSocketOption:
177 case QNativeSocketEngine::AddressReusable:
180 case QNativeSocketEngine::BindExclusively:
183 case QNativeSocketEngine::ReceiveOutOfBandData:
186 case QNativeSocketEngine::LowDelayOption:
190 case QNativeSocketEngine::KeepAliveOption:
193 case QNativeSocketEngine::MulticastTtlOption:
194 if (socketProtocol == QAbstractSocket::IPv6Protocol || socketProtocol == QAbstractSocket::AnyIPProtocol) {
195 level = IPPROTO_IPV6;
196 n = IPV6_MULTICAST_HOPS;
200 n = IP_MULTICAST_TTL;
203 case QNativeSocketEngine::MulticastLoopbackOption:
204 if (socketProtocol == QAbstractSocket::IPv6Protocol || socketProtocol == QAbstractSocket::AnyIPProtocol) {
205 level = IPPROTO_IPV6;
206 n = IPV6_MULTICAST_LOOP;
210 n = IP_MULTICAST_LOOP;
213 case QNativeSocketEngine::ReceivePacketInformation:
216 case QNativeSocketEngine::ReceiveHopLimit:
217 if (socketProtocol == QAbstractSocket::IPv6Protocol || socketProtocol == QAbstractSocket::AnyIPProtocol) {
218 level = IPPROTO_IPV6;
220 }
else if (socketProtocol == QAbstractSocket::IPv4Protocol) {
226 case QAbstractSocketEngine::PathMtuInformation:
228 case QNativeSocketEngine::KeepAliveIdleOption:
232 case QNativeSocketEngine::KeepAliveIntervalOption:
236 case QNativeSocketEngine::KeepAliveCountOption:
244
245
249 QT_SOCKLEN_T valueSize =
sizeof(value);
250 if (::getsockopt(socketDescriptor, SOL_SOCKET, SO_TYPE,
251 reinterpret_cast<
char *>(&value), &valueSize) != 0) {
254 if (value == SOCK_STREAM)
255 return QAbstractSocket::TcpSocket;
256 else if (value == SOCK_DGRAM)
257 return QAbstractSocket::UdpSocket;
259 return QAbstractSocket::UnknownSocketType;
267#ifndef SIO_UDP_CONNRESET
269# define IOC_VENDOR 0x18000000
272# define _WSAIOW(x,y) (IOC_IN|(x)|(y))
280 if (socketType == QAbstractSocket::SctpSocket) {
281 setError(QAbstractSocket::UnsupportedSocketOperationError,
282 ProtocolUnsupportedErrorString);
287 int protocol = (socketProtocol == QAbstractSocket::IPv6Protocol
288 || (socketProtocol == QAbstractSocket::AnyIPProtocol)) ?
AF_INET6 : AF_INET;
289 int type = (socketType == QAbstractSocket::UdpSocket) ? SOCK_DGRAM : SOCK_STREAM;
295#ifndef WSA_FLAG_NO_HANDLE_INHERIT
296#define WSA_FLAG_NO_HANDLE_INHERIT 0x80
300 if (socket == INVALID_SOCKET) {
301 int err = WSAGetLastError();
304 case WSANOTINITIALISED:
307 case WSAEAFNOSUPPORT:
308 case WSAESOCKTNOSUPPORT:
311 setError(QAbstractSocket::UnsupportedSocketOperationError, ProtocolUnsupportedErrorString);
315 setError(QAbstractSocket::SocketResourceError, ResourceErrorString);
324 if (socketType == QAbstractSocket::UdpSocket) {
327 DWORD dwBytesReturned = 0;
328 int bNewBehavior = 1;
330 NULL, 0, &dwBytesReturned, NULL, NULL) == SOCKET_ERROR) {
332 int err = WSAGetLastError();
339 GUID recvmsgguid = WSAID_WSARECVMSG;
340 if (WSAIoctl(socket, SIO_GET_EXTENSION_FUNCTION_POINTER,
341 &recvmsgguid,
sizeof(recvmsgguid),
342 &recvmsg,
sizeof(recvmsg), &bytesReturned, NULL, NULL) == SOCKET_ERROR)
345 GUID sendmsgguid = WSAID_WSASENDMSG;
346 if (WSAIoctl(socket, SIO_GET_EXTENSION_FUNCTION_POINTER,
347 &sendmsgguid,
sizeof(sendmsgguid),
348 &sendmsg,
sizeof(sendmsg), &bytesReturned, NULL, NULL) == SOCKET_ERROR)
355 reinterpret_cast<
char *>(&ipv6only),
sizeof(ipv6only));
358 socketDescriptor = socket;
359 this->socketProtocol = socketProtocol;
360 this->socketType = socketType;
363 if (!setOption(QAbstractSocketEngine::NonBlockingSocketOption, 1)) {
364 setError(QAbstractSocket::UnsupportedSocketOperationError, NonBlockingInitFailedErrorString);
373
374
375
378 Q_Q(
const QNativeSocketEngine);
384 case QNativeSocketEngine::NonBlockingSocketOption: {
385 unsigned long buf = 0;
386 if (WSAIoctl(socketDescriptor, FIONBIO, 0,0, &buf,
sizeof(buf), 0,0,0) == 0)
392 case QNativeSocketEngine::TypeOfServiceOption:
393 case QNativeSocketEngine::MaxStreamsSocketOption:
400#if Q_BYTE_ORDER != Q_LITTLE_ENDIAN
401#error code assumes windows is little endian
405 QT_SOCKOPTLEN_T len =
sizeof(v);
407 convertToLevelAndOption(opt, socketProtocol, level, n);
409 if (getsockopt(socketDescriptor, level, n, (
char *) &v, &len) == 0)
418
419
422 Q_Q(
const QNativeSocketEngine);
428 case QNativeSocketEngine::SendBufferSocketOption:
431 case QNativeSocketEngine::NonBlockingSocketOption:
433 unsigned long buf = v;
434 unsigned long outBuf;
435 DWORD sizeWritten = 0;
436 if (::WSAIoctl(socketDescriptor, FIONBIO, &buf,
sizeof(
unsigned long), &outBuf,
sizeof(
unsigned long), &sizeWritten, 0,0) == SOCKET_ERROR) {
442 case QNativeSocketEngine::TypeOfServiceOption:
443 case QNativeSocketEngine::MaxStreamsSocketOption:
446 case QNativeSocketEngine::ReceivePacketInformation: {
447 if (socketProtocol == QAbstractSocket::IPv6Protocol
448 || socketProtocol == QAbstractSocket::AnyIPProtocol) {
450 if (::setsockopt(socketDescriptor, IPPROTO_IPV6, IPV6_PKTINFO,
451 reinterpret_cast<
char *>(&v),
sizeof(v)) != 0) {
458 if (::setsockopt(socketDescriptor, IPPROTO_IP, IP_PKTINFO,
459 reinterpret_cast<
char *>(&v),
sizeof(v)) != 0) {
460 if (socketProtocol == QAbstractSocket::IPv4Protocol) {
468 case QNativeSocketEngine::BindInterfaceIndex: {
470 if (socketProtocol == QAbstractSocket::IPv6Protocol
471 || socketProtocol == QAbstractSocket::AnyIPProtocol) {
475 ret = ::setsockopt(socketDescriptor, IPPROTO_IPV6, IPV6_UNICAST_IF,
476 reinterpret_cast<
char *>(&v),
sizeof(v));
479 ret = ::setsockopt(socketDescriptor, IPPROTO_IPV6, IPV6_MULTICAST_IF,
480 reinterpret_cast<
char *>(&v),
sizeof(v));
484 const int enable = 1;
485 ret = ::setsockopt(socketDescriptor, IPPROTO_IPV6, IPV6_IFLIST,
486 reinterpret_cast<
const char *>(&enable),
sizeof(enable));
488 ret = ::setsockopt(socketDescriptor, IPPROTO_IPV6, IPV6_ADD_IFLIST,
489 reinterpret_cast<
char *>(&v),
sizeof(v));
499 int netIdx = htonl(v);
502 ret = ::setsockopt(socketDescriptor, IPPROTO_IP, IP_UNICAST_IF,
503 reinterpret_cast<
char *>(&netIdx),
sizeof(netIdx));
506 ret = ::setsockopt(socketDescriptor, IPPROTO_IP, IP_MULTICAST_IF,
507 reinterpret_cast<
char *>(&netIdx),
sizeof(netIdx));
511 const int enable = 1;
512 ret = ::setsockopt(socketDescriptor, IPPROTO_IP, IP_IFLIST,
513 reinterpret_cast<
const char *>(&enable),
sizeof(enable));
516 ret = ::setsockopt(socketDescriptor, IPPROTO_IP, IP_ADD_IFLIST,
517 reinterpret_cast<
char *>(&v),
sizeof(v));
520 if (socketProtocol == QAbstractSocket::IPv4Protocol)
531 convertToLevelAndOption(opt, socketProtocol, level, n);
534 if (::setsockopt(socketDescriptor, level, n, (
char*)&v,
sizeof(v)) != 0) {
542
543
544
547
548
549
553 localAddress.clear();
556 inboundStreamCount = outboundStreamCount = 0;
558 if (socketDescriptor == -1)
562 QT_SOCKLEN_T sockAddrSize =
sizeof(sa);
565 memset(&sa, 0,
sizeof(sa));
566 if (::getsockname(socketDescriptor, &sa.a, &sockAddrSize) == 0) {
567 qt_socket_getPortAndAddress(socketDescriptor, &sa, &localPort, &localAddress);
569 switch (sa.a.sa_family) {
571 socketProtocol = QAbstractSocket::IPv4Protocol;
574 socketProtocol = QAbstractSocket::IPv6Protocol;
577 socketProtocol = QAbstractSocket::UnknownNetworkLayerProtocol;
581 int err = WSAGetLastError();
583 if (err == WSAENOTSOCK) {
584 setError(QAbstractSocket::UnsupportedSocketOperationError,
585 InvalidSocketErrorString);
592 QT_SOCKOPTLEN_T optlen =
sizeof(ipv6only);
593 if (localAddress == QHostAddress::AnyIPv6
594 && !getsockopt(socketDescriptor, IPPROTO_IPV6,
IPV6_V6ONLY, (
char*)&ipv6only, &optlen )) {
596 socketProtocol = QAbstractSocket::AnyIPProtocol;
597 localAddress = QHostAddress::Any;
605 const uchar ipv6MappedNet[] = {0,0,0,0, 0,0,0,0, 0,0,0xff,0xff, 0,0,0,0};
606 if (localAddress.isInSubnet(QHostAddress(ipv6MappedNet), 128 - 32)) {
608 const quint32 localIPv4 = localAddress.toIPv4Address(&ok);
609 if (ok && localIPv4 == INADDR_ANY) {
610 socketProtocol = QAbstractSocket::AnyIPProtocol;
611 localAddress = QHostAddress::Any;
615 memset(&sa, 0,
sizeof(sa));
616 if (::getpeername(socketDescriptor, &sa.a, &sockAddrSize) == 0) {
617 qt_socket_getPortAndAddress(socketDescriptor, &sa, &peerPort, &peerAddress);
618 inboundStreamCount = outboundStreamCount = 1;
623 socketType = qt_socket_getType(socketDescriptor);
625#if defined (QNATIVESOCKETENGINE_DEBUG)
626 QString socketProtocolStr = QStringLiteral(
"UnknownProtocol");
627 if (socketProtocol == QAbstractSocket::IPv4Protocol) socketProtocolStr = QStringLiteral(
"IPv4Protocol");
628 else if (socketProtocol == QAbstractSocket::IPv6Protocol) socketProtocolStr = QStringLiteral(
"IPv6Protocol");
630 QString socketTypeStr = QStringLiteral(
"UnknownSocketType");
631 if (socketType == QAbstractSocket::TcpSocket) socketTypeStr = QStringLiteral(
"TcpSocket");
632 else if (socketType == QAbstractSocket::UdpSocket) socketTypeStr = QStringLiteral(
"UdpSocket");
634 qDebug(
"QNativeSocketEnginePrivate::fetchConnectionParameters() localAddress == %s, localPort = %i, peerAddress == %s, peerPort = %i, socketProtocol == %s, socketType == %s", localAddress.toString().toLatin1().constData(), localPort, peerAddress.toString().toLatin1().constData(), peerPort, socketProtocolStr.toLatin1().constData(), socketTypeStr.toLatin1().constData());
646 d->socketState = QAbstractSocket::ConnectedState;
648 case WSAEHOSTUNREACH:
650 d->socketState = QAbstractSocket::UnconnectedState;
652 case WSAEADDRNOTAVAIL:
654 d->socketState = QAbstractSocket::UnconnectedState;
658 d->socketState = QAbstractSocket::ConnectingState;
663 case WSAECONNREFUSED:
665 d->socketState = QAbstractSocket::UnconnectedState;
669 d->socketState = QAbstractSocket::UnconnectedState;
673 d->socketState = QAbstractSocket::UnconnectedState;
677 d->socketState = QAbstractSocket::UnconnectedState;
691#if defined (QNATIVESOCKETENGINE_DEBUG)
692 qDebug(
"QNativeSocketEnginePrivate::nativeConnect() to %s :: %i", address.toString().toLatin1().constData(), port);
696 QT_SOCKLEN_T sockAddrSize = 0;
698 setPortAndAddress(port, address, &aa, &sockAddrSize);
700 if ((socketProtocol == QAbstractSocket::IPv6Protocol || socketProtocol == QAbstractSocket::AnyIPProtocol) && address.toIPv4Address()) {
703 ipv6only = ::setsockopt(socketDescriptor, IPPROTO_IPV6,
IPV6_V6ONLY, (
char*)&ipv6only,
sizeof(ipv6only) );
707 int connectResult = ::WSAConnect(socketDescriptor, &aa.a, sockAddrSize, 0,0,0,0);
708 if (connectResult == SOCKET_ERROR) {
709 int err = WSAGetLastError();
713 case WSANOTINITIALISED:
716 case WSAEWOULDBLOCK: {
723 QT_SOCKLEN_T valueSize =
sizeof(value);
724 bool tryAgain =
false;
725 bool errorDetected =
false;
728 if (::getsockopt(socketDescriptor, SOL_SOCKET, SO_ERROR, (
char *) &value, &valueSize) == 0) {
729 if (value != NOERROR) {
731 errorDetected =
true;
734 const int val = NO_ERROR;
735 ::setsockopt(socketDescriptor, SOL_SOCKET, SO_ERROR,
reinterpret_cast<
const char*>(&val),
sizeof val);
741 tryAgain = !tryAgain;
743 setErrorFromWSAError(value,
this);
746 }
while (tryAgain && (tries < 2));
751 err = WSAEINPROGRESS;
756 setErrorFromWSAError(err,
this);
759 if (socketState != QAbstractSocket::ConnectedState) {
760#if defined (QNATIVESOCKETENGINE_DEBUG)
761 qDebug(
"QNativeSocketEnginePrivate::nativeConnect(%s, %i) == false (%s)",
762 address.toString().toLatin1().constData(), port,
763 socketState == QAbstractSocket::ConnectingState
764 ?
"Connection in progress" : socketErrorString.toLatin1().constData());
772#if defined (QNATIVESOCKETENGINE_DEBUG)
773 qDebug(
"QNativeSocketEnginePrivate::nativeConnect(%s, %i) == true",
774 address.toString().toLatin1().constData(), port);
777 socketState = QAbstractSocket::ConnectedState;
784 QHostAddress address = a;
785 if (address.protocol() == QAbstractSocket::IPv4Protocol) {
786 if ((address.toIPv4Address() & 0xffff0000) == 0xefff0000) {
788 address = QHostAddress(QHostAddress::AnyIPv4);
793 QT_SOCKLEN_T sockAddrSize = 0;
794 setPortAndAddress(port, address, &aa, &sockAddrSize);
799 if (address.protocol() == QAbstractSocket::IPv6Protocol)
801 ::setsockopt(socketDescriptor, IPPROTO_IPV6,
IPV6_V6ONLY, (
char*)&ipv6only,
sizeof(ipv6only) );
805 int bindResult = ::bind(socketDescriptor, &aa.a, sockAddrSize);
806 if (bindResult == SOCKET_ERROR && WSAGetLastError() == WSAEAFNOSUPPORT
807 && address.protocol() == QAbstractSocket::AnyIPProtocol) {
809 aa.a4.sin_family = AF_INET;
810 aa.a4.sin_port = htons(port);
811 aa.a4.sin_addr.s_addr = htonl(address.toIPv4Address());
812 sockAddrSize =
sizeof(aa.a4);
813 bindResult = ::bind(socketDescriptor, &aa.a, sockAddrSize);
815 if (bindResult == SOCKET_ERROR) {
816 int err = WSAGetLastError();
819 case WSANOTINITIALISED:
824 setError(QAbstractSocket::AddressInUseError, AddressInuseErrorString);
827 setError(QAbstractSocket::SocketAccessError, AddressProtectedErrorString);
829 case WSAEADDRNOTAVAIL:
830 setError(QAbstractSocket::SocketAddressNotAvailableError, AddressNotAvailableErrorString);
836#if defined (QNATIVESOCKETENGINE_DEBUG)
837 qDebug(
"QNativeSocketEnginePrivate::nativeBind(%s, %i) == false (%s)",
838 address.toString().toLatin1().constData(), port, socketErrorString.toLatin1().constData());
844#if defined (QNATIVESOCKETENGINE_DEBUG)
845 qDebug(
"QNativeSocketEnginePrivate::nativeBind(%s, %i) == true",
846 address.toString().toLatin1().constData(), port);
848 socketState = QAbstractSocket::BoundState;
855 if (::listen(socketDescriptor, backlog) == SOCKET_ERROR) {
856 int err = WSAGetLastError();
859 case WSANOTINITIALISED:
863 setError(QAbstractSocket::AddressInUseError,
864 PortInuseErrorString);
870#if defined (QNATIVESOCKETENGINE_DEBUG)
871 qDebug(
"QNativeSocketEnginePrivate::nativeListen(%i) == false (%s)",
872 backlog, socketErrorString.toLatin1().constData());
877#if defined (QNATIVESOCKETENGINE_DEBUG)
878 qDebug(
"QNativeSocketEnginePrivate::nativeListen(%i) == true", backlog);
881 socketState = QAbstractSocket::ListeningState;
887 SOCKET acceptedDescriptor = WSAAccept(socketDescriptor, 0,0,0,0);
888 if (acceptedDescriptor == INVALID_SOCKET) {
889 int err = WSAGetLastError();
892 setError(QAbstractSocket::SocketAccessError, AccessErrorString);
894 case WSAECONNREFUSED:
895 setError(QAbstractSocket::ConnectionRefusedError, ConnectionRefusedErrorString);
898 setError(QAbstractSocket::NetworkError, RemoteHostClosedErrorString);
901 setError(QAbstractSocket::NetworkError, NetworkUnreachableErrorString);
904 setError(QAbstractSocket::SocketResourceError, NotSocketErrorString);
908 setError(QAbstractSocket::UnsupportedSocketOperationError, ProtocolUnsupportedErrorString);
913 setError(QAbstractSocket::SocketResourceError, ResourceErrorString);
916 setError(QAbstractSocket::TemporaryError, TemporaryErrorString);
919 setError(QAbstractSocket::UnknownSocketError, UnknownSocketErrorString);
922 }
else if (acceptedDescriptor != INVALID_SOCKET && QAbstractEventDispatcher::instance()) {
927 QSocketNotifier n(acceptedDescriptor, QSocketNotifier::Read);
931#if defined (QNATIVESOCKETENGINE_DEBUG)
932 qDebug(
"QNativeSocketEnginePrivate::nativeAccept() == %lld", qint64(acceptedDescriptor));
934 return qintptr(acceptedDescriptor);
940 const QHostAddress &groupAddress,
941 const QNetworkInterface &iface)
948 struct ip_mreq mreq4;
949 struct ipv6_mreq mreq6;
951 if (groupAddress.protocol() == QAbstractSocket::IPv6Protocol) {
952 level = IPPROTO_IPV6;
954 sockArg =
reinterpret_cast<
char *>(&mreq6);
955 sockArgSize =
sizeof(mreq6);
956 memset(&mreq6, 0,
sizeof(mreq6));
957 Q_IPV6ADDR ip6 = groupAddress.toIPv6Address();
958 memcpy(&mreq6.ipv6mr_multiaddr, &ip6,
sizeof(ip6));
959 mreq6.ipv6mr_interface = iface.index();
960 }
else if (groupAddress.protocol() == QAbstractSocket::IPv4Protocol) {
963 sockArg =
reinterpret_cast<
char *>(&mreq4);
964 sockArgSize =
sizeof(mreq4);
965 memset(&mreq4, 0,
sizeof(mreq4));
966 mreq4.imr_multiaddr.s_addr = htonl(groupAddress.toIPv4Address());
968 if (iface.isValid()) {
969 const QList<QNetworkAddressEntry> addressEntries = iface.addressEntries();
971 for (
const QNetworkAddressEntry &entry : addressEntries) {
972 const QHostAddress ip = entry.ip();
973 if (ip.protocol() == QAbstractSocket::IPv4Protocol) {
974 mreq4.imr_interface.s_addr = htonl(ip.toIPv4Address());
980 d->setError(QAbstractSocket::NetworkError,
985 mreq4.imr_interface.s_addr = INADDR_ANY;
989 d->setError(QAbstractSocket::UnsupportedSocketOperationError,
994 int res = setsockopt(d->socketDescriptor, level, sockOpt, sockArg, sockArgSize);
996 d->setError(QAbstractSocket::UnsupportedSocketOperationError,
1004 const QNetworkInterface &iface)
1006 return multicastMembershipHelper(
this,
1014 const QNetworkInterface &iface)
1016 return multicastMembershipHelper(
this,
1025 if (socketProtocol == QAbstractSocket::IPv6Protocol || socketProtocol == QAbstractSocket::AnyIPProtocol) {
1027 QT_SOCKOPTLEN_T sizeofv =
sizeof(v);
1028 if (::getsockopt(socketDescriptor, IPPROTO_IPV6, IPV6_MULTICAST_IF, (
char *) &v, &sizeofv) == -1)
1029 return QNetworkInterface();
1030 return QNetworkInterface::interfaceFromIndex(v);
1035 QT_SOCKOPTLEN_T sizeofv =
sizeof(v);
1036 if (::getsockopt(socketDescriptor, IPPROTO_IP, IP_MULTICAST_IF, (
char *) &v, &sizeofv) == -1)
1037 return QNetworkInterface();
1038 if (v.s_addr != 0 && sizeofv >= QT_SOCKOPTLEN_T(
sizeof(v))) {
1039 QHostAddress ipv4(ntohl(v.s_addr));
1040 QList<QNetworkInterface> ifaces = QNetworkInterface::allInterfaces();
1041 for (
int i = 0; i < ifaces.count(); ++i) {
1042 const QNetworkInterface &iface = ifaces.at(i);
1043 if (!(iface.flags() & QNetworkInterface::CanMulticast))
1045 QList<QNetworkAddressEntry> entries = iface.addressEntries();
1046 for (
int j = 0; j < entries.count(); ++j) {
1047 const QNetworkAddressEntry &entry = entries.at(j);
1048 if (entry.ip() == ipv4)
1053 return QNetworkInterface();
1059 if (socketProtocol == QAbstractSocket::IPv6Protocol || socketProtocol == QAbstractSocket::AnyIPProtocol) {
1060 uint v = iface.isValid() ? iface.index() : 0;
1061 return (::setsockopt(socketDescriptor, IPPROTO_IPV6, IPV6_MULTICAST_IF, (
char *) &v,
sizeof(v)) != -1);
1065 if (iface.isValid()) {
1066 QList<QNetworkAddressEntry> entries = iface.addressEntries();
1067 for (
int i = 0; i < entries.count(); ++i) {
1068 const QNetworkAddressEntry &entry = entries.at(i);
1069 const QHostAddress &ip = entry.ip();
1070 if (ip.protocol() == QAbstractSocket::IPv4Protocol) {
1071 v.s_addr = htonl(ip.toIPv4Address());
1072 int r = ::setsockopt(socketDescriptor, IPPROTO_IP, IP_MULTICAST_IF, (
char *) &v,
sizeof(v));
1080 v.s_addr = INADDR_ANY;
1081 return (::setsockopt(socketDescriptor, IPPROTO_IP, IP_MULTICAST_IF, (
char *) &v,
sizeof(v)) != -1);
1086 unsigned long nbytes = 0;
1087 unsigned long dummy = 0;
1088 DWORD sizeWritten = 0;
1089 if (::WSAIoctl(socketDescriptor, FIONREAD, &dummy,
sizeof(dummy), &nbytes,
sizeof(nbytes), &sizeWritten, 0,0) == SOCKET_ERROR) {
1099 if (nbytes == 1 && socketType == QAbstractSocket::UdpSocket) {
1103 buf.len =
sizeof(c);
1104 DWORD bytesReceived;
1105 DWORD flags = MSG_PEEK;
1106 if (::WSARecvFrom(socketDescriptor, &buf, 1, &bytesReceived, &flags, 0,0,0,0) == SOCKET_ERROR) {
1107 int err = WSAGetLastError();
1108 if (err != WSAECONNRESET && err != WSAENETRESET)
1111 return bytesReceived;
1121 qt_sockaddr storage;
1122 QT_SOCKLEN_T storageSize =
sizeof(storage);
1123 memset(&storage, 0, storageSize);
1125 bool result =
false;
1132 buf.len =
sizeof(c);
1133 DWORD available = 0;
1134 DWORD flags = MSG_PEEK;
1135 int ret = ::WSARecvFrom(socketDescriptor, &buf, 1, &available, &flags, &storage.a, &storageSize,0,0);
1136 int err = WSAGetLastError();
1137 if (ret == SOCKET_ERROR && err != WSAEMSGSIZE) {
1139 result = (err == WSAECONNRESET || err == WSAENETRESET);
1146#if defined (QNATIVESOCKETENGINE_DEBUG)
1147 qDebug(
"QNativeSocketEnginePrivate::nativeHasPendingDatagrams() == %s",
1148 result ?
"true" :
"false");
1161 char udpMessagePeekBuffer[2048];
1162 const int increments = 5;
1163 QVarLengthArray<WSABUF, 10> buf;
1165 buf.reserve(buf.size() + increments);
1166 std::fill_n(std::back_inserter(buf), increments, WSABUF{
sizeof(udpMessagePeekBuffer), udpMessagePeekBuffer});
1169 DWORD bytesRead = 0;
1170 recvResult = ::WSARecv(socketDescriptor, buf.data(), DWORD(buf.size()), &bytesRead, &flags,
nullptr,
nullptr);
1171 int err = WSAGetLastError();
1172 if (recvResult != SOCKET_ERROR) {
1173 ret = qint64(bytesRead);
1192#if defined (QNATIVESOCKETENGINE_DEBUG)
1193 qDebug(
"QNativeSocketEnginePrivate::nativePendingDatagramSize() == %lli", ret);
1200 QAbstractSocketEngine::PacketHeaderOptions options)
1203 char cbuf[WSA_CMSG_SPACE(
sizeof(
struct in6_pktinfo)) + WSA_CMSG_SPACE(
sizeof(
int))];
1210 memset(&msg, 0,
sizeof(msg));
1211 memset(&aa, 0,
sizeof(aa));
1214 buf.buf = maxLength ? data : &c;
1215 buf.len = maxLength ? maxLength : 1;
1216 msg.lpBuffers = &buf;
1217 msg.dwBufferCount = 1;
1218 msg.name =
reinterpret_cast<LPSOCKADDR>(&aa);
1219 msg.namelen =
sizeof(aa);
1220 msg.Control.buf = cbuf;
1221 msg.Control.len =
sizeof(cbuf);
1224 DWORD bytesRead = 0;
1228 ret = recvmsg(socketDescriptor, &msg, &bytesRead, 0,0);
1230 ret = ::WSARecvFrom(socketDescriptor, &buf, 1, &bytesRead, &flags, msg.name, &msg.namelen,0,0);
1231 if (ret == SOCKET_ERROR) {
1232 int err = WSAGetLastError();
1233 if (err == WSAEMSGSIZE) {
1236 ret = qint64(bytesRead) > maxLength ? maxLength : qint64(bytesRead);
1237 if (options & QNativeSocketEngine::WantDatagramSender)
1238 qt_socket_getPortAndAddress(socketDescriptor, &aa, &header->senderPort, &header->senderAddress);
1243 setError(QAbstractSocket::NetworkError, NetworkDroppedConnectionErrorString);
1246 setError(QAbstractSocket::ConnectionRefusedError, ConnectionResetErrorString);
1249 setError(QAbstractSocket::NetworkError, ReceiveDatagramErrorString);
1257 ret = qint64(bytesRead);
1258 if (options & QNativeSocketEngine::WantDatagramSender)
1259 qt_socket_getPortAndAddress(socketDescriptor, &aa, &header->senderPort, &header->senderAddress);
1262 if (ret != -1 && recvmsg && options != QAbstractSocketEngine::WantNone) {
1264 header->destinationPort = localPort;
1265 WSACMSGHDR *cmsgptr;
1266 for (cmsgptr = WSA_CMSG_FIRSTHDR(&msg); cmsgptr != NULL;
1267 cmsgptr = WSA_CMSG_NXTHDR(&msg, cmsgptr)) {
1268 if (cmsgptr->cmsg_level == IPPROTO_IPV6 && cmsgptr->cmsg_type == IPV6_PKTINFO
1269 && cmsgptr->cmsg_len >= WSA_CMSG_LEN(
sizeof(in6_pktinfo))) {
1270 in6_pktinfo *info =
reinterpret_cast<in6_pktinfo *>(WSA_CMSG_DATA(cmsgptr));
1272 header->destinationAddress.setAddress(
reinterpret_cast<quint8 *>(&info->ipi6_addr));
1273 header->ifindex = info->ipi6_ifindex;
1274 if (header->ifindex)
1275 header->destinationAddress.setScopeId(QString::number(info->ipi6_ifindex));
1277 if (cmsgptr->cmsg_level == IPPROTO_IP && cmsgptr->cmsg_type == IP_PKTINFO
1278 && cmsgptr->cmsg_len >= WSA_CMSG_LEN(
sizeof(in_pktinfo))) {
1279 in_pktinfo *info =
reinterpret_cast<in_pktinfo *>(WSA_CMSG_DATA(cmsgptr));
1281 WSANtohl(socketDescriptor, info->ipi_addr.s_addr, &addr);
1282 header->destinationAddress.setAddress(addr);
1283 header->ifindex = info->ipi_ifindex;
1286 if (cmsgptr->cmsg_len == WSA_CMSG_LEN(
sizeof(
int))
1287 && ((cmsgptr->cmsg_level == IPPROTO_IPV6 && cmsgptr->cmsg_type == IPV6_HOPLIMIT)
1288 || (cmsgptr->cmsg_level == IPPROTO_IP && cmsgptr->cmsg_type == IP_TTL))) {
1289 header->hopLimit = *
reinterpret_cast<
int *>(WSA_CMSG_DATA(cmsgptr));
1294#if defined (QNATIVESOCKETENGINE_DEBUG)
1295 bool printSender = (ret != -1 && (options & QNativeSocketEngine::WantDatagramSender) != 0);
1296 qDebug(
"QNativeSocketEnginePrivate::nativeReceiveDatagram(%p \"%s\", %lli, %s, %i) == %lli",
1297 data, QtDebugUtils::toPrintable(data, ret, 16).constData(), maxLength,
1298 printSender ? header->senderAddress.toString().toLatin1().constData() :
"(unknown)",
1299 printSender ? header->senderPort : 0, ret);
1307 const QIpPacketHeader &header)
1310 char cbuf[WSA_CMSG_SPACE(
sizeof(
struct in6_pktinfo)) + WSA_CMSG_SPACE(
sizeof(
int))];
1313 WSACMSGHDR *cmsgptr = &align;
1318 memset(&msg, 0,
sizeof(msg));
1319 memset(&aa, 0,
sizeof(aa));
1320 buf.buf = len ? (
char*)data : 0;
1321 msg.lpBuffers = &buf;
1322 msg.dwBufferCount = 1;
1326 setPortAndAddress(header.destinationPort, header.destinationAddress, &aa, &msg.namelen);
1328 uint oldIfIndex = 0;
1329 bool mustSetIpv6MulticastIf =
false;
1331 if (msg.namelen ==
sizeof(aa.a6)) {
1333 if (header.hopLimit != -1) {
1334 msg.Control.len += WSA_CMSG_SPACE(
sizeof(
int));
1335 cmsgptr->cmsg_len = WSA_CMSG_LEN(
sizeof(
int));
1336 cmsgptr->cmsg_level = IPPROTO_IPV6;
1337 cmsgptr->cmsg_type = IPV6_HOPLIMIT;
1338 memcpy(WSA_CMSG_DATA(cmsgptr), &header.hopLimit,
sizeof(
int));
1339 cmsgptr =
reinterpret_cast<WSACMSGHDR *>(
reinterpret_cast<
char *>(cmsgptr)
1340 + WSA_CMSG_SPACE(
sizeof(
int)));
1342 if (!header.senderAddress.isNull()) {
1343 struct in6_pktinfo *data =
reinterpret_cast<in6_pktinfo *>(WSA_CMSG_DATA(cmsgptr));
1344 memset(data, 0,
sizeof(*data));
1345 msg.Control.len += WSA_CMSG_SPACE(
sizeof(*data));
1346 cmsgptr->cmsg_len = WSA_CMSG_LEN(
sizeof(*data));
1347 cmsgptr->cmsg_level = IPPROTO_IPV6;
1348 cmsgptr->cmsg_type = IPV6_PKTINFO;
1349 data->ipi6_ifindex = header.ifindex;
1351 Q_IPV6ADDR tmp = header.senderAddress.toIPv6Address();
1352 memcpy(&data->ipi6_addr, &tmp,
sizeof(tmp));
1353 cmsgptr =
reinterpret_cast<WSACMSGHDR *>(
reinterpret_cast<
char *>(cmsgptr)
1354 + WSA_CMSG_SPACE(
sizeof(*data)));
1355 }
else if (header.ifindex != 0) {
1361 QT_SOCKOPTLEN_T len =
sizeof(oldIfIndex);
1362 if (::getsockopt(socketDescriptor, IPPROTO_IPV6, IPV6_MULTICAST_IF,
1363 reinterpret_cast<
char *>(&oldIfIndex), &len) == -1
1364 || ::setsockopt(socketDescriptor, IPPROTO_IPV6, IPV6_MULTICAST_IF,
1365 reinterpret_cast<
const char *>(&header.ifindex),
sizeof(header.ifindex)) == -1) {
1366 setError(QAbstractSocket::NetworkError, SendDatagramErrorString);
1369 mustSetIpv6MulticastIf =
true;
1373 if (header.hopLimit != -1) {
1374 msg.Control.len += WSA_CMSG_SPACE(
sizeof(
int));
1375 cmsgptr->cmsg_len = WSA_CMSG_LEN(
sizeof(
int));
1376 cmsgptr->cmsg_level = IPPROTO_IP;
1377 cmsgptr->cmsg_type = IP_TTL;
1378 memcpy(WSA_CMSG_DATA(cmsgptr), &header.hopLimit,
sizeof(
int));
1379 cmsgptr =
reinterpret_cast<WSACMSGHDR *>(
reinterpret_cast<
char *>(cmsgptr)
1380 + WSA_CMSG_SPACE(
sizeof(
int)));
1382 if (header.ifindex != 0 || !header.senderAddress.isNull()) {
1383 struct in_pktinfo *data =
reinterpret_cast<in_pktinfo *>(WSA_CMSG_DATA(cmsgptr));
1384 memset(data, 0,
sizeof(*data));
1385 msg.Control.len += WSA_CMSG_SPACE(
sizeof(*data));
1386 cmsgptr->cmsg_len = WSA_CMSG_LEN(
sizeof(*data));
1387 cmsgptr->cmsg_level = IPPROTO_IP;
1388 cmsgptr->cmsg_type = IP_PKTINFO;
1389 data->ipi_ifindex = header.ifindex;
1390 WSAHtonl(socketDescriptor, header.senderAddress.toIPv4Address(), &data->ipi_addr.s_addr);
1391 cmsgptr =
reinterpret_cast<WSACMSGHDR *>(
reinterpret_cast<
char *>(cmsgptr)
1392 + WSA_CMSG_SPACE(
sizeof(*data)));
1396 if (msg.Control.len != 0)
1397 msg.Control.buf = cbuf;
1400 DWORD bytesSent = 0;
1403 ret = sendmsg(socketDescriptor, &msg, flags, &bytesSent, 0,0);
1405 ret = ::WSASendTo(socketDescriptor, &buf, 1, &bytesSent, flags, msg.name, msg.namelen, 0,0);
1407 if (ret == SOCKET_ERROR) {
1408 int err = WSAGetLastError();
1412 setError(QAbstractSocket::DatagramTooLargeError, DatagramTooLargeErrorString);
1415 setError(QAbstractSocket::NetworkError, SendDatagramErrorString);
1420 ret = qint64(bytesSent);
1423 if (mustSetIpv6MulticastIf) {
1425 ::setsockopt(socketDescriptor, IPPROTO_IPV6, IPV6_MULTICAST_IF,
1426 reinterpret_cast<
char *>(&oldIfIndex),
sizeof(oldIfIndex));
1429#if defined (QNATIVESOCKETENGINE_DEBUG)
1430 qDebug(
"QNativeSocketEnginePrivate::nativeSendDatagram(%p \"%s\", %lli, \"%s\", %i) == %lli",
1431 data, QtDebugUtils::toPrintable(data, len, 16).constData(), len,
1432 header.destinationAddress.toString().toLatin1().constData(),
1433 header.destinationPort, ret);
1442 Q_Q(QNativeSocketEngine);
1444 qint64 bytesToSend = len;
1448 buf.buf =
const_cast<
char*>(data) + ret;
1449 buf.len = bytesToSend;
1451 DWORD bytesWritten = 0;
1453 int socketRet = ::WSASend(socketDescriptor, &buf, 1, &bytesWritten, flags, 0,0);
1455 ret += qint64(bytesWritten);
1458 if (socketRet != SOCKET_ERROR) {
1459 if (ret == len || bytesToSend != qint64(bytesWritten))
1461 }
else if ((err = WSAGetLastError()) == WSAEWOULDBLOCK) {
1463 }
else if (err == WSAENOBUFS) {
1473 case WSAECONNABORTED:
1475 setError(QAbstractSocket::NetworkError, WriteErrorString);
1485 bytesToSend = qMin<qint64>(49152, len - ret);
1488#if defined (QNATIVESOCKETENGINE_DEBUG)
1489 qDebug(
"QNativeSocketEnginePrivate::nativeWrite(%p \"%s\", %lli) == %lli",
1490 data, QtDebugUtils::toPrintable(data, ret, 16).constData(), len, ret);
1501 buf.len = maxLength;
1503 DWORD bytesRead = 0;
1504 if (::WSARecv(socketDescriptor, &buf, 1, &bytesRead, &flags, 0,0) == SOCKET_ERROR) {
1505 int err = WSAGetLastError();
1508 case WSAEWOULDBLOCK:
1516 case WSAECONNABORTED:
1524 if (WSAGetLastError() == WSAEWOULDBLOCK)
1527 ret = qint64(bytesRead);
1530#if defined (QNATIVESOCKETENGINE_DEBUG)
1532 qDebug(
"QNativeSocketEnginePrivate::nativeRead(%p \"%s\", %lli) == %lli", data,
1533 QtDebugUtils::toPrintable(data, bytesRead, 16).constData(), maxLength, ret);
1535 qDebug(
"QNativeSocketEnginePrivate::nativeRead(%p, %lli) == -2 (WOULD BLOCK)",
1545 using namespace std::chrono;
1546 const auto secs = duration_cast<seconds>(dur);
1547 const auto frac = duration_cast<microseconds>(dur - secs);
1548 struct timeval tval;
1549 tval.tv_sec = secs.count();
1550 tval.tv_usec = frac.count();
1564 memset(&fds, 0,
sizeof(fd_set));
1566 fds.fd_array[0] = (SOCKET)socketDescriptor;
1568 struct timeval tv = durationToTimeval(deadline.remainingTimeAsDuration());
1570 if (selectForRead) {
1571 ret = select(0, &fds, 0, 0, &tv);
1577 FD_ZERO(&fdexception);
1578 FD_SET((SOCKET)socketDescriptor, &fdexception);
1580 ret = select(0, 0, &fds, &fdexception, &tv);
1583 if (ret > 0 && FD_ISSET((SOCKET)socketDescriptor, &fdexception))
1594 bool checkRead,
bool checkWrite,
1595 bool *selectForRead,
bool *selectForWrite)
const
1607 memset(&fdread, 0,
sizeof(fd_set));
1609 fdread.fd_count = 1;
1610 fdread.fd_array[0] = (SOCKET)socketDescriptor;
1612 memset(&fdwrite, 0,
sizeof(fd_set));
1613 FD_ZERO(&fdexception);
1615 fdwrite.fd_count = 1;
1616 fdwrite.fd_array[0] = (SOCKET)socketDescriptor;
1619 FD_SET((SOCKET)socketDescriptor, &fdexception);
1622 struct timeval tv = durationToTimeval(deadline.remainingTimeAsDuration());
1624 ret = select(socketDescriptor + 1, &fdread, &fdwrite, &fdexception, &tv);
1627 if (ret > 0 && FD_ISSET((SOCKET)socketDescriptor, &fdexception))
1636 *selectForRead = FD_ISSET((SOCKET)socketDescriptor, &fdread);
1637 *selectForWrite = FD_ISSET((SOCKET)socketDescriptor, &fdwrite);
1644#if defined (QTCPSOCKETENGINE_DEBUG)
1645 qDebug(
"QNativeSocketEnginePrivate::nativeClose()");
1651 ::closesocket(socketDescriptor);
bool nativeHasPendingDatagrams() const
bool createNewSocket(QAbstractSocket::SocketType type, QAbstractSocket::NetworkLayerProtocol &protocol)
QNetworkInterface nativeMulticastInterface() const
qint64 nativeBytesAvailable() const
QSocketNotifier * readNotifier
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)
bool nativeSetMulticastInterface(const QNetworkInterface &iface)
bool fetchConnectionParameters()
Fetches information about both ends of the connection: whatever is available.
bool nativeBind(const QHostAddress &address, quint16 port)
qint64 nativePendingDatagramSize() const
bool nativeListen(int backlog)
qint64 nativeSendDatagram(const char *data, qint64 length, const QIpPacketHeader &header)
bool nativeConnect(const QHostAddress &address, quint16 port)
bool nativeLeaveMulticastGroup(const QHostAddress &groupAddress, const QNetworkInterface &iface)
qint64 nativeRead(char *data, qint64 maxLength)
qint64 nativeReceiveDatagram(char *data, qint64 maxLength, QIpPacketHeader *header, QAbstractSocketEngine::PacketHeaderOptions options)
@ NetworkUnreachableErrorString
@ HostUnreachableErrorString
@ OperationUnsupportedErrorString
@ AddressNotAvailableErrorString
@ InvalidSocketErrorString
@ ConnectionTimeOutErrorString
@ ConnectionRefusedErrorString
@ AddressInuseErrorString
@ ProtocolUnsupportedErrorString
Combined button and popup list for selecting options.
#define SO_EXCLUSIVEADDRUSE
static void qt_socket_getPortAndAddress(SOCKET socketDescriptor, const qt_sockaddr *sa, quint16 *port, QHostAddress *address)
static void convertToLevelAndOption(QNativeSocketEngine::SocketOption opt, QAbstractSocket::NetworkLayerProtocol socketProtocol, int &level, int &n)
static bool multicastMembershipHelper(QNativeSocketEnginePrivate *d, int how6, int how4, const QHostAddress &groupAddress, const QNetworkInterface &iface)
#define SIO_UDP_CONNRESET
static void setErrorFromWSAError(int error, QNativeSocketEnginePrivate *d)
#define WSA_FLAG_NO_HANDLE_INHERIT
timeval durationToTimeval(std::chrono::nanoseconds dur) noexcept
#define WS_ERROR_DEBUG(x)
static QAbstractSocket::SocketType qt_socket_getType(qintptr socketDescriptor)