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) );
706 int connectResult = ::WSAConnect(socketDescriptor, &aa.a, sockAddrSize,
nullptr,
nullptr,
708 int socketError = WSAGetLastError();
709 if (connectResult == SOCKET_ERROR) {
712 switch (socketError) {
713 case WSANOTINITIALISED:
716 case WSAEWOULDBLOCK: {
717 socketError = WSAEINPROGRESS;
724 if (socketState != QAbstractSocket::ConnectedState) {
725#if defined (QNATIVESOCKETENGINE_DEBUG)
726 qDebug(
"QNativeSocketEnginePrivate::nativeConnect(%s, %i) == false (%s)",
727 address.toString().toLatin1().constData(), port,
728 socketState == QAbstractSocket::ConnectingState
729 ?
"Connection in progress" : socketErrorString.toLatin1().constData());
735#if defined (QNATIVESOCKETENGINE_DEBUG)
736 qDebug(
"QNativeSocketEnginePrivate::nativeConnect(%s, %i) == true",
737 address.toString().toLatin1().constData(), port);
740 socketState = QAbstractSocket::ConnectedState;
747 QT_SOCKLEN_T optlen =
sizeof(value);
748 char *optval =
reinterpret_cast<
char *>(&value);
749 if (::getsockopt(socketDescriptor, SOL_SOCKET, SO_ERROR, optval, &optlen) != 0)
752 if (value == NO_ERROR) {
753 socketState = QAbstractSocket::ConnectedState;
758 if (socketState == QAbstractSocket::ConnectingState
759 && value != WSAEWOULDBLOCK
760 && value != WSAEINPROGRESS
761 && value != WSAEALREADY) {
762 socketState = QAbstractSocket::UnconnectedState;
765 return socketState != QAbstractSocket::ConnectingState;
771 QHostAddress address = a;
772 if (address.protocol() == QAbstractSocket::IPv4Protocol) {
773 if ((address.toIPv4Address() & 0xffff0000) == 0xefff0000) {
775 address = QHostAddress(QHostAddress::AnyIPv4);
780 QT_SOCKLEN_T sockAddrSize = 0;
781 setPortAndAddress(port, address, &aa, &sockAddrSize);
786 if (address.protocol() == QAbstractSocket::IPv6Protocol)
788 ::setsockopt(socketDescriptor, IPPROTO_IPV6,
IPV6_V6ONLY, (
char*)&ipv6only,
sizeof(ipv6only) );
792 int bindResult = ::bind(socketDescriptor, &aa.a, sockAddrSize);
793 if (bindResult == SOCKET_ERROR && WSAGetLastError() == WSAEAFNOSUPPORT
794 && address.protocol() == QAbstractSocket::AnyIPProtocol) {
796 aa.a4.sin_family = AF_INET;
797 aa.a4.sin_port = htons(port);
798 aa.a4.sin_addr.s_addr = htonl(address.toIPv4Address());
799 sockAddrSize =
sizeof(aa.a4);
800 bindResult = ::bind(socketDescriptor, &aa.a, sockAddrSize);
802 if (bindResult == SOCKET_ERROR) {
803 int err = WSAGetLastError();
806 case WSANOTINITIALISED:
811 setError(QAbstractSocket::AddressInUseError, AddressInuseErrorString);
814 setError(QAbstractSocket::SocketAccessError, AddressProtectedErrorString);
816 case WSAEADDRNOTAVAIL:
817 setError(QAbstractSocket::SocketAddressNotAvailableError, AddressNotAvailableErrorString);
823#if defined (QNATIVESOCKETENGINE_DEBUG)
824 qDebug(
"QNativeSocketEnginePrivate::nativeBind(%s, %i) == false (%s)",
825 address.toString().toLatin1().constData(), port, socketErrorString.toLatin1().constData());
831#if defined (QNATIVESOCKETENGINE_DEBUG)
832 qDebug(
"QNativeSocketEnginePrivate::nativeBind(%s, %i) == true",
833 address.toString().toLatin1().constData(), port);
835 socketState = QAbstractSocket::BoundState;
842 if (::listen(socketDescriptor, backlog) == SOCKET_ERROR) {
843 int err = WSAGetLastError();
846 case WSANOTINITIALISED:
850 setError(QAbstractSocket::AddressInUseError,
851 PortInuseErrorString);
857#if defined (QNATIVESOCKETENGINE_DEBUG)
858 qDebug(
"QNativeSocketEnginePrivate::nativeListen(%i) == false (%s)",
859 backlog, socketErrorString.toLatin1().constData());
864#if defined (QNATIVESOCKETENGINE_DEBUG)
865 qDebug(
"QNativeSocketEnginePrivate::nativeListen(%i) == true", backlog);
868 socketState = QAbstractSocket::ListeningState;
874 SOCKET acceptedDescriptor = WSAAccept(socketDescriptor, 0,0,0,0);
875 if (acceptedDescriptor == INVALID_SOCKET) {
876 int err = WSAGetLastError();
879 setError(QAbstractSocket::SocketAccessError, AccessErrorString);
881 case WSAECONNREFUSED:
882 setError(QAbstractSocket::ConnectionRefusedError, ConnectionRefusedErrorString);
885 setError(QAbstractSocket::NetworkError, RemoteHostClosedErrorString);
888 setError(QAbstractSocket::NetworkError, NetworkUnreachableErrorString);
891 setError(QAbstractSocket::SocketResourceError, NotSocketErrorString);
895 setError(QAbstractSocket::UnsupportedSocketOperationError, ProtocolUnsupportedErrorString);
900 setError(QAbstractSocket::SocketResourceError, ResourceErrorString);
903 setError(QAbstractSocket::TemporaryError, TemporaryErrorString);
906 setError(QAbstractSocket::UnknownSocketError, UnknownSocketErrorString);
909 }
else if (acceptedDescriptor != INVALID_SOCKET && QAbstractEventDispatcher::instance()) {
914 QSocketNotifier n(acceptedDescriptor, QSocketNotifier::Read);
918#if defined (QNATIVESOCKETENGINE_DEBUG)
919 qDebug(
"QNativeSocketEnginePrivate::nativeAccept() == %lld", qint64(acceptedDescriptor));
921 return qintptr(acceptedDescriptor);
927 const QHostAddress &groupAddress,
928 const QNetworkInterface &iface)
935 struct ip_mreq mreq4;
936 struct ipv6_mreq mreq6;
938 if (groupAddress.protocol() == QAbstractSocket::IPv6Protocol) {
939 level = IPPROTO_IPV6;
941 sockArg =
reinterpret_cast<
char *>(&mreq6);
942 sockArgSize =
sizeof(mreq6);
943 memset(&mreq6, 0,
sizeof(mreq6));
944 Q_IPV6ADDR ip6 = groupAddress.toIPv6Address();
945 memcpy(&mreq6.ipv6mr_multiaddr, &ip6,
sizeof(ip6));
946 mreq6.ipv6mr_interface = iface.index();
947 }
else if (groupAddress.protocol() == QAbstractSocket::IPv4Protocol) {
950 sockArg =
reinterpret_cast<
char *>(&mreq4);
951 sockArgSize =
sizeof(mreq4);
952 memset(&mreq4, 0,
sizeof(mreq4));
953 mreq4.imr_multiaddr.s_addr = htonl(groupAddress.toIPv4Address());
955 if (iface.isValid()) {
956 const QList<QNetworkAddressEntry> addressEntries = iface.addressEntries();
958 for (
const QNetworkAddressEntry &entry : addressEntries) {
959 const QHostAddress ip = entry.ip();
960 if (ip.protocol() == QAbstractSocket::IPv4Protocol) {
961 mreq4.imr_interface.s_addr = htonl(ip.toIPv4Address());
967 d->setError(QAbstractSocket::NetworkError,
972 mreq4.imr_interface.s_addr = INADDR_ANY;
976 d->setError(QAbstractSocket::UnsupportedSocketOperationError,
981 int res = setsockopt(d->socketDescriptor, level, sockOpt, sockArg, sockArgSize);
983 d->setError(QAbstractSocket::UnsupportedSocketOperationError,
991 const QNetworkInterface &iface)
993 return multicastMembershipHelper(
this,
1001 const QNetworkInterface &iface)
1003 return multicastMembershipHelper(
this,
1012 if (socketProtocol == QAbstractSocket::IPv6Protocol || socketProtocol == QAbstractSocket::AnyIPProtocol) {
1014 QT_SOCKOPTLEN_T sizeofv =
sizeof(v);
1015 if (::getsockopt(socketDescriptor, IPPROTO_IPV6, IPV6_MULTICAST_IF, (
char *) &v, &sizeofv) == -1)
1016 return QNetworkInterface();
1017 return QNetworkInterface::interfaceFromIndex(v);
1022 QT_SOCKOPTLEN_T sizeofv =
sizeof(v);
1023 if (::getsockopt(socketDescriptor, IPPROTO_IP, IP_MULTICAST_IF, (
char *) &v, &sizeofv) == -1)
1024 return QNetworkInterface();
1025 if (v.s_addr != 0 && sizeofv >= QT_SOCKOPTLEN_T(
sizeof(v))) {
1026 QHostAddress ipv4(ntohl(v.s_addr));
1027 QList<QNetworkInterface> ifaces = QNetworkInterface::allInterfaces();
1028 for (
int i = 0; i < ifaces.count(); ++i) {
1029 const QNetworkInterface &iface = ifaces.at(i);
1030 if (!(iface.flags() & QNetworkInterface::CanMulticast))
1032 QList<QNetworkAddressEntry> entries = iface.addressEntries();
1033 for (
int j = 0; j < entries.count(); ++j) {
1034 const QNetworkAddressEntry &entry = entries.at(j);
1035 if (entry.ip() == ipv4)
1040 return QNetworkInterface();
1046 if (socketProtocol == QAbstractSocket::IPv6Protocol || socketProtocol == QAbstractSocket::AnyIPProtocol) {
1047 uint v = iface.isValid() ? iface.index() : 0;
1048 return (::setsockopt(socketDescriptor, IPPROTO_IPV6, IPV6_MULTICAST_IF, (
char *) &v,
sizeof(v)) != -1);
1052 if (iface.isValid()) {
1053 QList<QNetworkAddressEntry> entries = iface.addressEntries();
1054 for (
int i = 0; i < entries.count(); ++i) {
1055 const QNetworkAddressEntry &entry = entries.at(i);
1056 const QHostAddress &ip = entry.ip();
1057 if (ip.protocol() == QAbstractSocket::IPv4Protocol) {
1058 v.s_addr = htonl(ip.toIPv4Address());
1059 int r = ::setsockopt(socketDescriptor, IPPROTO_IP, IP_MULTICAST_IF, (
char *) &v,
sizeof(v));
1067 v.s_addr = INADDR_ANY;
1068 return (::setsockopt(socketDescriptor, IPPROTO_IP, IP_MULTICAST_IF, (
char *) &v,
sizeof(v)) != -1);
1073 unsigned long nbytes = 0;
1074 unsigned long dummy = 0;
1075 DWORD sizeWritten = 0;
1076 if (::WSAIoctl(socketDescriptor, FIONREAD, &dummy,
sizeof(dummy), &nbytes,
sizeof(nbytes), &sizeWritten, 0,0) == SOCKET_ERROR) {
1086 if (nbytes == 1 && socketType == QAbstractSocket::UdpSocket) {
1090 buf.len =
sizeof(c);
1091 DWORD bytesReceived;
1092 DWORD flags = MSG_PEEK;
1093 if (::WSARecvFrom(socketDescriptor, &buf, 1, &bytesReceived, &flags, 0,0,0,0) == SOCKET_ERROR) {
1094 int err = WSAGetLastError();
1095 if (err != WSAECONNRESET && err != WSAENETRESET)
1098 return bytesReceived;
1108 qt_sockaddr storage;
1109 QT_SOCKLEN_T storageSize =
sizeof(storage);
1110 memset(&storage, 0, storageSize);
1112 bool result =
false;
1119 buf.len =
sizeof(c);
1120 DWORD available = 0;
1121 DWORD flags = MSG_PEEK;
1122 int ret = ::WSARecvFrom(socketDescriptor, &buf, 1, &available, &flags, &storage.a, &storageSize,0,0);
1123 int err = WSAGetLastError();
1124 if (ret == SOCKET_ERROR && err != WSAEMSGSIZE) {
1126 result = (err == WSAECONNRESET || err == WSAENETRESET);
1133#if defined (QNATIVESOCKETENGINE_DEBUG)
1134 qDebug(
"QNativeSocketEnginePrivate::nativeHasPendingDatagrams() == %s",
1135 result ?
"true" :
"false");
1148 char udpMessagePeekBuffer[2048];
1149 const int increments = 5;
1150 QVarLengthArray<WSABUF, 10> buf;
1152 buf.reserve(buf.size() + increments);
1153 std::fill_n(std::back_inserter(buf), increments, WSABUF{
sizeof(udpMessagePeekBuffer), udpMessagePeekBuffer});
1156 DWORD bytesRead = 0;
1157 recvResult = ::WSARecv(socketDescriptor, buf.data(), DWORD(buf.size()), &bytesRead, &flags,
nullptr,
nullptr);
1158 int err = WSAGetLastError();
1159 if (recvResult != SOCKET_ERROR) {
1160 ret = qint64(bytesRead);
1179#if defined (QNATIVESOCKETENGINE_DEBUG)
1180 qDebug(
"QNativeSocketEnginePrivate::nativePendingDatagramSize() == %lli", ret);
1187 QAbstractSocketEngine::PacketHeaderOptions options)
1190 char cbuf[WSA_CMSG_SPACE(
sizeof(
struct in6_pktinfo)) + WSA_CMSG_SPACE(
sizeof(
int))];
1197 memset(&msg, 0,
sizeof(msg));
1198 memset(&aa, 0,
sizeof(aa));
1201 buf.buf = maxLength ? data : &c;
1202 buf.len = maxLength ? maxLength : 1;
1203 msg.lpBuffers = &buf;
1204 msg.dwBufferCount = 1;
1205 msg.name =
reinterpret_cast<LPSOCKADDR>(&aa);
1206 msg.namelen =
sizeof(aa);
1207 msg.Control.buf = cbuf;
1208 msg.Control.len =
sizeof(cbuf);
1211 DWORD bytesRead = 0;
1215 ret = recvmsg(socketDescriptor, &msg, &bytesRead, 0,0);
1217 ret = ::WSARecvFrom(socketDescriptor, &buf, 1, &bytesRead, &flags, msg.name, &msg.namelen,0,0);
1218 if (ret == SOCKET_ERROR) {
1219 int err = WSAGetLastError();
1220 if (err == WSAEMSGSIZE) {
1223 ret = qint64(bytesRead) > maxLength ? maxLength : qint64(bytesRead);
1224 if (options & QNativeSocketEngine::WantDatagramSender)
1225 qt_socket_getPortAndAddress(socketDescriptor, &aa, &header->senderPort, &header->senderAddress);
1230 setError(QAbstractSocket::NetworkError, NetworkDroppedConnectionErrorString);
1233 setError(QAbstractSocket::ConnectionRefusedError, ConnectionResetErrorString);
1236 setError(QAbstractSocket::NetworkError, ReceiveDatagramErrorString);
1244 ret = qint64(bytesRead);
1245 if (options & QNativeSocketEngine::WantDatagramSender)
1246 qt_socket_getPortAndAddress(socketDescriptor, &aa, &header->senderPort, &header->senderAddress);
1249 if (ret != -1 && recvmsg && options != QAbstractSocketEngine::WantNone) {
1251 header->destinationPort = localPort;
1252 WSACMSGHDR *cmsgptr;
1253 for (cmsgptr = WSA_CMSG_FIRSTHDR(&msg); cmsgptr != NULL;
1254 cmsgptr = WSA_CMSG_NXTHDR(&msg, cmsgptr)) {
1255 if (cmsgptr->cmsg_level == IPPROTO_IPV6 && cmsgptr->cmsg_type == IPV6_PKTINFO
1256 && cmsgptr->cmsg_len >= WSA_CMSG_LEN(
sizeof(in6_pktinfo))) {
1257 in6_pktinfo *info =
reinterpret_cast<in6_pktinfo *>(WSA_CMSG_DATA(cmsgptr));
1259 header->destinationAddress.setAddress(
reinterpret_cast<quint8 *>(&info->ipi6_addr));
1260 header->ifindex = info->ipi6_ifindex;
1261 if (header->ifindex)
1262 header->destinationAddress.setScopeId(QString::number(info->ipi6_ifindex));
1264 if (cmsgptr->cmsg_level == IPPROTO_IP && cmsgptr->cmsg_type == IP_PKTINFO
1265 && cmsgptr->cmsg_len >= WSA_CMSG_LEN(
sizeof(in_pktinfo))) {
1266 in_pktinfo *info =
reinterpret_cast<in_pktinfo *>(WSA_CMSG_DATA(cmsgptr));
1268 WSANtohl(socketDescriptor, info->ipi_addr.s_addr, &addr);
1269 header->destinationAddress.setAddress(addr);
1270 header->ifindex = info->ipi_ifindex;
1273 if (cmsgptr->cmsg_len == WSA_CMSG_LEN(
sizeof(
int))
1274 && ((cmsgptr->cmsg_level == IPPROTO_IPV6 && cmsgptr->cmsg_type == IPV6_HOPLIMIT)
1275 || (cmsgptr->cmsg_level == IPPROTO_IP && cmsgptr->cmsg_type == IP_TTL))) {
1276 header->hopLimit = *
reinterpret_cast<
int *>(WSA_CMSG_DATA(cmsgptr));
1281#if defined (QNATIVESOCKETENGINE_DEBUG)
1282 bool printSender = (ret != -1 && (options & QNativeSocketEngine::WantDatagramSender) != 0);
1283 qDebug(
"QNativeSocketEnginePrivate::nativeReceiveDatagram(%p \"%s\", %lli, %s, %i) == %lli",
1284 data, QtDebugUtils::toPrintable(data, ret, 16).constData(), maxLength,
1285 printSender ? header->senderAddress.toString().toLatin1().constData() :
"(unknown)",
1286 printSender ? header->senderPort : 0, ret);
1294 const QIpPacketHeader &header)
1297 char cbuf[WSA_CMSG_SPACE(
sizeof(
struct in6_pktinfo)) + WSA_CMSG_SPACE(
sizeof(
int))];
1300 WSACMSGHDR *cmsgptr = &align;
1305 memset(&msg, 0,
sizeof(msg));
1306 memset(&aa, 0,
sizeof(aa));
1307 buf.buf = len ? (
char*)data : 0;
1308 msg.lpBuffers = &buf;
1309 msg.dwBufferCount = 1;
1313 setPortAndAddress(header.destinationPort, header.destinationAddress, &aa, &msg.namelen);
1315 uint oldIfIndex = 0;
1316 bool mustSetIpv6MulticastIf =
false;
1318 if (msg.namelen ==
sizeof(aa.a6)) {
1320 if (header.hopLimit != -1) {
1321 msg.Control.len += WSA_CMSG_SPACE(
sizeof(
int));
1322 cmsgptr->cmsg_len = WSA_CMSG_LEN(
sizeof(
int));
1323 cmsgptr->cmsg_level = IPPROTO_IPV6;
1324 cmsgptr->cmsg_type = IPV6_HOPLIMIT;
1325 memcpy(WSA_CMSG_DATA(cmsgptr), &header.hopLimit,
sizeof(
int));
1326 cmsgptr =
reinterpret_cast<WSACMSGHDR *>(
reinterpret_cast<
char *>(cmsgptr)
1327 + WSA_CMSG_SPACE(
sizeof(
int)));
1329 if (!header.senderAddress.isNull()) {
1330 struct in6_pktinfo *data =
reinterpret_cast<in6_pktinfo *>(WSA_CMSG_DATA(cmsgptr));
1331 memset(data, 0,
sizeof(*data));
1332 msg.Control.len += WSA_CMSG_SPACE(
sizeof(*data));
1333 cmsgptr->cmsg_len = WSA_CMSG_LEN(
sizeof(*data));
1334 cmsgptr->cmsg_level = IPPROTO_IPV6;
1335 cmsgptr->cmsg_type = IPV6_PKTINFO;
1336 data->ipi6_ifindex = header.ifindex;
1338 Q_IPV6ADDR tmp = header.senderAddress.toIPv6Address();
1339 memcpy(&data->ipi6_addr, &tmp,
sizeof(tmp));
1340 cmsgptr =
reinterpret_cast<WSACMSGHDR *>(
reinterpret_cast<
char *>(cmsgptr)
1341 + WSA_CMSG_SPACE(
sizeof(*data)));
1342 }
else if (header.ifindex != 0) {
1348 QT_SOCKOPTLEN_T len =
sizeof(oldIfIndex);
1349 if (::getsockopt(socketDescriptor, IPPROTO_IPV6, IPV6_MULTICAST_IF,
1350 reinterpret_cast<
char *>(&oldIfIndex), &len) == -1
1351 || ::setsockopt(socketDescriptor, IPPROTO_IPV6, IPV6_MULTICAST_IF,
1352 reinterpret_cast<
const char *>(&header.ifindex),
sizeof(header.ifindex)) == -1) {
1353 setError(QAbstractSocket::NetworkError, SendDatagramErrorString);
1356 mustSetIpv6MulticastIf =
true;
1360 if (header.hopLimit != -1) {
1361 msg.Control.len += WSA_CMSG_SPACE(
sizeof(
int));
1362 cmsgptr->cmsg_len = WSA_CMSG_LEN(
sizeof(
int));
1363 cmsgptr->cmsg_level = IPPROTO_IP;
1364 cmsgptr->cmsg_type = IP_TTL;
1365 memcpy(WSA_CMSG_DATA(cmsgptr), &header.hopLimit,
sizeof(
int));
1366 cmsgptr =
reinterpret_cast<WSACMSGHDR *>(
reinterpret_cast<
char *>(cmsgptr)
1367 + WSA_CMSG_SPACE(
sizeof(
int)));
1369 if (header.ifindex != 0 || !header.senderAddress.isNull()) {
1370 struct in_pktinfo *data =
reinterpret_cast<in_pktinfo *>(WSA_CMSG_DATA(cmsgptr));
1371 memset(data, 0,
sizeof(*data));
1372 msg.Control.len += WSA_CMSG_SPACE(
sizeof(*data));
1373 cmsgptr->cmsg_len = WSA_CMSG_LEN(
sizeof(*data));
1374 cmsgptr->cmsg_level = IPPROTO_IP;
1375 cmsgptr->cmsg_type = IP_PKTINFO;
1376 data->ipi_ifindex = header.ifindex;
1377 WSAHtonl(socketDescriptor, header.senderAddress.toIPv4Address(), &data->ipi_addr.s_addr);
1378 cmsgptr =
reinterpret_cast<WSACMSGHDR *>(
reinterpret_cast<
char *>(cmsgptr)
1379 + WSA_CMSG_SPACE(
sizeof(*data)));
1383 if (msg.Control.len != 0)
1384 msg.Control.buf = cbuf;
1387 DWORD bytesSent = 0;
1390 ret = sendmsg(socketDescriptor, &msg, flags, &bytesSent, 0,0);
1392 ret = ::WSASendTo(socketDescriptor, &buf, 1, &bytesSent, flags, msg.name, msg.namelen, 0,0);
1394 if (ret == SOCKET_ERROR) {
1395 int err = WSAGetLastError();
1399 setError(QAbstractSocket::DatagramTooLargeError, DatagramTooLargeErrorString);
1402 setError(QAbstractSocket::NetworkError, SendDatagramErrorString);
1407 ret = qint64(bytesSent);
1410 if (mustSetIpv6MulticastIf) {
1412 ::setsockopt(socketDescriptor, IPPROTO_IPV6, IPV6_MULTICAST_IF,
1413 reinterpret_cast<
char *>(&oldIfIndex),
sizeof(oldIfIndex));
1416#if defined (QNATIVESOCKETENGINE_DEBUG)
1417 qDebug(
"QNativeSocketEnginePrivate::nativeSendDatagram(%p \"%s\", %lli, \"%s\", %i) == %lli",
1418 data, QtDebugUtils::toPrintable(data, len, 16).constData(), len,
1419 header.destinationAddress.toString().toLatin1().constData(),
1420 header.destinationPort, ret);
1429 Q_Q(QNativeSocketEngine);
1431 qint64 bytesToSend = len;
1435 buf.buf =
const_cast<
char*>(data) + ret;
1436 buf.len = bytesToSend;
1438 DWORD bytesWritten = 0;
1440 int socketRet = ::WSASend(socketDescriptor, &buf, 1, &bytesWritten, flags, 0,0);
1442 ret += qint64(bytesWritten);
1445 if (socketRet != SOCKET_ERROR) {
1446 if (ret == len || bytesToSend != qint64(bytesWritten))
1448 }
else if ((err = WSAGetLastError()) == WSAEWOULDBLOCK) {
1450 }
else if (err == WSAENOBUFS) {
1460 case WSAECONNABORTED:
1462 setError(QAbstractSocket::NetworkError, WriteErrorString);
1472 bytesToSend = qMin<qint64>(49152, len - ret);
1475#if defined (QNATIVESOCKETENGINE_DEBUG)
1476 qDebug(
"QNativeSocketEnginePrivate::nativeWrite(%p \"%s\", %lli) == %lli",
1477 data, QtDebugUtils::toPrintable(data, ret, 16).constData(), len, ret);
1488 buf.len = maxLength;
1490 DWORD bytesRead = 0;
1491 if (::WSARecv(socketDescriptor, &buf, 1, &bytesRead, &flags, 0,0) == SOCKET_ERROR) {
1492 int err = WSAGetLastError();
1495 case WSAEWOULDBLOCK:
1503 case WSAECONNABORTED:
1511 if (WSAGetLastError() == WSAEWOULDBLOCK)
1514 ret = qint64(bytesRead);
1517#if defined (QNATIVESOCKETENGINE_DEBUG)
1519 qDebug(
"QNativeSocketEnginePrivate::nativeRead(%p \"%s\", %lli) == %lli", data,
1520 QtDebugUtils::toPrintable(data, bytesRead, 16).constData(), maxLength, ret);
1522 qDebug(
"QNativeSocketEnginePrivate::nativeRead(%p, %lli) == -2 (WOULD BLOCK)",
1532 using namespace std::chrono;
1533 const auto secs = duration_cast<seconds>(dur);
1534 const auto frac = duration_cast<microseconds>(dur - secs);
1535 struct timeval tval;
1536 tval.tv_sec = secs.count();
1537 tval.tv_usec = frac.count();
1551 memset(&fds, 0,
sizeof(fd_set));
1553 fds.fd_array[0] = (SOCKET)socketDescriptor;
1555 struct timeval tv = durationToTimeval(deadline.remainingTimeAsDuration());
1557 if (selectForRead) {
1558 ret = select(0, &fds, 0, 0, &tv);
1564 FD_ZERO(&fdexception);
1565 FD_SET((SOCKET)socketDescriptor, &fdexception);
1567 ret = select(0, 0, &fds, &fdexception, &tv);
1570 if (ret > 0 && FD_ISSET((SOCKET)socketDescriptor, &fdexception))
1581 bool checkRead,
bool checkWrite,
1582 bool *selectForRead,
bool *selectForWrite)
const
1594 memset(&fdread, 0,
sizeof(fd_set));
1596 fdread.fd_count = 1;
1597 fdread.fd_array[0] = (SOCKET)socketDescriptor;
1599 memset(&fdwrite, 0,
sizeof(fd_set));
1600 FD_ZERO(&fdexception);
1602 fdwrite.fd_count = 1;
1603 fdwrite.fd_array[0] = (SOCKET)socketDescriptor;
1606 FD_SET((SOCKET)socketDescriptor, &fdexception);
1609 struct timeval tv = durationToTimeval(deadline.remainingTimeAsDuration());
1611 ret = select(socketDescriptor + 1, &fdread, &fdwrite, &fdexception, &tv);
1614 if (ret > 0 && FD_ISSET((SOCKET)socketDescriptor, &fdexception))
1623 *selectForRead = FD_ISSET((SOCKET)socketDescriptor, &fdread);
1624 *selectForWrite = FD_ISSET((SOCKET)socketDescriptor, &fdwrite);
1631#if defined (QTCPSOCKETENGINE_DEBUG)
1632 qDebug(
"QNativeSocketEnginePrivate::nativeClose()");
1638 ::closesocket(socketDescriptor);
bool nativeHasPendingDatagrams() const
bool createNewSocket(QAbstractSocket::SocketType type, QAbstractSocket::NetworkLayerProtocol &protocol)
QNetworkInterface nativeMulticastInterface() const
bool nativeCheckConnection()
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)