1,3c1,39
< // Copyright (C) 2021 The Qt Company Ltd.
< // Copyright (C) 2016 Intel Corporation.
< // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
---
> /****************************************************************************
> **
> ** Copyright (C) 2021 The Qt Company Ltd.
> ** Copyright (C) 2016 Intel Corporation.
> ** Contact: https://www.qt.io/licensing/
> **
> ** This file is part of the QtNetwork module of the Qt Toolkit.
> **
> ** $QT_BEGIN_LICENSE:COMM$
> **
> ** Commercial License Usage
> ** Licensees holding valid commercial Qt licenses may use this file in
> ** accordance with the commercial license agreement provided with the
> ** Software or, alternatively, in accordance with the terms contained in
> ** a written agreement between you and The Qt Company. For licensing terms
> ** and conditions see https://www.qt.io/terms-conditions. For further
> ** information use the contact form at https://www.qt.io/contact-us.
> **
> ** $QT_END_LICENSE$
> **
> **
> **
> **
> **
> **
> **
> **
> **
> **
> **
> **
> **
> **
> **
> **
> **
> **
> **
> ****************************************************************************/
6c42
< #include "qnativesocketengine_p_p.h"
---
> #include "qnativesocketengine_p.h"
8d43
< #include "qdeadlinetimer.h"
10a46
> #include "qelapsedtimer.h"
14,16d49
< #ifdef Q_OS_WASM
< #include <private/qeventdispatcher_wasm_p.h>
< #endif
19a53,67
> 
> #ifdef Q_OS_VXWORKS
> // VxWorks lacks if_indextoname
> # define QT_NO_IPV6IFNAME
> #endif
> 
> #ifndef QT_NO_IPV6IFNAME
> #include <net/if.h>
> #endif
> #ifdef QT_LINUXBASE
> #include <arpa/inet.h>
> #endif
> #ifdef Q_OS_BSD4
> #include <net/if_dl.h>
> #endif
25c73,74
< #include <private/qdebug_p.h>
---
> #include <qstring.h>
> #include <ctype.h>
34,36d82
< #ifdef Q_OS_BSD4
< #  include <net/if_dl.h>
< #endif
39a86,117
> #if defined QNATIVESOCKETENGINE_DEBUG
> 
> /*
>     Returns a human readable representation of the first \a len
>     characters in \a data.
> */
> static QByteArray qt_prettyDebug(const char *data, int len, int maxSize)
> {
>     if (!data) return "(null)";
>     QByteArray out;
>     for (int i = 0; i < len; ++i) {
>         char c = data[i];
>         if (isprint(c)) {
>             out += c;
>         } else switch (c) {
>         case '\n': out += "\\n"; break;
>         case '\r': out += "\\r"; break;
>         case '\t': out += "\\t"; break;
>         default:
>             QString tmp;
>             tmp.sprintf("\\%o", c);
>             out += tmp.toLatin1();
>         }
>     }
> 
>     if (len < maxSize)
>         out += "...";
> 
>     return out;
> }
> #endif
> 
202c280,285
<     if (socket < 0 && socketProtocol == QAbstractSocket::AnyIPProtocol && errno == EAFNOSUPPORT) {
---
>     if (socket < 0 && socketProtocol == QAbstractSocket::AnyIPProtocol && ( errno == EAFNOSUPPORT
> #if defined (Q_OS_VXWORKS)
>         || errno == ENOTSUP )) {
> #else
>         )) {
> #endif
244,245c327,330
<     this->socketProtocol = socketProtocol;
<     this->socketType = socketType;
---
>     if (socket != -1) {
>         this->socketProtocol = socketProtocol;
>         this->socketType = socketType;
>     }
318c403
< #if !defined(Q_OS_VXWORKS)
---
> #if !defined(Q_OS_VXWORKS_GNU)
380c465,466
<     return ::setsockopt(socketDescriptor, level, n, (char *) &v, sizeof(v)) == 0;
---
>     QT_SOCKOPTLEN_T len = sizeof(v);
>     return ::setsockopt(socketDescriptor, level, n, (char *) &v, len) == 0;
404d489
<         case ENOENT:
440d524
<             break;
482c566,572
<     if (bindResult < 0 && errno == EAFNOSUPPORT && address.protocol() == QAbstractSocket::AnyIPProtocol) {
---
>     if (bindResult < 0 && (errno == EAFNOSUPPORT
> #ifdef Q_OS_VXWORKS
>         || errno == EINVAL)
> #else
>         )
> #endif
>         && address.protocol() == QAbstractSocket::AnyIPProtocol) {
558c648
< qintptr QNativeSocketEnginePrivate::nativeAccept()
---
> int QNativeSocketEnginePrivate::nativeAccept()
604c694
<     return qintptr(acceptedDescriptor);
---
>     return acceptedDescriptor;
618c708
<     int sockArgSize;
---
>     QT_SOCKLEN_T sockArgSize;
717,719d806
< #if defined(Q_OS_SOLARIS)
<     struct in_addr v = { 0, 0, 0, 0};
< #else
721d807
< #endif
728c814
<         for (int i = 0; i < ifaces.size(); ++i) {
---
>         for (int i = 0; i < ifaces.count(); ++i) {
731c817
<             for (int j = 0; j < entries.size(); ++j) {
---
>             for (int j = 0; j < entries.count(); ++j) {
751c837
<         for (int i = 0; i < entries.size(); ++i) {
---
>         for (int i = 0; i < entries.count(); ++i) {
798c884
<     QT_EINTR_LOOP(readBytes, ::recv(socketDescriptor, &c, 1, MSG_PEEK));
---
>     EINTR_LOOP(readBytes, ::recv(socketDescriptor, &c, 1, MSG_PEEK));
813a900,903
> #ifdef Q_OS_VXWORKS
>     ssize_t prevRecvResult = -1;
> #endif
> 
817c907
<     QT_EINTR_LOOP(recvResult, ::recv(socketDescriptor, &c, 1, MSG_PEEK | MSG_TRUNC));
---
>     EINTR_LOOP(recvResult, ::recv(socketDescriptor, &c, 1, MSG_PEEK | MSG_TRUNC));
844a935,946
> #ifdef Q_OS_VXWORKS
>         // VxWorks does not know how many bytes there is available on socket
>         // until it fails to read those from buffer... So only way to know
>         // available amount of bytes available, is to read until it fails
>         // and EMSGSIZE error is returned.
>         if (recvResult != -1)
>             prevRecvResult = recvResult;
>         if (recvResult == -1 && (errno == EMSGSIZE || errno == EINTR)) {
>             recvResult = prevRecvResult;
>             break;
>         }
> #endif
980c1082
<                 static_assert(sizeof(header->hopLimit) == sizeof(int));
---
>                 Q_STATIC_ASSERT(sizeof(header->hopLimit) == sizeof(int));
997c1099
<            data, QtDebugUtils::toPrintable(data, recvResult, 16).constData(), maxSize,
---
>            data, qt_prettyDebug(data, qMin(recvResult, ssize_t(16)), recvResult).data(), maxSize,
1113a1216,1218
> #ifdef Q_OS_VXWORKS
>         case ENOMEM:
> #endif
1126c1231
<            QtDebugUtils::toPrintable(data, len, 16).constData(), len,
---
>            qt_prettyDebug(data, qMin<int>(len, 16), len).data(), len,
1280,1282d1384
< #if EWOULDBLOCK != EAGAIN
<         case EWOULDBLOCK:
< #endif
1295,1296c1397,1399
<     qDebug("QNativeSocketEnginePrivate::nativeWrite(%p \"%s\", %llu) == %i", data,
<            QtDebugUtils::toPrintable(data, len, 16).constData(), len, (int) writtenBytes);
---
>     qDebug("QNativeSocketEnginePrivate::nativeWrite(%p \"%s\", %llu) == %i",
>            data, qt_prettyDebug(data, qMin((int) len, 16),
>                                 (int) len).data(), len, (int) writtenBytes);
1345,1346c1448,1450
<     qDebug("QNativeSocketEnginePrivate::nativeRead(%p \"%s\", %llu) == %zd", data,
<            QtDebugUtils::toPrintable(data, r, 16).constData(), maxSize, r);
---
>     qDebug("QNativeSocketEnginePrivate::nativeRead(%p \"%s\", %llu) == %zd",
>            data, qt_prettyDebug(data, qMin(r, ssize_t(16)), r).data(),
>            maxSize, r);
1352c1456
< int QNativeSocketEnginePrivate::nativeSelect(QDeadlineTimer deadline, bool selectForRead) const
---
> int QNativeSocketEnginePrivate::nativeSelect(int timeout, bool selectForRead) const
1355c1459
<     return nativeSelect(deadline, selectForRead, !selectForRead, &dummy, &dummy);
---
>     return nativeSelect(timeout, selectForRead, !selectForRead, &dummy, &dummy);
1358,1362c1462,1463
< #ifndef Q_OS_WASM
< 
< int QNativeSocketEnginePrivate::nativeSelect(QDeadlineTimer deadline, bool checkRead,
<                                              bool checkWrite, bool *selectForRead,
<                                              bool *selectForWrite) const
---
> int QNativeSocketEnginePrivate::nativeSelect(int timeout, bool checkRead, bool checkWrite,
>                        bool *selectForRead, bool *selectForWrite) const
1372c1473
<     const int ret = qt_safe_poll(&pfd, 1, deadline);
---
>     const int ret = qt_poll_msecs(&pfd, 1, timeout);
1383c1484
<     static const short write_flags = POLLOUT | POLLHUP | POLLERR;
---
>     static const short write_flags = POLLOUT | POLLERR;
1390,1412d1490
< 
< #else
< 
< int QNativeSocketEnginePrivate::nativeSelect(QDeadlineTimer deadline, bool checkRead,
<                                              bool checkWrite, bool *selectForRead,
<                                              bool *selectForWrite) const
< {
<     *selectForRead = checkRead;
<     *selectForWrite = checkWrite;
<     bool socketDisconnect = false;
<     QEventDispatcherWasm::socketSelect(deadline.remainingTime(), socketDescriptor, checkRead,
<                                        checkWrite, selectForRead, selectForWrite,
<                                        &socketDisconnect);
< 
<     // The disconnect/close handling code in QAbstractsScket::canReadNotification()
<     // does not detect remote disconnect properly; do that here as a workardound.
<     if (socketDisconnect)
<         receiver->closeNotification();
< 
<     return 1;
< }
< 
< #endif // Q_OS_WASM
