Ignore:
Timestamp:
Feb 11, 2010, 11:19:06 PM (15 years ago)
Author:
Dmitry A. Kuminov
Message:

trunk: Merged in qt 4.6.1 sources.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/src/network/socket/qnativesocketengine.cpp

    r2 r561  
    22**
    33** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
    4 ** Contact: Qt Software Information (qt-info@nokia.com)
     4** All rights reserved.
     5** Contact: Nokia Corporation (qt-info@nokia.com)
    56**
    67** This file is part of the QtNetwork module of the Qt Toolkit.
     
    2122** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
    2223**
    23 ** In addition, as a special exception, Nokia gives you certain
    24 ** additional rights. These rights are described in the Nokia Qt LGPL
    25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
    26 ** package.
     24** In addition, as a special exception, Nokia gives you certain additional
     25** rights.  These rights are described in the Nokia Qt LGPL Exception
     26** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
    2727**
    2828** GNU General Public License Usage
     
    3434** met: http://www.gnu.org/copyleft/gpl.html.
    3535**
    36 ** If you are unsure which license is appropriate for your use, please
    37 ** contact the sales department at qt-sales@nokia.com.
     36** If you have questions regarding the use of this file, please contact
     37** Nokia at qt-info@nokia.com.
    3838** $QT_END_LICENSE$
    3939**
     
    4848
    4949    \reentrant
    50     \ingroup io
     50    \ingroup network
    5151    \inmodule QtNetwork
    5252
     
    195195    switch (errorString) {
    196196    case NonBlockingInitFailedErrorString:
    197         socketErrorString = QLatin1String(QT_TRANSLATE_NOOP("QNativeSocketEngine", "Unable to initialize non-blocking socket"));
     197        socketErrorString = QNativeSocketEngine::tr("Unable to initialize non-blocking socket");
    198198        break;
    199199    case BroadcastingInitFailedErrorString:
    200         socketErrorString = QLatin1String(QT_TRANSLATE_NOOP("QNativeSocketEngine", "Unable to initialize broadcast socket"));
     200        socketErrorString = QNativeSocketEngine::tr("Unable to initialize broadcast socket");
    201201        break;
    202202    case NoIpV6ErrorString:
    203         socketErrorString = QLatin1String(QT_TRANSLATE_NOOP("QNativeSocketEngine", "Attempt to use IPv6 socket on a platform with no IPv6 support"));
     203        socketErrorString = QNativeSocketEngine::tr("Attempt to use IPv6 socket on a platform with no IPv6 support");
    204204        break;
    205205    case RemoteHostClosedErrorString:
    206         socketErrorString = QLatin1String(QT_TRANSLATE_NOOP("QNativeSocketEngine", "The remote host closed the connection"));
     206        socketErrorString = QNativeSocketEngine::tr("The remote host closed the connection");
    207207        break;
    208208    case TimeOutErrorString:
    209         socketErrorString = QLatin1String(QT_TRANSLATE_NOOP("QNativeSocketEngine", "Network operation timed out"));
     209        socketErrorString = QNativeSocketEngine::tr("Network operation timed out");
    210210        break;
    211211    case ResourceErrorString:
    212         socketErrorString = QLatin1String(QT_TRANSLATE_NOOP("QNativeSocketEngine", "Out of resources"));
     212        socketErrorString = QNativeSocketEngine::tr("Out of resources");
    213213        break;
    214214    case OperationUnsupportedErrorString:
    215         socketErrorString = QLatin1String(QT_TRANSLATE_NOOP("QNativeSocketEngine", "Unsupported socket operation"));
     215        socketErrorString = QNativeSocketEngine::tr("Unsupported socket operation");
    216216        break;
    217217    case ProtocolUnsupportedErrorString:
    218         socketErrorString = QLatin1String(QT_TRANSLATE_NOOP("QNativeSocketEngine", "Protocol type not supported"));
     218        socketErrorString = QNativeSocketEngine::tr("Protocol type not supported");
    219219        break;
    220220    case InvalidSocketErrorString:
    221         socketErrorString = QLatin1String(QT_TRANSLATE_NOOP("QNativeSocketEngine", "Invalid socket descriptor"));
     221        socketErrorString = QNativeSocketEngine::tr("Invalid socket descriptor");
    222222        break;
    223223    case HostUnreachableErrorString:
    224         socketErrorString = QLatin1String(QT_TRANSLATE_NOOP("QNativeSocketEngine", "Host unreachable"));
     224        socketErrorString = QNativeSocketEngine::tr("Host unreachable");
    225225        break;
    226226    case NetworkUnreachableErrorString:
    227         socketErrorString = QLatin1String(QT_TRANSLATE_NOOP("QNativeSocketEngine", "Network unreachable"));
     227        socketErrorString = QNativeSocketEngine::tr("Network unreachable");
    228228        break;
    229229    case AccessErrorString:
    230         socketErrorString = QLatin1String(QT_TRANSLATE_NOOP("QNativeSocketEngine", "Permission denied"));
     230        socketErrorString = QNativeSocketEngine::tr("Permission denied");
    231231        break;
    232232    case ConnectionTimeOutErrorString:
    233         socketErrorString = QLatin1String(QT_TRANSLATE_NOOP("QNativeSocketEngine", "Connection timed out"));
     233        socketErrorString = QNativeSocketEngine::tr("Connection timed out");
    234234        break;
    235235    case ConnectionRefusedErrorString:
    236         socketErrorString = QLatin1String(QT_TRANSLATE_NOOP("QNativeSocketEngine", "Connection refused"));
     236        socketErrorString = QNativeSocketEngine::tr("Connection refused");
    237237        break;
    238238    case AddressInuseErrorString:
    239         socketErrorString = QLatin1String(QT_TRANSLATE_NOOP("QNativeSocketEngine", "The bound address is already in use"));
     239        socketErrorString = QNativeSocketEngine::tr("The bound address is already in use");
    240240        break;
    241241    case AddressNotAvailableErrorString:
    242         socketErrorString = QLatin1String(QT_TRANSLATE_NOOP("QNativeSocketEngine", "The address is not available"));
     242        socketErrorString = QNativeSocketEngine::tr("The address is not available");
    243243        break;
    244244    case AddressProtectedErrorString:
    245         socketErrorString = QLatin1String(QT_TRANSLATE_NOOP("QNativeSocketEngine", "The address is protected"));
     245        socketErrorString = QNativeSocketEngine::tr("The address is protected");
    246246        break;
    247247    case DatagramTooLargeErrorString:
    248         socketErrorString = QLatin1String(QT_TRANSLATE_NOOP("QNativeSocketEngine", "Datagram was too large to send"));
     248        socketErrorString = QNativeSocketEngine::tr("Datagram was too large to send");
    249249        break;
    250250    case SendDatagramErrorString:
    251         socketErrorString = QLatin1String(QT_TRANSLATE_NOOP("QNativeSocketEngine", "Unable to send a message"));
     251        socketErrorString = QNativeSocketEngine::tr("Unable to send a message");
    252252        break;
    253253    case ReceiveDatagramErrorString:
    254         socketErrorString = QLatin1String(QT_TRANSLATE_NOOP("QNativeSocketEngine", "Unable to receive a message"));
     254        socketErrorString = QNativeSocketEngine::tr("Unable to receive a message");
    255255        break;
    256256    case WriteErrorString:
    257         socketErrorString = QLatin1String(QT_TRANSLATE_NOOP("QNativeSocketEngine", "Unable to write"));
     257        socketErrorString = QNativeSocketEngine::tr("Unable to write");
    258258        break;
    259259    case ReadErrorString:
    260         socketErrorString = QLatin1String(QT_TRANSLATE_NOOP("QNativeSocketEngine", "Network error"));
     260        socketErrorString = QNativeSocketEngine::tr("Network error");
    261261        break;
    262262    case PortInuseErrorString:
    263         socketErrorString = QLatin1String(QT_TRANSLATE_NOOP("QNativeSocketEngine", "Another socket is already listening on the same port"));
     263        socketErrorString = QNativeSocketEngine::tr("Another socket is already listening on the same port");
    264264        break;
    265265    case NotSocketErrorString:
    266         socketErrorString = QLatin1String(QT_TRANSLATE_NOOP("QNativeSocketEngine", "Operation on non-socket"));
     266        socketErrorString = QNativeSocketEngine::tr("Operation on non-socket");
    267267        break;
    268268    case InvalidProxyTypeString:
    269         socketErrorString = QLatin1String(QT_TRANSLATE_NOOP("QNativeSocketEngine", "The proxy type is invalid for this operation"));
     269        socketErrorString = QNativeSocketEngine::tr("The proxy type is invalid for this operation");
    270270        break;
    271271    case UnknownSocketErrorString:
    272         socketErrorString = QLatin1String(QT_TRANSLATE_NOOP("QNativeSocketEngine", "Unknown error"));
     272        socketErrorString = QNativeSocketEngine::tr("Unknown error");
    273273        break;
    274274    }
     
    382382    }
    383383
     384
    384385    // Make sure we receive out-of-band data
     386    // On Symbian OS this works only with native IP stack, not with WinSock
    385387    if (socketType == QAbstractSocket::TcpSocket
    386388        && !setOption(ReceiveOutOfBandData, 1)) {
     
    388390    }
    389391
    390     // Set the send and receive buffer sizes to a magic size, found
    391     // most optimal for our platforms.
    392     setReceiveBufferSize(49152);
    393     setSendBufferSize(49152);
     392    // Before Qt 4.6, we always set the send and receive buffer size to 49152 as
     393    // this was found to be an optimal value. However, modern OS
     394    // all have some kind of auto tuning for this and we therefore don't set
     395    // this explictly anymore.
     396    // If it introduces any performance regressions for Qt 4.6.x (x > 0) then
     397    // it will be put back in.
     398    //
     399    // You can use tests/manual/qhttpnetworkconnection to test HTTP download speed
     400    // with this.
     401    //
     402    // pre-4.6:
     403    // setReceiveBufferSize(49152);
     404    // setSendBufferSize(49152);
    394405
    395406    d->socketType = socketType;
     
    744755}
    745756
     757
     758qint64 QNativeSocketEngine::bytesToWrite() const
     759{
     760    return 0;
     761}
     762
    746763/*!
    747764    Reads up to \a maxSize bytes into \a data from the socket.
     
    860877bool QNativeSocketEngine::waitForWrite(int msecs, bool *timedOut)
    861878{
    862     Q_D(const QNativeSocketEngine);
     879    Q_D(QNativeSocketEngine);
    863880    Q_CHECK_VALID_SOCKETLAYER(QNativeSocketEngine::waitForWrite(), false);
    864881    Q_CHECK_NOT_STATE(QNativeSocketEngine::waitForWrite(),
     
    877894        d_func()->fetchConnectionParameters();
    878895        return true;
     896    } else {
     897        int value = 0;
     898        int valueSize = sizeof(value);
     899        if (::getsockopt(d->socketDescriptor, SOL_SOCKET, SO_ERROR, (char *) &value, &valueSize) == 0) {
     900            if (value == WSAECONNREFUSED) {
     901                d->setError(QAbstractSocket::ConnectionRefusedError, QNativeSocketEnginePrivate::ConnectionRefusedErrorString);
     902                d->socketState = QAbstractSocket::UnconnectedState;
     903                return false;
     904            } else if (value == WSAETIMEDOUT) {
     905                d->setError(QAbstractSocket::NetworkError, QNativeSocketEnginePrivate::ConnectionTimeOutErrorString);
     906                d->socketState = QAbstractSocket::UnconnectedState;
     907                return false;
     908            } else if (value == WSAEHOSTUNREACH) {
     909                d->setError(QAbstractSocket::NetworkError, QNativeSocketEnginePrivate::HostUnreachableErrorString);
     910                d->socketState = QAbstractSocket::UnconnectedState;
     911                return false;
     912            }
     913        }
    879914    }
    880915#endif
     
    897932                                      int msecs, bool *timedOut)
    898933{
    899     Q_D(const QNativeSocketEngine);
     934    Q_D(QNativeSocketEngine);
    900935    Q_CHECK_VALID_SOCKETLAYER(QNativeSocketEngine::waitForWrite(), false);
    901936    Q_CHECK_NOT_STATE(QNativeSocketEngine::waitForReadOrWrite(),
     
    911946        d_func()->fetchConnectionParameters();
    912947        return true;
    913     }
    914 #endif   
     948    } else {
     949        int value = 0;
     950        int valueSize = sizeof(value);
     951        if (::getsockopt(d->socketDescriptor, SOL_SOCKET, SO_ERROR, (char *) &value, &valueSize) == 0) {
     952            if (value == WSAECONNREFUSED) {
     953                d->setError(QAbstractSocket::ConnectionRefusedError, QNativeSocketEnginePrivate::ConnectionRefusedErrorString);
     954                d->socketState = QAbstractSocket::UnconnectedState;
     955                return false;
     956            } else if (value == WSAETIMEDOUT) {
     957                d->setError(QAbstractSocket::NetworkError, QNativeSocketEnginePrivate::ConnectionTimeOutErrorString);
     958                d->socketState = QAbstractSocket::UnconnectedState;
     959                return false;
     960            } else if (value == WSAEHOSTUNREACH) {
     961                d->setError(QAbstractSocket::NetworkError, QNativeSocketEnginePrivate::HostUnreachableErrorString);
     962                d->socketState = QAbstractSocket::UnconnectedState;
     963                return false;
     964            }
     965        }
     966    }
     967#endif
    915968    if (ret == 0) {
    916969        if (timedOut)
     
    10871140{
    10881141    if (e->type() == QEvent::SockAct) {
    1089         engine->exceptionNotification();
     1142        if (engine->state() == QAbstractSocket::ConnectingState)
     1143            engine->connectionNotification();
     1144        else
     1145            engine->exceptionNotification();
    10901146        return true;
    10911147    }
Note: See TracChangeset for help on using the changeset viewer.