From 0679abb6b4f85878cb64fce2089ba926e3b9400c Mon Sep 17 00:00:00 2001 From: Shane Kearns Date: Fri, 18 Mar 2011 11:30:35 +0000 Subject: handle errors in QSymbianHostResolver::requestHostLookup It was hanging because although the error flags were set, the callback was not emitted and nothing was done with the return value from the function. Now, it sets the state to error, and self completes - so that the completion through RunL is used as normal. Because the state is error, the processing of name/address is skipped and the error string is not rewritten. Note, error being detected at this point is only common when using an explicit network session (as RHostResolver::Open can fail if the RConnection is in the wrong state) Reviewed-by: Markus Goetz --- src/network/kernel/qhostinfo_p.h | 5 ++- src/network/kernel/qhostinfo_symbian.cpp | 64 +++++++++++++++++--------------- 2 files changed, 38 insertions(+), 31 deletions(-) diff --git a/src/network/kernel/qhostinfo_p.h b/src/network/kernel/qhostinfo_p.h index 79fad84..909bd03 100644 --- a/src/network/kernel/qhostinfo_p.h +++ b/src/network/kernel/qhostinfo_p.h @@ -228,7 +228,7 @@ public: QSymbianHostResolver(const QString &hostName, int id); ~QSymbianHostResolver(); - QHostInfo requestHostLookup(); + void requestHostLookup(); int id(); QHostInfoResult resultEmitter; @@ -258,7 +258,8 @@ private: enum { EIdle, EGetByName, - EGetByAddress + EGetByAddress, + EError } iState; }; diff --git a/src/network/kernel/qhostinfo_symbian.cpp b/src/network/kernel/qhostinfo_symbian.cpp index ad5f38a..54ec33c 100644 --- a/src/network/kernel/qhostinfo_symbian.cpp +++ b/src/network/kernel/qhostinfo_symbian.cpp @@ -233,7 +233,7 @@ QSymbianHostResolver::~QSymbianHostResolver() } // Async equivalent to QHostInfoAgent::fromName() -QHostInfo QSymbianHostResolver::requestHostLookup() +void QSymbianHostResolver::requestHostLookup() { #if defined(QHOSTINFO_DEBUG) @@ -245,45 +245,51 @@ QHostInfo QSymbianHostResolver::requestHostLookup() if (err) { // What are we doing with iResults?? iResults.setError(QHostInfo::UnknownError); - iResults.setErrorString(QObject::tr("Symbian error code: %1").arg(err)); + iResults.setErrorString(QSystemError(err, QSystemError::NativeError).toString()); - iHostResolver.Close(); - return iResults; - } + } else { - if (iAddress.setAddress(iHostName)) { - // Reverse lookup + if (iAddress.setAddress(iHostName)) { + // Reverse lookup - TInetAddr IpAdd; - IpAdd.Input(qt_QString2TPtrC(iHostName)); + TInetAddr IpAdd; + IpAdd.Input(qt_QString2TPtrC(iHostName)); - // Asynchronous request. - iHostResolver.GetByAddress(IpAdd, iNameResult, iStatus); // <---- ASYNC - iState = EGetByAddress; + // Asynchronous request. + iHostResolver.GetByAddress(IpAdd, iNameResult, iStatus); // <---- ASYNC + iState = EGetByAddress; - } else { + } else { - // IDN support - QByteArray aceHostname = QUrl::toAce(iHostName); - iResults.setHostName(iHostName); - if (aceHostname.isEmpty()) { - iResults.setError(QHostInfo::HostNotFound); - iResults.setErrorString(iHostName.isEmpty() ? - QCoreApplication::translate("QHostInfoAgent", "No host name given") : - QCoreApplication::translate("QHostInfoAgent", "Invalid hostname")); + // IDN support + QByteArray aceHostname = QUrl::toAce(iHostName); + iResults.setHostName(iHostName); + if (aceHostname.isEmpty()) { + iResults.setError(QHostInfo::HostNotFound); + iResults.setErrorString(iHostName.isEmpty() ? + QCoreApplication::translate("QHostInfoAgent", "No host name given") : + QCoreApplication::translate("QHostInfoAgent", "Invalid hostname")); - iHostResolver.Close(); - return iResults; - } + err = KErrArgument; + } else { - // Asynchronous request. - iHostResolver.GetByName(qt_QString2TPtrC(QString::fromLatin1(aceHostname)), iNameResult, iStatus); - iState = EGetByName; + // Asynchronous request. + iHostResolver.GetByName(qt_QString2TPtrC(QString::fromLatin1(aceHostname)), iNameResult, iStatus); + iState = EGetByName; + } + } } - SetActive(); + if (err) { + iHostResolver.Close(); - return iResults; + //self complete so that RunL can inform manager without causing recursion + iState = EError; + iStatus = KRequestPending; + SetActive(); + TRequestStatus* stat = &iStatus; + User::RequestComplete(stat, err); + } } void QSymbianHostResolver::DoCancel() -- cgit v0.12