diff options
author | Shane Kearns <shane.kearns@accenture.com> | 2011-02-17 13:27:45 (GMT) |
---|---|---|
committer | Shane Kearns <shane.kearns@accenture.com> | 2011-02-17 13:39:08 (GMT) |
commit | 44ef44bc3826c78a10bcf02d3357bf6332c6c3ed (patch) | |
tree | 53053bdacc56009825ab24d3ed313390a9a40d4f /src/network/socket | |
parent | 42adaaa0dffa9df387a145181bc97ee3bb9a4c7b (diff) | |
download | Qt-44ef44bc3826c78a10bcf02d3357bf6332c6c3ed.zip Qt-44ef44bc3826c78a10bcf02d3357bf6332c6c3ed.tar.gz Qt-44ef44bc3826c78a10bcf02d3357bf6332c6c3ed.tar.bz2 |
Explicit network session for QNetworkAccessManager
Implemented a tunnel to get the QNetworkSession from QNetworkAccessManager
down to the socket engine. This is currently a private API for QNAM.
This patch only implements the FTP backend - the other backends are to
follow.
On Symbian, the native socket engine will extract the native session
(RConnection) from the QNetworkSession implementation, and use that to
open sockets using the explicitly specified session.
When no session is specified on the socket (default for networking usage
outside of QNAM) then the socket is opened with no RConnection specified,
which allows the IP stack to find any route via an open interface.
The QFtp autotest is enhanced to test QFtp with an explicit session as well
as implicit connectivity (where a QNetworkSession is opened by the user,
and then QFtp is used without a specified connection).
This autotest gives better coverage than the FTP test cases in QNetworkReply.
Reviewed-by: Markus Goetz
Diffstat (limited to 'src/network/socket')
-rw-r--r-- | src/network/socket/qabstractsocket.cpp | 8 | ||||
-rw-r--r-- | src/network/socket/qsymbiansocketengine.cpp | 31 | ||||
-rw-r--r-- | src/network/socket/qsymbiansocketengine_p.h | 5 | ||||
-rw-r--r-- | src/network/socket/qtcpserver.cpp | 8 |
4 files changed, 43 insertions, 9 deletions
diff --git a/src/network/socket/qabstractsocket.cpp b/src/network/socket/qabstractsocket.cpp index 3462538..af5f027 100644 --- a/src/network/socket/qabstractsocket.cpp +++ b/src/network/socket/qabstractsocket.cpp @@ -546,6 +546,10 @@ bool QAbstractSocketPrivate::initSocketLayer(QAbstractSocket::NetworkLayerProtoc resetSocketLayer(); socketEngine = QAbstractSocketEngine::createSocketEngine(q->socketType(), proxyInUse, q); +#ifndef QT_NO_BEARERMANAGEMENT + //copy network session down to the socket engine (if it has been set) + socketEngine->setProperty("_q_networksession", q->property("_q_networksession")); +#endif if (!socketEngine) { socketError = QAbstractSocket::UnsupportedSocketOperationError; q->setErrorString(QAbstractSocket::tr("Operation on socket is not supported")); @@ -1600,6 +1604,10 @@ bool QAbstractSocket::setSocketDescriptor(int socketDescriptor, SocketState sock d->resetSocketLayer(); d->socketEngine = QAbstractSocketEngine::createSocketEngine(socketDescriptor, this); +#ifndef QT_NO_BEARERMANAGEMENT + //copy network session down to the socket engine (if it has been set) + d->socketEngine->setProperty("_q_networksession", property("_q_networksession")); +#endif if (!d->socketEngine) { d->socketError = UnsupportedSocketOperationError; setErrorString(tr("Operation on socket is not supported")); diff --git a/src/network/socket/qsymbiansocketengine.cpp b/src/network/socket/qsymbiansocketengine.cpp index d6b893a..b9537c1 100644 --- a/src/network/socket/qsymbiansocketengine.cpp +++ b/src/network/socket/qsymbiansocketengine.cpp @@ -47,6 +47,7 @@ #include "qelapsedtimer.h" #include "qvarlengtharray.h" #include "qnetworkinterface.h" +#include "qnetworksession_p.h" #include <es_sock.h> #include <in_sock.h> #include <net/if.h> @@ -186,10 +187,26 @@ bool QSymbianSocketEnginePrivate::createNewSocket(QAbstractSocket::SocketType so TUint family = KAfInet; // KAfInet6 is only used as an address family, not as a protocol family TUint type = (socketType == QAbstractSocket::UdpSocket) ? KSockDatagram : KSockStream; TUint protocol = (socketType == QAbstractSocket::UdpSocket) ? KProtocolInetUdp : KProtocolInetTcp; + + //Check if there is a user specified session + RConnection *connection = 0; + QVariant v(q->property("_q_networksession")); + if (v.isValid()) { + QSharedPointer<QNetworkSession> s = qvariant_cast<QSharedPointer<QNetworkSession> >(v); + connection = QNetworkSessionPrivate::nativeSession(*s); +#ifdef QNATIVESOCKETENGINE_DEBUG + qDebug() << "QSymbianSocketEnginePrivate::createNewSocket - _q_networksession was set" << connection; +#endif + } TInt err; -// if (connection) -// err = nativeSocket.Open(socketServer, family, type, protocol, *connection); -// else + if (connection) { + if (connection->SubSessionHandle()) + err = nativeSocket.Open(socketServer, family, type, protocol, *connection); + else { + setError(QAbstractSocket::NetworkError, SessionNotOpenErrorString); + return false; + } + } else err = nativeSocket.Open(socketServer, family, type, protocol); //TODO: FIXME - deprecated API, make sure we always have a connection instead if (err != KErrNone) { @@ -246,7 +263,6 @@ void QSymbianSocketEnginePrivate::setPortAndAddress(TInetAddr& nativeAddr, quint QSymbianSocketEnginePrivate::QSymbianSocketEnginePrivate() : socketDescriptor(-1), socketServer(QSymbianSocketManager::instance().getSocketServer()), - connection(QSymbianSocketManager::instance().defaultConnection()), readNotifier(0), writeNotifier(0), exceptNotifier(0), @@ -1330,9 +1346,12 @@ void QSymbianSocketEnginePrivate::setError(QAbstractSocket::SocketError error, E case InvalidProxyTypeString: socketErrorString = QSymbianSocketEngine::tr("The proxy type is invalid for this operation"); break; - case InvalidAddressError: + case InvalidAddressErrorString: socketErrorString = QSymbianSocketEngine::tr("The address is invalid for this operation"); break; + case SessionNotOpenErrorString: + socketErrorString = QSymbianSocketEngine::tr("The specified network session is not opened"); + break; case UnknownSocketErrorString: socketErrorString = QSymbianSocketEngine::tr("Unknown error"); break; @@ -1378,7 +1397,7 @@ void QSymbianSocketEnginePrivate::setError(TInt symbianError) setError(QAbstractSocket::NetworkError, ConnectionTimeOutErrorString); break; case KErrBadName: - setError(QAbstractSocket::NetworkError, InvalidAddressError); + setError(QAbstractSocket::NetworkError, InvalidAddressErrorString); break; default: socketError = QAbstractSocket::NetworkError; diff --git a/src/network/socket/qsymbiansocketengine_p.h b/src/network/socket/qsymbiansocketengine_p.h index a2904ae..bc39450 100644 --- a/src/network/socket/qsymbiansocketengine_p.h +++ b/src/network/socket/qsymbiansocketengine_p.h @@ -196,8 +196,6 @@ public: mutable RSocket nativeSocket; // From QtCore: RSocketServ& socketServer; - // From QtCore, check lifetime issues, also should be pulling this out of a QNetworkSession somehow: - RConnection *connection; mutable RTimer selectTimer; QSocketNotifier *readNotifier, *writeNotifier, *exceptNotifier; @@ -231,7 +229,8 @@ public: NotSocketErrorString, InvalidProxyTypeString, //symbian specific - InvalidAddressError, + InvalidAddressErrorString, + SessionNotOpenErrorString, UnknownSocketErrorString = -1 }; diff --git a/src/network/socket/qtcpserver.cpp b/src/network/socket/qtcpserver.cpp index e382830..6b012db 100644 --- a/src/network/socket/qtcpserver.cpp +++ b/src/network/socket/qtcpserver.cpp @@ -287,6 +287,10 @@ bool QTcpServer::listen(const QHostAddress &address, quint16 port) delete d->socketEngine; d->socketEngine = QAbstractSocketEngine::createSocketEngine(QAbstractSocket::TcpSocket, proxy, this); +#ifndef QT_NO_BEARERMANAGEMENT + //copy network session down to the socket engine (if it has been set) + d->socketEngine->setProperty("_q_networksession", property("_q_networksession")); +#endif if (!d->socketEngine) { d->serverSocketError = QAbstractSocket::UnsupportedSocketOperationError; d->serverSocketErrorString = tr("Operation on socket is not supported"); @@ -412,6 +416,10 @@ bool QTcpServer::setSocketDescriptor(int socketDescriptor) if (d->socketEngine) delete d->socketEngine; d->socketEngine = QAbstractSocketEngine::createSocketEngine(socketDescriptor, this); +#ifndef QT_NO_BEARERMANAGEMENT + //copy network session down to the socket engine (if it has been set) + d->socketEngine->setProperty("_q_networksession", property("_q_networksession")); +#endif if (!d->socketEngine->initialize(socketDescriptor, QAbstractSocket::ListeningState)) { d->serverSocketError = d->socketEngine->error(); d->serverSocketErrorString = d->socketEngine->errorString(); |