Index: /trunk/src/network/socket/qlocalserver_os2.cpp
===================================================================
--- /trunk/src/network/socket/qlocalserver_os2.cpp	(revision 157)
+++ /trunk/src/network/socket/qlocalserver_os2.cpp	(revision 157)
@@ -0,0 +1,253 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** Copyright (C) 2009 netlabs.org. OS/2 parts.
+**
+** This file is part of the QtNetwork module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial Usage
+** Licensees holding valid Qt Commercial licenses may use this file in
+** accordance with the Qt Commercial License Agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Nokia.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file.  Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file.  Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qlocalserver.h"
+#include "qlocalserver_p.h"
+#include "qlocalsocket.h"
+#include "qlocalsocket_p.h"
+
+#ifndef QT_NO_LOCALSERVER
+
+#include <sys/socket.h>
+#include <sys/un.h>
+
+#include <qdebug.h>
+#include <qdir.h>
+#include <qdatetime.h>
+
+QT_BEGIN_NAMESPACE
+
+void QLocalServerPrivate::init()
+{
+}
+
+bool QLocalServerPrivate::removeServer(const QString &name)
+{
+    QString fileName;
+    if (name.startsWith(QLatin1Char('/'))) {
+        fileName = name;
+    } else {
+        fileName = QDir::cleanPath(QDir::tempPath());
+        fileName += QLatin1Char('/') + name;
+    }
+    if (QFile::exists(fileName))
+        return QFile::remove(fileName);
+    else
+        return true;
+}
+
+bool QLocalServerPrivate::listen(const QString &requestedServerName)
+{
+    Q_Q(QLocalServer);
+
+    // determine the full server path
+    if (requestedServerName.startsWith(QLatin1Char('/'))) {
+        fullServerName = requestedServerName;
+    } else {
+        fullServerName = QDir::cleanPath(QDir::tempPath());
+        fullServerName += QLatin1Char('/') + requestedServerName;
+    }
+    serverName = requestedServerName;
+
+    // create the unix socket
+    listenSocket = qSocket(PF_UNIX, SOCK_STREAM, 0);
+    if (-1 == listenSocket) {
+        setError(QLatin1String("QLocalServer::listen"));
+        closeServer();
+        return false;
+    }
+
+    // Construct the unix address
+    struct ::sockaddr_un addr;
+    addr.sun_family = PF_UNIX;
+    if (sizeof(addr.sun_path) < (uint)fullServerName.toLatin1().size() + 1) {
+        setError(QLatin1String("QLocalServer::listen"));
+        closeServer();
+        return false;
+    }
+    ::memcpy(addr.sun_path, fullServerName.toLatin1().data(),
+             fullServerName.toLatin1().size() + 1);
+
+    // bind
+    if(-1 == qBind(listenSocket, (sockaddr *)&addr, sizeof(sockaddr_un))) {
+        setError(QLatin1String("QLocalServer::listen"));
+        // if address is in use already, just close the socket, but do not delete the file
+        if(errno == EADDRINUSE)
+            QT_CLOSE(listenSocket);
+        // otherwise, close the socket and delete the file
+        else
+            closeServer();
+        listenSocket = -1;
+        return false;
+    }
+
+    // listen for connections
+    if (-1 == qListen(listenSocket, 50)) {
+        setError(QLatin1String("QLocalServer::listen"));
+        closeServer();
+        listenSocket = -1;
+        if (error != QAbstractSocket::AddressInUseError)
+            QFile::remove(fullServerName);
+        return false;
+    }
+    Q_ASSERT(!socketNotifier);
+    socketNotifier = new QSocketNotifier(listenSocket,
+                                         QSocketNotifier::Read, q);
+    q->connect(socketNotifier, SIGNAL(activated(int)),
+               q, SLOT(_q_socketActivated()));
+    socketNotifier->setEnabled(maxPendingConnections > 0);
+    return true;
+}
+
+/*!
+    \internal
+
+    \sa QLocalServer::closeServer()
+ */
+void QLocalServerPrivate::closeServer()
+{
+    if (-1 != listenSocket)
+        QT_CLOSE(listenSocket);
+    listenSocket = -1;
+
+    if (socketNotifier)
+        socketNotifier->deleteLater();
+    socketNotifier = 0;
+
+    if (!fullServerName.isEmpty())
+        QFile::remove(fullServerName);
+}
+
+/*!
+    \internal
+
+    We have received a notification that we can read on the listen socket.
+    Accept the new socket.
+ */
+void QLocalServerPrivate::_q_socketActivated()
+{
+    Q_Q(QLocalServer);
+    if (-1 == listenSocket)
+        return;
+
+    ::sockaddr_un addr;
+    QT_SOCKLEN_T length = sizeof(sockaddr_un);
+    int connectedSocket = qAccept(listenSocket, (sockaddr *)&addr, &length);
+    if(-1 == connectedSocket) {
+        setError(QLatin1String("QLocalSocket::activated"));
+        closeServer();
+    } else {
+        socketNotifier->setEnabled(pendingConnections.size()
+                                   <= maxPendingConnections);
+        q->incomingConnection(connectedSocket);
+    }
+}
+
+void QLocalServerPrivate::waitForNewConnection(int msec, bool *timedOut)
+{
+    fd_set readfds;
+    FD_ZERO(&readfds);
+    FD_SET(listenSocket, &readfds);
+
+    timeval timeout;
+    timeout.tv_sec = msec / 1000;
+    timeout.tv_usec = (msec % 1000) * 1000;
+
+    // timeout can not be 0 or else select will return an error.
+    if (0 == msec)
+        timeout.tv_usec = 1000;
+
+    int result = -1;
+    // on Linux timeout will be updated by select, but _not_ on other systems.
+    QTime timer;
+    timer.start();
+    while (pendingConnections.isEmpty() && (-1 == msec || timer.elapsed() < msec)) {
+        result = ::select(listenSocket + 1, &readfds, 0, 0, &timeout);
+        if (-1 == result && errno != EINTR) {
+            setError(QLatin1String("QLocalServer::waitForNewConnection"));
+            closeServer();
+            break;
+        }
+        if (result > 0)
+            _q_socketActivated();
+    }
+    if (timedOut)
+        *timedOut = (result == 0);
+}
+
+void QLocalServerPrivate::setError(const QString &function)
+{
+    if (EAGAIN == errno)
+        return;
+
+    switch (errno) {
+    case EACCES:
+        errorString = QLocalServer::tr("%1: Permission denied").arg(function);
+        error = QAbstractSocket::SocketAccessError;
+        break;
+    case ELOOP:
+    case ENOENT:
+    case ENAMETOOLONG:
+    case EROFS:
+    case ENOTDIR:
+        errorString = QLocalServer::tr("%1: Name error").arg(function);
+        error = QAbstractSocket::HostNotFoundError;
+        break;
+    case EADDRINUSE:
+        errorString = QLocalServer::tr("%1: Address in use").arg(function);
+        error = QAbstractSocket::AddressInUseError;
+        break;
+
+    default:
+        errorString = QLocalServer::tr("%1: Unknown error %2")
+                      .arg(function).arg(errno);
+        error = QAbstractSocket::UnknownSocketError;
+#if defined QLOCALSERVER_DEBUG
+        qWarning() << errorString << "fullServerName:" << fullServerName;
+#endif
+    }
+}
+
+QT_END_NAMESPACE
+
+#endif // QT_NO_LOCALSERVER
Index: /trunk/src/network/socket/qlocalsocket_os2.cpp
===================================================================
--- /trunk/src/network/socket/qlocalsocket_os2.cpp	(revision 157)
+++ /trunk/src/network/socket/qlocalsocket_os2.cpp	(revision 157)
@@ -0,0 +1,568 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** Copyright (C) 2009 netlabs.org. OS/2 parts.
+**
+** This file is part of the QtNetwork module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial Usage
+** Licensees holding valid Qt Commercial licenses may use this file in
+** accordance with the Qt Commercial License Agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Nokia.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file.  Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file.  Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qlocalsocket.h"
+#include "qlocalsocket_p.h"
+
+#ifndef QT_NO_LOCALSOCKET
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <errno.h>
+
+#include <qdatetime.h>
+#include <qdir.h>
+#include <qdebug.h>
+
+#define QT_CONNECT_TIMEOUT 30000
+
+QT_BEGIN_NAMESPACE
+
+QLocalSocketPrivate::QLocalSocketPrivate() : QIODevicePrivate(),
+        delayConnect(0),
+        connectTimer(0),
+        connectingSocket(-1),
+        connectingOpenMode(0),
+        state(QLocalSocket::UnconnectedState)
+{
+}
+
+void QLocalSocketPrivate::init()
+{
+    Q_Q(QLocalSocket);
+    // QIODevice signals
+    q->connect(&unixSocket, SIGNAL(aboutToClose()), q, SIGNAL(aboutToClose()));
+    q->connect(&unixSocket, SIGNAL(bytesWritten(qint64)),
+               q, SIGNAL(bytesWritten(qint64)));
+    q->connect(&unixSocket, SIGNAL(readyRead()), q, SIGNAL(readyRead()));
+    // QAbstractSocket signals
+    q->connect(&unixSocket, SIGNAL(connected()), q, SIGNAL(connected()));
+    q->connect(&unixSocket, SIGNAL(disconnected()), q, SIGNAL(disconnected()));
+    q->connect(&unixSocket, SIGNAL(stateChanged(QAbstractSocket::SocketState)),
+               q, SLOT(_q_stateChanged(QAbstractSocket::SocketState)));
+    q->connect(&unixSocket, SIGNAL(error(QAbstractSocket::SocketError)),
+               q, SLOT(_q_error(QAbstractSocket::SocketError)));
+    q->connect(&unixSocket, SIGNAL(readChannelFinished()), q, SIGNAL(readChannelFinished()));
+    unixSocket.setParent(q);
+}
+
+void QLocalSocketPrivate::_q_error(QAbstractSocket::SocketError socketError)
+{
+    Q_Q(QLocalSocket);
+    QString function = QLatin1String("QLocalSocket");
+    QLocalSocket::LocalSocketError error = (QLocalSocket::LocalSocketError)socketError;
+    QString errorString = generateErrorString(error, function);
+    q->setErrorString(errorString);
+    emit q->error(error);
+}
+
+void QLocalSocketPrivate::_q_stateChanged(QAbstractSocket::SocketState newState)
+{
+    Q_Q(QLocalSocket);
+    QLocalSocket::LocalSocketState currentState = state;
+    switch(newState) {
+    case QAbstractSocket::UnconnectedState:
+        state = QLocalSocket::UnconnectedState;
+        serverName = QString();
+        fullServerName = QString();
+        break;
+    case QAbstractSocket::ConnectingState:
+        state = QLocalSocket::ConnectingState;
+        break;
+    case QAbstractSocket::ConnectedState:
+        state = QLocalSocket::ConnectedState;
+        break;
+    case QAbstractSocket::ClosingState:
+        state = QLocalSocket::ClosingState;
+        break;
+    default:
+#if defined QLOCALSOCKET_DEBUG
+        qWarning() << "QLocalSocket::Unhandled socket state change:" << newState;
+#endif
+        return;
+    }
+    if (currentState != state)
+        emit q->stateChanged(state);
+}
+
+QString QLocalSocketPrivate::generateErrorString(QLocalSocket::LocalSocketError error, const QString &function) const
+{
+    QString errorString;
+    switch (error) {
+    case QLocalSocket::ConnectionRefusedError:
+        errorString = QLocalSocket::tr("%1: Connection refused").arg(function);
+        break;
+    case QLocalSocket::PeerClosedError:
+        errorString = QLocalSocket::tr("%1: Remote closed").arg(function);
+        break;
+    case QLocalSocket::ServerNotFoundError:
+        errorString = QLocalSocket::tr("%1: Invalid name").arg(function);
+        break;
+    case QLocalSocket::SocketAccessError:
+        errorString = QLocalSocket::tr("%1: Socket access error").arg(function);
+        break;
+    case QLocalSocket::SocketResourceError:
+        errorString = QLocalSocket::tr("%1: Socket resource error").arg(function);
+        break;
+    case QLocalSocket::SocketTimeoutError:
+        errorString = QLocalSocket::tr("%1: Socket operation timed out").arg(function);
+        break;
+    case QLocalSocket::DatagramTooLargeError:
+        errorString = QLocalSocket::tr("%1: Datagram too large").arg(function);
+        break;
+    case QLocalSocket::ConnectionError:
+        errorString = QLocalSocket::tr("%1: Connection error").arg(function);
+        break;
+    case QLocalSocket::UnsupportedSocketOperationError:
+        errorString = QLocalSocket::tr("%1: The socket operation is not supported").arg(function);
+        break;
+    case QLocalSocket::UnknownSocketError:
+    default:
+        errorString = QLocalSocket::tr("%1: Unknown error %2").arg(function).arg(errno);
+    }
+    return errorString;
+}
+
+void QLocalSocketPrivate::errorOccurred(QLocalSocket::LocalSocketError error, const QString &function)
+{
+    Q_Q(QLocalSocket);
+    switch (error) {
+    case QLocalSocket::ConnectionRefusedError:
+        unixSocket.setSocketError(QAbstractSocket::ConnectionRefusedError);
+        break;
+    case QLocalSocket::PeerClosedError:
+        unixSocket.setSocketError(QAbstractSocket::RemoteHostClosedError);
+        break;
+    case QLocalSocket::ServerNotFoundError:
+        unixSocket.setSocketError(QAbstractSocket::HostNotFoundError);
+        break;
+    case QLocalSocket::SocketAccessError:
+        unixSocket.setSocketError(QAbstractSocket::SocketAccessError);
+        break;
+    case QLocalSocket::SocketResourceError:
+        unixSocket.setSocketError(QAbstractSocket::SocketResourceError);
+        break;
+    case QLocalSocket::SocketTimeoutError:
+        unixSocket.setSocketError(QAbstractSocket::SocketTimeoutError);
+        break;
+    case QLocalSocket::DatagramTooLargeError:
+        unixSocket.setSocketError(QAbstractSocket::DatagramTooLargeError);
+        break;
+    case QLocalSocket::ConnectionError:
+        unixSocket.setSocketError(QAbstractSocket::NetworkError);
+        break;
+    case QLocalSocket::UnsupportedSocketOperationError:
+        unixSocket.setSocketError(QAbstractSocket::UnsupportedSocketOperationError);
+        break;
+    case QLocalSocket::UnknownSocketError:
+    default:
+        unixSocket.setSocketError(QAbstractSocket::UnknownSocketError);
+    }
+
+    QString errorString = generateErrorString(error, function);
+    q->setErrorString(errorString);
+    emit q->error(error);
+
+    // errors cause a disconnect
+    unixSocket.setSocketState(QAbstractSocket::UnconnectedState);
+    bool stateChanged = (state != QLocalSocket::UnconnectedState);
+    state = QLocalSocket::UnconnectedState;
+    q->close();
+    if (stateChanged)
+        q->emit stateChanged(state);
+}
+
+void QLocalSocket::connectToServer(const QString &name, OpenMode openMode)
+{
+    Q_D(QLocalSocket);
+    if (state() == ConnectedState
+        || state() == ConnectingState)
+        return;
+
+    d->errorString = QString();
+    d->unixSocket.setSocketState(QAbstractSocket::ConnectingState);
+    d->state = ConnectingState;
+    emit stateChanged(d->state);
+
+    if (name.isEmpty()) {
+        d->errorOccurred(ServerNotFoundError,
+                QLatin1String("QLocalSocket::connectToServer"));
+        return;
+    }
+
+    // create the socket
+    if (-1 == (d->connectingSocket = qSocket(PF_UNIX, SOCK_STREAM, 0))) {
+        d->errorOccurred(UnsupportedSocketOperationError,
+                        QLatin1String("QLocalSocket::connectToServer"));
+        return;
+    }
+
+    // set non blocking so we can try to connect and it wont wait
+    int flags = fcntl(d->connectingSocket, F_GETFL, 0);
+    if (-1 == flags
+        || -1 == (fcntl(d->connectingSocket, F_SETFL, flags | O_NONBLOCK))) {
+        d->errorOccurred(UnknownSocketError,
+                QLatin1String("QLocalSocket::connectToServer"));
+        return;
+    }
+
+    // _q_connectToSocket does the actual connecting
+    d->connectingName = name;
+    d->connectingOpenMode = openMode;
+    d->_q_connectToSocket();
+}
+
+/*!
+    \internal
+
+    Tries to connect connectingName and connectingOpenMode
+
+    \sa connectToServer() waitForConnected()
+  */
+void QLocalSocketPrivate::_q_connectToSocket()
+{
+    Q_Q(QLocalSocket);
+    QString connectingPathName;
+
+    // determine the full server path
+    if (connectingName.startsWith(QLatin1Char('/'))) {
+        connectingPathName = connectingName;
+    } else {
+        connectingPathName = QDir::tempPath();
+        connectingPathName += QLatin1Char('/') + connectingName;
+    }
+
+    struct sockaddr_un name;
+    name.sun_family = PF_UNIX;
+    if (sizeof(name.sun_path) < (uint)connectingPathName.toLatin1().size() + 1) {
+        QString function = QLatin1String("QLocalSocket::connectToServer");
+        errorOccurred(QLocalSocket::ServerNotFoundError, function);
+        return;
+    }
+    ::memcpy(name.sun_path, connectingPathName.toLatin1().data(),
+             connectingPathName.toLatin1().size() + 1);
+    if (-1 == qConnect(connectingSocket, (struct sockaddr *)&name, sizeof(name))) {
+        QString function = QLatin1String("QLocalSocket::connectToServer");
+        switch (errno)
+        {
+        case EINVAL:
+        case ECONNREFUSED:
+            errorOccurred(QLocalSocket::ConnectionRefusedError, function);
+            break;
+        case ENOENT:
+            errorOccurred(QLocalSocket::ServerNotFoundError, function);
+            break;
+        case EACCES:
+        case EPERM:
+            errorOccurred(QLocalSocket::SocketAccessError, function);
+            break;
+        case ETIMEDOUT:
+            errorOccurred(QLocalSocket::SocketTimeoutError, function);
+            break;
+        case EAGAIN:
+            // Try again later, all of the sockets listening are full
+            if (!delayConnect) {
+                delayConnect = new QSocketNotifier(connectingSocket, QSocketNotifier::Write);
+                q->connect(delayConnect, SIGNAL(activated(int)), q, SLOT(_q_connectToSocket()));
+            }
+            if (!connectTimer) {
+                connectTimer = new QTimer(q);
+                q->connect(connectTimer, SIGNAL(timeout()),
+                                 q, SLOT(_q_abortConnectionAttempt()),
+                                 Qt::DirectConnection);
+                connectTimer->start(QT_CONNECT_TIMEOUT);
+            }
+            delayConnect->setEnabled(true);
+            break;
+        default:
+            errorOccurred(QLocalSocket::UnknownSocketError, function);
+        }
+        return;
+    }
+
+    // connected!
+    if (delayConnect) {
+        delayConnect->setEnabled(false);
+        delete delayConnect;
+        delayConnect = 0;
+    }
+    serverName = connectingName;
+    fullServerName = connectingPathName;
+    if (unixSocket.setSocketDescriptor(connectingSocket,
+        QAbstractSocket::ConnectedState, connectingOpenMode)) {
+        q->QIODevice::open(connectingOpenMode);
+        q->emit connected();
+    } else {
+        QString function = QLatin1String("QLocalSocket::connectToServer");
+        errorOccurred(QLocalSocket::UnknownSocketError, function);
+    }
+    connectingSocket = -1;
+    connectingName = QString();
+    connectingOpenMode = 0;
+}
+
+bool QLocalSocket::setSocketDescriptor(quintptr socketDescriptor,
+        LocalSocketState socketState, OpenMode openMode)
+{
+    Q_D(QLocalSocket);
+    QAbstractSocket::SocketState newSocketState = QAbstractSocket::UnconnectedState;
+    switch (socketState) {
+    case ConnectingState:
+        newSocketState = QAbstractSocket::ConnectingState;
+        break;
+    case ConnectedState:
+        newSocketState = QAbstractSocket::ConnectedState;
+        break;
+    case ClosingState:
+        newSocketState = QAbstractSocket::ClosingState;
+        break;
+    case UnconnectedState:
+        newSocketState = QAbstractSocket::UnconnectedState;
+        break;
+    }
+    QIODevice::open(openMode);
+    d->state = socketState;
+    return d->unixSocket.setSocketDescriptor(socketDescriptor,
+                                             newSocketState, openMode);
+}
+
+void QLocalSocketPrivate::_q_abortConnectionAttempt()
+{
+    Q_Q(QLocalSocket);
+    q->close();
+}
+
+quintptr QLocalSocket::socketDescriptor() const
+{
+    Q_D(const QLocalSocket);
+    return d->unixSocket.socketDescriptor();
+}
+
+qint64 QLocalSocket::readData(char *data, qint64 c)
+{
+    Q_D(QLocalSocket);
+    return d->unixSocket.readData(data, c);
+}
+
+qint64 QLocalSocket::writeData(const char *data, qint64 c)
+{
+    Q_D(QLocalSocket);
+    return d->unixSocket.writeData(data, c);
+}
+
+void QLocalSocket::abort()
+{
+    Q_D(QLocalSocket);
+    d->unixSocket.abort();
+}
+
+qint64 QLocalSocket::bytesAvailable() const
+{
+    Q_D(const QLocalSocket);
+    return QIODevice::bytesAvailable() + d->unixSocket.bytesAvailable();
+}
+
+qint64 QLocalSocket::bytesToWrite() const
+{
+    Q_D(const QLocalSocket);
+    return d->unixSocket.bytesToWrite();
+}
+
+bool QLocalSocket::canReadLine() const
+{
+    Q_D(const QLocalSocket);
+    return QIODevice::canReadLine() || d->unixSocket.canReadLine();
+}
+
+void QLocalSocket::close()
+{
+    Q_D(QLocalSocket);
+    d->unixSocket.close();
+    if (d->delayConnect) {
+        d->delayConnect->setEnabled(false);
+        delete d->delayConnect;
+        d->delayConnect = 0;
+        d->connectTimer->stop();
+        delete d->connectTimer;
+        d->connectTimer = 0;
+    }
+    if (d->connectingSocket != -1)
+        ::close(d->connectingSocket);
+    d->connectingSocket = -1;
+    d->connectingName = QString();
+    d->connectingOpenMode = 0;
+    d->serverName = QString();
+    d->fullServerName = QString();
+    QIODevice::close();
+}
+
+bool QLocalSocket::waitForBytesWritten(int msecs)
+{
+    Q_D(QLocalSocket);
+    return d->unixSocket.waitForBytesWritten(msecs);
+}
+
+bool QLocalSocket::flush()
+{
+    Q_D(QLocalSocket);
+    return d->unixSocket.flush();
+}
+
+void QLocalSocket::disconnectFromServer()
+{
+    Q_D(QLocalSocket);
+    d->unixSocket.disconnectFromHost();
+}
+
+QLocalSocket::LocalSocketError QLocalSocket::error() const
+{
+    Q_D(const QLocalSocket);
+    switch (d->unixSocket.error()) {
+    case QAbstractSocket::ConnectionRefusedError:
+        return QLocalSocket::ConnectionRefusedError;
+    case QAbstractSocket::RemoteHostClosedError:
+        return QLocalSocket::PeerClosedError;
+    case QAbstractSocket::HostNotFoundError:
+        return QLocalSocket::ServerNotFoundError;
+    case QAbstractSocket::SocketAccessError:
+        return QLocalSocket::SocketAccessError;
+    case QAbstractSocket::SocketResourceError:
+        return QLocalSocket::SocketResourceError;
+    case QAbstractSocket::SocketTimeoutError:
+        return QLocalSocket::SocketTimeoutError;
+    case QAbstractSocket::DatagramTooLargeError:
+        return QLocalSocket::DatagramTooLargeError;
+    case QAbstractSocket::NetworkError:
+        return QLocalSocket::ConnectionError;
+    case QAbstractSocket::UnsupportedSocketOperationError:
+        return QLocalSocket::UnsupportedSocketOperationError;
+    case QAbstractSocket::UnknownSocketError:
+        return QLocalSocket::UnknownSocketError;
+    default:
+#if defined QLOCALSOCKET_DEBUG
+        qWarning() << "QLocalSocket error not handled:" << d->unixSocket.error();
+#endif
+        break;
+    }
+    return UnknownSocketError;
+}
+
+bool QLocalSocket::isValid() const
+{
+    Q_D(const QLocalSocket);
+    return d->unixSocket.isValid();
+}
+
+qint64 QLocalSocket::readBufferSize() const
+{
+    Q_D(const QLocalSocket);
+    return d->unixSocket.readBufferSize();
+}
+
+void QLocalSocket::setReadBufferSize(qint64 size)
+{
+    Q_D(QLocalSocket);
+    d->unixSocket.setReadBufferSize(size);
+}
+
+bool QLocalSocket::waitForConnected(int msec)
+{
+    Q_D(QLocalSocket);
+    if (state() != ConnectingState)
+        return (state() == ConnectedState);
+
+    fd_set readfds;
+    FD_ZERO(&readfds);
+    FD_SET(d->connectingSocket, &readfds);
+
+    timeval timeout;
+    timeout.tv_sec = msec / 1000;
+    timeout.tv_usec = (msec % 1000) * 1000;
+
+    // timeout can not be 0 or else select will return an error.
+    if (0 == msec)
+        timeout.tv_usec = 1000;
+
+    int result = -1;
+    // on Linux timeout will be updated by select, but _not_ on other systems.
+    QTime timer;
+    timer.start();
+    while (state() == ConnectingState
+           && (-1 == msec || timer.elapsed() < msec)) {
+        result = ::select(d->connectingSocket + 1, &readfds, 0, 0, &timeout);
+        if (-1 == result && errno != EINTR) {
+            d->errorOccurred( QLocalSocket::UnknownSocketError,
+                    QLatin1String("QLocalSocket::waitForConnected"));
+            break;
+        }
+        if (result > 0)
+            d->_q_connectToSocket();
+    }
+
+    return (state() == ConnectedState);
+}
+
+bool QLocalSocket::waitForDisconnected(int msecs)
+{
+    Q_D(QLocalSocket);
+    if (state() == UnconnectedState) {
+        qWarning() << "QLocalSocket::waitForDisconnected() is not allowed in UnconnectedState";
+        return false;
+    }
+    return (d->unixSocket.waitForDisconnected(msecs));
+}
+
+bool QLocalSocket::waitForReadyRead(int msecs)
+{
+    Q_D(QLocalSocket);
+    if (state() == QLocalSocket::UnconnectedState)
+        return false;
+    return (d->unixSocket.waitForReadyRead(msecs));
+}
+
+QT_END_NAMESPACE
+
+#endif
Index: /trunk/src/network/socket/qnativesocketengine_os2.cpp
===================================================================
--- /trunk/src/network/socket/qnativesocketengine_os2.cpp	(revision 157)
+++ /trunk/src/network/socket/qnativesocketengine_os2.cpp	(revision 157)
@@ -0,0 +1,845 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** Copyright (C) 2009 netlabs.org. OS/2 parts.
+**
+** This file is part of the QtNetwork module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial Usage
+** Licensees holding valid Qt Commercial licenses may use this file in
+** accordance with the Qt Commercial License Agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Nokia.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file.  Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file.  Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//#define QNATIVESOCKETENGINE_DEBUG
+
+#include "qnativesocketengine_p.h"
+#include "qiodevice.h"
+#include "qhostaddress.h"
+#include "qvarlengtharray.h"
+#include "qdatetime.h"
+#include <time.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <sys/filio.h>
+
+#if defined QNATIVESOCKETENGINE_DEBUG
+#include <qstring.h>
+#include <ctype.h>
+#endif
+
+QT_BEGIN_NAMESPACE
+
+#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
+
+static void qt_ignore_sigpipe()
+{
+    // Set to ignore SIGPIPE once only.
+    static QBasicAtomicInt atom = Q_BASIC_ATOMIC_INITIALIZER(0);
+    if (atom.testAndSetRelaxed(0, 1)) {
+        struct sigaction noaction;
+        memset(&noaction, 0, sizeof(noaction));
+        noaction.sa_handler = SIG_IGN;
+        ::sigaction(SIGPIPE, &noaction, 0);
+    }
+}
+
+/*
+    Extracts the port and address from a sockaddr, and stores them in
+    \a port and \a addr if they are non-null.
+*/
+static inline void qt_socket_getPortAndAddress(struct sockaddr *sa, quint16 *port, QHostAddress *addr)
+{
+    struct sockaddr_in *sa4 = (struct sockaddr_in *)sa;
+    if (port)
+        *port = ntohs(sa4->sin_port);
+    if (addr) {
+        QHostAddress tmpAddress;
+        tmpAddress.setAddress(ntohl(sa4->sin_addr.s_addr));
+        *addr = tmpAddress;
+    }
+}
+
+/*! \internal
+
+    Creates and returns a new socket descriptor of type \a socketType
+    and \a socketProtocol.  Returns -1 on failure.
+*/
+bool QNativeSocketEnginePrivate::createNewSocket(QAbstractSocket::SocketType socketType,
+                                         QAbstractSocket::NetworkLayerProtocol socketProtocol)
+{
+    Q_UNUSED(socketProtocol);
+    int protocol = AF_INET;
+    int type = (socketType == QAbstractSocket::UdpSocket) ? SOCK_DGRAM : SOCK_STREAM;
+    int socket = qt_socket_socket(protocol, type, 0);
+
+    if (socket <= 0) {
+        switch (errno) {
+        case EPROTONOSUPPORT:
+        case EAFNOSUPPORT:
+        case EINVAL:
+            setError(QAbstractSocket::UnsupportedSocketOperationError, ProtocolUnsupportedErrorString);
+            break;
+        case ENFILE:
+        case EMFILE:
+        case ENOBUFS:
+        case ENOMEM:
+            setError(QAbstractSocket::SocketResourceError, ResourceErrorString);
+            break;
+        case EACCES:
+            setError(QAbstractSocket::SocketAccessError, AccessErrorString);
+            break;
+        default:
+            break;
+        }
+
+        return false;
+    }
+
+    // Ensure that the socket is closed on exec*().
+    ::fcntl(socket, F_SETFD, FD_CLOEXEC);
+    socketDescriptor = socket;
+    return true;
+}
+
+/*
+    Returns the value of the socket option \a opt.
+*/
+int QNativeSocketEnginePrivate::option(QNativeSocketEngine::SocketOption opt) const
+{
+    Q_Q(const QNativeSocketEngine);
+    if (!q->isValid())
+        return -1;
+
+    int n = -1;
+    switch (opt) {
+    case QNativeSocketEngine::ReceiveBufferSocketOption:
+        n = SO_RCVBUF;
+        break;
+    case QNativeSocketEngine::SendBufferSocketOption:
+        n = SO_SNDBUF;
+        break;
+    case QNativeSocketEngine::NonBlockingSocketOption:
+        break;
+    case QNativeSocketEngine::BroadcastSocketOption:
+        break;
+    case QNativeSocketEngine::AddressReusable:
+        n = SO_REUSEADDR;
+        break;
+    case QNativeSocketEngine::BindExclusively:
+        return true;
+    case QNativeSocketEngine::ReceiveOutOfBandData:
+        n = SO_OOBINLINE;
+        break;
+    }
+
+    int v = -1;
+    QT_SOCKOPTLEN_T len = sizeof(v);
+    if (getsockopt(socketDescriptor, SOL_SOCKET, n, (char *) &v, &len) != -1)
+        return v;
+    return -1;
+}
+
+
+/*
+    Sets the socket option \a opt to \a v.
+*/
+bool QNativeSocketEnginePrivate::setOption(QNativeSocketEngine::SocketOption opt, int v)
+{
+    Q_Q(QNativeSocketEngine);
+    if (!q->isValid())
+        return false;
+
+    int n = 0;
+    switch (opt) {
+    case QNativeSocketEngine::ReceiveBufferSocketOption:
+        n = SO_RCVBUF;
+        break;
+    case QNativeSocketEngine::SendBufferSocketOption:
+        n = SO_SNDBUF;
+        break;
+    case QNativeSocketEngine::BroadcastSocketOption:
+        n = SO_BROADCAST;
+        break;
+    case QNativeSocketEngine::NonBlockingSocketOption: {
+        // Make the socket nonblocking.
+        int flags = ::fcntl(socketDescriptor, F_GETFL, 0);
+        if (flags == -1) {
+#ifdef QNATIVESOCKETENGINE_DEBUG
+            perror("QNativeSocketEnginePrivate::setOption(): fcntl(F_GETFL) failed");
+#endif
+            return false;
+        }
+        if (::fcntl(socketDescriptor, F_SETFL, flags | O_NONBLOCK) == -1) {
+#ifdef QNATIVESOCKETENGINE_DEBUG
+            perror("QNativeSocketEnginePrivate::setOption(): fcntl(F_SETFL) failed");
+#endif
+            return false;
+        }
+
+        return true;
+    }
+    case QNativeSocketEngine::AddressReusable:
+#ifdef SO_REUSEPORT
+        n = SO_REUSEPORT;
+#else
+        n = SO_REUSEADDR;
+#endif
+        break;
+    case QNativeSocketEngine::BindExclusively:
+        return true;
+    case QNativeSocketEngine::ReceiveOutOfBandData:
+        n = SO_OOBINLINE;
+        break;
+    }
+
+    return ::setsockopt(socketDescriptor, SOL_SOCKET, n, (char *) &v, sizeof(v)) == 0;
+}
+
+bool QNativeSocketEnginePrivate::nativeConnect(const QHostAddress &addr, quint16 port)
+{
+    struct sockaddr_in sockAddrIPv4;
+    struct sockaddr *sockAddrPtr = 0;
+    QT_SOCKLEN_T sockAddrSize = 0;
+
+    if (addr.protocol() == QAbstractSocket::IPv4Protocol) {
+        memset(&sockAddrIPv4, 0, sizeof(sockAddrIPv4));
+        sockAddrIPv4.sin_family = AF_INET;
+        sockAddrIPv4.sin_port = htons(port);
+        sockAddrIPv4.sin_addr.s_addr = htonl(addr.toIPv4Address());
+
+        sockAddrSize = sizeof(sockAddrIPv4);
+        sockAddrPtr = (struct sockaddr *) &sockAddrIPv4;
+    } else {
+        // unreachable
+    }
+
+    int connectResult = QT_SOCKET_CONNECT(socketDescriptor, sockAddrPtr, sockAddrSize);
+    if (connectResult == -1) {
+        switch (errno) {
+        case EISCONN:
+            socketState = QAbstractSocket::ConnectedState;
+            break;
+        case ECONNREFUSED:
+        case EINVAL:
+            setError(QAbstractSocket::ConnectionRefusedError, ConnectionRefusedErrorString);
+            socketState = QAbstractSocket::UnconnectedState;
+            break;
+        case ETIMEDOUT:
+            setError(QAbstractSocket::NetworkError, ConnectionTimeOutErrorString);
+            break;
+        case EHOSTUNREACH:
+            setError(QAbstractSocket::NetworkError, HostUnreachableErrorString);
+            socketState = QAbstractSocket::UnconnectedState;
+            break;
+        case ENETUNREACH:
+            setError(QAbstractSocket::NetworkError, NetworkUnreachableErrorString);
+            socketState = QAbstractSocket::UnconnectedState;
+            break;
+        case EADDRINUSE:
+            setError(QAbstractSocket::NetworkError, AddressInuseErrorString);
+            break;
+        case EINPROGRESS:
+        case EALREADY:
+            setError(QAbstractSocket::UnfinishedSocketOperationError, InvalidSocketErrorString);
+            socketState = QAbstractSocket::ConnectingState;
+            break;
+        case EAGAIN:
+            setError(QAbstractSocket::UnfinishedSocketOperationError, InvalidSocketErrorString);
+            setError(QAbstractSocket::SocketResourceError, ResourceErrorString);
+            break;
+        case EACCES:
+        case EPERM:
+            setError(QAbstractSocket::SocketAccessError, AccessErrorString);
+            socketState = QAbstractSocket::UnconnectedState;
+            break;
+        case EAFNOSUPPORT:
+        case EBADF:
+        case EFAULT:
+        case ENOTSOCK:
+            socketState = QAbstractSocket::UnconnectedState;
+        default:
+            break;
+        }
+
+        if (socketState != QAbstractSocket::ConnectedState) {
+#if defined (QNATIVESOCKETENGINE_DEBUG)
+            qDebug("QNativeSocketEnginePrivate::nativeConnect(%s, %i) == false (%s)",
+                   addr.toString().toLatin1().constData(), port,
+                   socketState == QAbstractSocket::ConnectingState
+                   ? "Connection in progress" : socketErrorString.toLatin1().constData());
+#endif
+            return false;
+        }
+    }
+
+#if defined (QNATIVESOCKETENGINE_DEBUG)
+    qDebug("QNativeSocketEnginePrivate::nativeConnect(%s, %i) == true",
+           addr.toString().toLatin1().constData(), port);
+#endif
+
+    socketState = QAbstractSocket::ConnectedState;
+    return true;
+}
+
+bool QNativeSocketEnginePrivate::nativeBind(const QHostAddress &address, quint16 port)
+{
+    struct sockaddr_in sockAddrIPv4;
+    struct sockaddr *sockAddrPtr = 0;
+    QT_SOCKLEN_T sockAddrSize = 0;
+
+    if (address.protocol() == QAbstractSocket::IPv4Protocol) {
+        memset(&sockAddrIPv4, 0, sizeof(sockAddrIPv4));
+        sockAddrIPv4.sin_family = AF_INET;
+        sockAddrIPv4.sin_port = htons(port);
+        sockAddrIPv4.sin_addr.s_addr = htonl(address.toIPv4Address());
+        sockAddrSize = sizeof(sockAddrIPv4);
+        sockAddrPtr = (struct sockaddr *) &sockAddrIPv4;
+    } else {
+        // unreachable
+    }
+
+    int bindResult = QT_SOCKET_BIND(socketDescriptor, sockAddrPtr, sockAddrSize);
+    if (bindResult < 0) {
+        switch(errno) {
+        case EADDRINUSE:
+            setError(QAbstractSocket::AddressInUseError, AddressInuseErrorString);
+            break;
+        case EACCES:
+            setError(QAbstractSocket::SocketAccessError, AddressProtectedErrorString);
+            break;
+        case EINVAL:
+            setError(QAbstractSocket::UnsupportedSocketOperationError, OperationUnsupportedErrorString);
+            break;
+        case EADDRNOTAVAIL:
+            setError(QAbstractSocket::SocketAddressNotAvailableError, AddressNotAvailableErrorString);
+            break;
+        default:
+            break;
+        }
+
+#if defined (QNATIVESOCKETENGINE_DEBUG)
+        qDebug("QNativeSocketEnginePrivate::nativeBind(%s, %i) == false (%s)",
+               address.toString().toLatin1().constData(), port, socketErrorString.toLatin1().constData());
+#endif
+
+        return false;
+    }
+
+#if defined (QNATIVESOCKETENGINE_DEBUG)
+    qDebug("QNativeSocketEnginePrivate::nativeBind(%s, %i) == true",
+           address.toString().toLatin1().constData(), port);
+#endif
+    socketState = QAbstractSocket::BoundState;
+    return true;
+}
+
+bool QNativeSocketEnginePrivate::nativeListen(int backlog)
+{
+    if (qt_socket_listen(socketDescriptor, backlog) < 0) {
+        switch (errno) {
+        case EADDRINUSE:
+            setError(QAbstractSocket::AddressInUseError,
+                     PortInuseErrorString);
+            break;
+        default:
+            break;
+        }
+
+#if defined (QNATIVESOCKETENGINE_DEBUG)
+        qDebug("QNativeSocketEnginePrivate::nativeListen(%i) == false (%s)",
+               backlog, socketErrorString.toLatin1().constData());
+#endif
+        return false;
+    }
+
+#if defined (QNATIVESOCKETENGINE_DEBUG)
+    qDebug("QNativeSocketEnginePrivate::nativeListen(%i) == true", backlog);
+#endif
+
+    socketState = QAbstractSocket::ListeningState;
+    return true;
+}
+
+int QNativeSocketEnginePrivate::nativeAccept()
+{
+    int acceptedDescriptor = qt_socket_accept(socketDescriptor, 0, 0);
+#if defined (QNATIVESOCKETENGINE_DEBUG)
+    qDebug("QNativeSocketEnginePrivate::nativeAccept() == %i", acceptedDescriptor);
+#endif
+    // Ensure that the socket is closed on exec*()
+    ::fcntl(acceptedDescriptor, F_SETFD, FD_CLOEXEC);
+    return acceptedDescriptor;
+}
+
+qint64 QNativeSocketEnginePrivate::nativeBytesAvailable() const
+{
+    /*
+      Apparently, there is not consistency among different operating
+      systems on how to use FIONREAD.
+
+      FreeBSD, Linux and Solaris all expect the 3rd argument to
+      ioctl() to be an int, which is normally 32-bit even on 64-bit
+      machines.
+
+      IRIX, on the other hand, expects a size_t, which is 64-bit on
+      64-bit machines.
+
+      So, the solution is to use size_t initialized to zero to make
+      sure all bits are set to zero, preventing underflow with the
+      FreeBSD/Linux/Solaris ioctls.
+    */
+    size_t nbytes = 0;
+    // gives shorter than true amounts on Unix domain sockets.
+    qint64 available = 0;
+    if (::ioctl(socketDescriptor, FIONREAD, (char *) &nbytes) >= 0)
+        available = (qint64) *((int *) &nbytes);
+
+#if defined (QNATIVESOCKETENGINE_DEBUG)
+    qDebug("QNativeSocketEnginePrivate::nativeBytesAvailable() == %lli", available);
+#endif
+    return available;
+}
+
+bool QNativeSocketEnginePrivate::nativeHasPendingDatagrams() const
+{
+    // Create a sockaddr struct and reset its port number.
+    struct sockaddr storage;
+    sockaddr *storagePtr = reinterpret_cast<sockaddr *>(&storage);
+    storagePtr->sa_family = 0;
+
+    sockaddr_in *storagePtrIPv4 = reinterpret_cast<sockaddr_in *>(&storage);
+    storagePtrIPv4->sin_port = 0;
+    QT_SOCKLEN_T storageSize = sizeof(storage);
+
+    // Peek 0 bytes into the next message. The size of the message may
+    // well be 0, so we can't check recvfrom's return value.
+    ssize_t readBytes;
+    do {
+        char c;
+        readBytes = ::recvfrom(socketDescriptor, &c, 1, MSG_PEEK, storagePtr, &storageSize);
+    } while (readBytes == -1 && errno == EINTR);
+
+    // If there's no error, or if our buffer was too small, there must be a
+    // pending datagram.
+    bool result = (readBytes != -1) || errno == EMSGSIZE;
+
+#if defined (QNATIVESOCKETENGINE_DEBUG)
+    qDebug("QNativeSocketEnginePrivate::nativeHasPendingDatagrams() == %s",
+           result ? "true" : "false");
+#endif
+    return result;
+}
+
+qint64 QNativeSocketEnginePrivate::nativePendingDatagramSize() const
+{
+    QVarLengthArray<char, 8192> udpMessagePeekBuffer(8192);
+    ssize_t recvResult = -1;
+    for (;;) {
+        // the data written to udpMessagePeekBuffer is discarded, so
+        // this function is still reentrant although it might not look
+        // so.
+        recvResult = ::recv(socketDescriptor, udpMessagePeekBuffer.data(),
+                            udpMessagePeekBuffer.size(), MSG_PEEK);
+        if (recvResult == -1 && errno == EINTR)
+            continue;
+
+        if (recvResult != (ssize_t) udpMessagePeekBuffer.size())
+            break;
+
+        udpMessagePeekBuffer.resize(udpMessagePeekBuffer.size() * 2);
+    }
+
+#if defined (QNATIVESOCKETENGINE_DEBUG)
+    qDebug("QNativeSocketEnginePrivate::nativePendingDatagramSize() == %i", recvResult);
+#endif
+
+    return qint64(recvResult);
+}
+
+qint64 QNativeSocketEnginePrivate::nativeReceiveDatagram(char *data, qint64 maxSize,
+                                                    QHostAddress *address, quint16 *port)
+{
+    struct sockaddr_in aa;
+    memset(&aa, 0, sizeof(aa));
+    QT_SOCKLEN_T sz;
+    sz = sizeof(aa);
+
+    ssize_t recvFromResult = 0;
+    do {
+        char c;
+        recvFromResult = ::recvfrom(socketDescriptor, maxSize ? data : &c, maxSize ? maxSize : 1,
+                                    0, (struct sockaddr *)&aa, &sz);
+    } while (recvFromResult == -1 && errno == EINTR);
+
+    if (recvFromResult == -1) {
+        setError(QAbstractSocket::NetworkError, ReceiveDatagramErrorString);
+    } else if (port || address) {
+        qt_socket_getPortAndAddress((struct sockaddr *) &aa, port, address);
+    }
+
+#if defined (QNATIVESOCKETENGINE_DEBUG)
+    qDebug("QNativeSocketEnginePrivate::nativeReceiveDatagram(%p \"%s\", %lli, %s, %i) == %lli",
+           data, qt_prettyDebug(data, qMin(recvFromResult, ssize_t(16)), recvFromResult).data(), maxSize,
+           address ? address->toString().toLatin1().constData() : "(nil)",
+           port ? *port : 0, (qint64) recvFromResult);
+#endif
+
+    return qint64(maxSize ? recvFromResult : recvFromResult == -1 ? -1 : 0);
+}
+
+qint64 QNativeSocketEnginePrivate::nativeSendDatagram(const char *data, qint64 len,
+                                                   const QHostAddress &host, quint16 port)
+{
+    struct sockaddr_in sockAddrIPv4;
+    struct sockaddr *sockAddrPtr = 0;
+    QT_SOCKLEN_T sockAddrSize = 0;
+
+    if (host.protocol() == QAbstractSocket::IPv4Protocol) {
+	memset(&sockAddrIPv4, 0, sizeof(sockAddrIPv4));
+	sockAddrIPv4.sin_family = AF_INET;
+	sockAddrIPv4.sin_port = htons(port);
+	sockAddrIPv4.sin_addr.s_addr = htonl(host.toIPv4Address());
+	sockAddrSize = sizeof(sockAddrIPv4);
+	sockAddrPtr = (struct sockaddr *)&sockAddrIPv4;
+    }
+
+    // ignore the SIGPIPE signal
+    qt_ignore_sigpipe();
+
+    ssize_t sentBytes;
+    do {
+        sentBytes = ::sendto(socketDescriptor, data, len,
+                             0, sockAddrPtr, sockAddrSize);
+    } while (sentBytes == -1 && errno == EINTR);
+
+    if (sentBytes < 0) {
+        switch (errno) {
+        case EMSGSIZE:
+            setError(QAbstractSocket::DatagramTooLargeError, DatagramTooLargeErrorString);
+            break;
+        default:
+            setError(QAbstractSocket::NetworkError, SendDatagramErrorString);
+        }
+    }
+
+#if defined (QNATIVESOCKETENGINE_DEBUG)
+    qDebug("QNativeSocketEngine::sendDatagram(%p \"%s\", %lli, \"%s\", %i) == %lli", data,
+           qt_prettyDebug(data, qMin<int>(len, 16), len).data(), len, host.toString().toLatin1().constData(),
+           port, (qint64) sentBytes);
+#endif
+
+    return qint64(sentBytes);
+}
+
+bool QNativeSocketEnginePrivate::fetchConnectionParameters()
+{
+    localPort = 0;
+    localAddress.clear();
+    peerPort = 0;
+    peerAddress.clear();
+
+    if (socketDescriptor == -1)
+        return false;
+
+    struct sockaddr_in sa;
+    struct sockaddr *sockAddrPtr = (struct sockaddr *) &sa;
+    QT_SOCKLEN_T sockAddrSize = sizeof(sa);
+
+    // Determine local address
+    memset(&sa, 0, sizeof(sa));
+    if (::getsockname(socketDescriptor, sockAddrPtr, &sockAddrSize) == 0) {
+        qt_socket_getPortAndAddress(sockAddrPtr, &localPort, &localAddress);
+
+        // Determine protocol family
+        switch (sockAddrPtr->sa_family) {
+        case AF_INET:
+            socketProtocol = QAbstractSocket::IPv4Protocol;
+            break;
+        default:
+            socketProtocol = QAbstractSocket::UnknownNetworkLayerProtocol;
+            break;
+        }
+
+    } else if (errno == EBADF) {
+        setError(QAbstractSocket::UnsupportedSocketOperationError, InvalidSocketErrorString);
+        return false;
+    }
+
+    // Determine the remote address
+    if (!::getpeername(socketDescriptor, sockAddrPtr, &sockAddrSize))
+        qt_socket_getPortAndAddress(sockAddrPtr, &peerPort, &peerAddress);
+
+    // Determine the socket type (UDP/TCP)
+    int value = 0;
+    QT_SOCKOPTLEN_T valueSize = sizeof(int);
+    if (::getsockopt(socketDescriptor, SOL_SOCKET, SO_TYPE, &value, &valueSize) == 0) {
+        if (value == SOCK_STREAM)
+            socketType = QAbstractSocket::TcpSocket;
+        else if (value == SOCK_DGRAM)
+            socketType = QAbstractSocket::UdpSocket;
+        else
+            socketType = QAbstractSocket::UnknownSocketType;
+    }
+#if defined (QNATIVESOCKETENGINE_DEBUG)
+    QString socketProtocolStr = "UnknownProtocol";
+    if (socketProtocol == QAbstractSocket::IPv4Protocol) socketProtocolStr = "IPv4Protocol";
+    else if (socketProtocol == QAbstractSocket::IPv6Protocol) socketProtocolStr = "IPv6Protocol";
+
+    QString socketTypeStr = "UnknownSocketType";
+    if (socketType == QAbstractSocket::TcpSocket) socketTypeStr = "TcpSocket";
+    else if (socketType == QAbstractSocket::UdpSocket) socketTypeStr = "UdpSocket";
+
+    qDebug("QNativeSocketEnginePrivate::fetchConnectionParameters() local == %s:%i,"
+           " peer == %s:%i, socket == %s - %s",
+           localAddress.toString().toLatin1().constData(), localPort,
+           peerAddress.toString().toLatin1().constData(), peerPort,socketTypeStr.toLatin1().constData(),
+           socketProtocolStr.toLatin1().constData());
+#endif
+    return true;
+}
+
+void QNativeSocketEnginePrivate::nativeClose()
+{
+#if defined (QNATIVESOCKETENGINE_DEBUG)
+    qDebug("QNativeSocketEngine::nativeClose()");
+#endif
+    ::close(socketDescriptor);
+}
+
+qint64 QNativeSocketEnginePrivate::nativeWrite(const char *data, qint64 len)
+{
+    Q_Q(QNativeSocketEngine);
+
+    // ignore the SIGPIPE signal
+    qt_ignore_sigpipe();
+
+    // loop while ::write() returns -1 and errno == EINTR, in case
+    // of an interrupting signal.
+    ssize_t writtenBytes;
+    do {
+        writtenBytes = ::write(socketDescriptor, data, len);
+    } while (writtenBytes < 0 && errno == EINTR);
+
+    if (writtenBytes < 0) {
+        switch (errno) {
+        case EPIPE:
+        case ECONNRESET:
+            writtenBytes = -1;
+            setError(QAbstractSocket::RemoteHostClosedError, RemoteHostClosedErrorString);
+            q->close();
+            break;
+        case EAGAIN:
+            writtenBytes = 0;
+            break;
+        case EMSGSIZE:
+            setError(QAbstractSocket::DatagramTooLargeError, DatagramTooLargeErrorString);
+            break;
+        default:
+            break;
+        }
+    }
+
+#if defined (QNATIVESOCKETENGINE_DEBUG)
+    qDebug("QNativeSocketEnginePrivate::nativeWrite(%p \"%s\", %llu) == %i",
+           data, qt_prettyDebug(data, qMin((int) len, 16),
+                                (int) len).data(), len, (int) writtenBytes);
+#endif
+
+    return qint64(writtenBytes);
+}
+/*
+*/
+qint64 QNativeSocketEnginePrivate::nativeRead(char *data, qint64 maxSize)
+{
+    Q_Q(QNativeSocketEngine);
+    if (!q->isValid()) {
+        qWarning("QNativeSocketEngine::unbufferedRead: Invalid socket");
+        return -1;
+    }
+
+    ssize_t r = 0;
+    do {
+        r = ::read(socketDescriptor, data, maxSize);
+    } while (r == -1 && errno == EINTR);
+
+    if (r < 0) {
+        r = -1;
+        switch (errno) {
+#if EWOULDBLOCK-0 && EWOULDBLOCK != EAGAIN
+        case EWOULDBLOCK:
+#endif
+        case EAGAIN:
+            // No data was available for reading
+            r = -2;
+            break;
+        case EBADF:
+        case EINVAL:
+        case EIO:
+            setError(QAbstractSocket::NetworkError, ReadErrorString);
+            break;
+        case ECONNRESET:
+            r = 0;
+            break;
+        default:
+            break;
+        }
+    }
+
+#if defined (QNATIVESOCKETENGINE_DEBUG)
+    qDebug("QNativeSocketEnginePrivate::nativeRead(%p \"%s\", %llu) == %i",
+           data, qt_prettyDebug(data, qMin(r, ssize_t(16)), r).data(),
+           maxSize, r);
+#endif
+
+    return qint64(r);
+}
+
+int QNativeSocketEnginePrivate::nativeSelect(int timeout, bool selectForRead) const
+{
+    fd_set fds;
+    FD_ZERO(&fds);
+    FD_SET(socketDescriptor, &fds);
+
+    struct timeval tv;
+    tv.tv_sec = timeout / 1000;
+    tv.tv_usec = (timeout % 1000) * 1000;
+
+    QTime timer;
+    timer.start();
+
+    int retval;
+    do {
+        if (selectForRead)
+            retval = select(socketDescriptor + 1, &fds, 0, 0, timeout < 0 ? 0 : &tv);
+        else
+            retval = select(socketDescriptor + 1, 0, &fds, 0, timeout < 0 ? 0 : &tv);
+
+        if (retval != -1 || errno != EINTR)
+            break;
+
+        if (timeout > 0) {
+            // recalculate the timeout
+            int t = timeout - timer.elapsed();
+            if (t < 0) {
+                // oops, timeout turned negative?
+                retval = -1;
+                break;
+            }
+
+            tv.tv_sec = t / 1000;
+            tv.tv_usec = (t % 1000) * 1000;
+        }
+    } while (true);
+
+    return retval;
+}
+
+int QNativeSocketEnginePrivate::nativeSelect(int timeout, bool checkRead, bool checkWrite,
+				      bool *selectForRead, bool *selectForWrite) const
+{
+    fd_set fdread;
+    FD_ZERO(&fdread);
+    if (checkRead)
+        FD_SET(socketDescriptor, &fdread);
+
+    fd_set fdwrite;
+    FD_ZERO(&fdwrite);
+    if (checkWrite)
+        FD_SET(socketDescriptor, &fdwrite);
+
+    struct timeval tv;
+    tv.tv_sec = timeout / 1000;
+    tv.tv_usec = (timeout % 1000) * 1000;
+
+    QTime timer;
+    timer.start();
+
+    int ret;
+    do {
+        ret = select(socketDescriptor + 1, &fdread, &fdwrite, 0, timeout < 0 ? 0 : &tv);
+        if (ret != -1 || errno != EINTR)
+            break;
+
+        if (timeout > 0) {
+            // recalculate the timeout
+            int t = timeout - timer.elapsed();
+            if (t < 0) {
+                // oops, timeout turned negative?
+                ret = -1;
+                break;
+            }
+
+            tv.tv_sec = t / 1000;
+            tv.tv_usec = (t % 1000) * 1000;
+        }
+    } while (true);
+    if (ret <= 0)
+        return ret;
+
+    *selectForRead = FD_ISSET(socketDescriptor, &fdread);
+    *selectForWrite = FD_ISSET(socketDescriptor, &fdwrite);
+    return ret;
+}
+
+QT_END_NAMESPACE
Index: /trunk/src/network/socket/socket.pri
===================================================================
--- /trunk/src/network/socket/socket.pri	(revision 156)
+++ /trunk/src/network/socket/socket.pri	(revision 157)
@@ -35,4 +35,8 @@
                 socket/qlocalserver_win.cpp
 
+os2:SOURCES += socket/qnativesocketengine_os2.cpp \
+               socket/qlocalsocket_os2.cpp \
+               socket/qlocalserver_os2.cpp
+
 wince*: {
     SOURCES -= socket/qlocalsocket_win.cpp \
