summaryrefslogtreecommitdiffstats
path: root/src/network
diff options
context:
space:
mode:
Diffstat (limited to 'src/network')
-rw-r--r--src/network/access/qnetworkreplyimpl.cpp10
-rw-r--r--src/network/network.pro3
-rw-r--r--src/network/socket/qabstractsocket.cpp16
-rw-r--r--src/network/socket/qsymbiansocketengine.cpp70
-rw-r--r--src/network/socket/qsymbiansocketengine_p.h2
-rw-r--r--src/network/socket/qtcpserver.cpp5
6 files changed, 79 insertions, 27 deletions
diff --git a/src/network/access/qnetworkreplyimpl.cpp b/src/network/access/qnetworkreplyimpl.cpp
index e50f3d627d..bf36ae8a4c 100644
--- a/src/network/access/qnetworkreplyimpl.cpp
+++ b/src/network/access/qnetworkreplyimpl.cpp
@@ -859,6 +859,8 @@ void QNetworkReplyImpl::abort()
if (d->state != QNetworkReplyImplPrivate::Finished) {
// call finished which will emit signals
d->error(OperationCanceledError, tr("Operation canceled"));
+ if (d->state == QNetworkReplyImplPrivate::WaitingForSession)
+ d->state = QNetworkReplyImplPrivate::Working;
d->finished();
}
d->state = QNetworkReplyImplPrivate::Aborted;
@@ -1018,10 +1020,6 @@ bool QNetworkReplyImplPrivate::migrateBackend()
if (state == Finished || state == Aborted)
return true;
- // Backend does not support resuming download.
- if (!backend->canResume())
- return false;
-
// Request has outgoing data, not migrating.
if (outgoingData)
return false;
@@ -1030,6 +1028,10 @@ bool QNetworkReplyImplPrivate::migrateBackend()
if (copyDevice)
return true;
+ // Backend does not support resuming download.
+ if (!backend->canResume())
+ return false;
+
state = QNetworkReplyImplPrivate::Reconnecting;
if (backend) {
diff --git a/src/network/network.pro b/src/network/network.pro
index fc5d08d936..4ee71b028e 100644
--- a/src/network/network.pro
+++ b/src/network/network.pro
@@ -19,6 +19,9 @@ win32-msvc*|win32-icc:QMAKE_LFLAGS += /BASE:0x64000000
unix|win32-g++*:QMAKE_PKGCONFIG_REQUIRES = QtCore
include(../qbase.pri)
+
+HEADERS += $$QT_SOURCE_TREE/src/network/qtnetworkversion.h
+
include(access/access.pri)
include(bearer/bearer.pri)
include(kernel/kernel.pri)
diff --git a/src/network/socket/qabstractsocket.cpp b/src/network/socket/qabstractsocket.cpp
index d8d263370d..fc0bb85a45 100644
--- a/src/network/socket/qabstractsocket.cpp
+++ b/src/network/socket/qabstractsocket.cpp
@@ -547,15 +547,15 @@ 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"));
return false;
}
+#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
#ifndef QT_NO_NETWORKPROXY
//copy user agent to socket engine (if it has been set)
socketEngine->setProperty("_q_user-agent", q->property("_q_user-agent"));
@@ -1609,15 +1609,15 @@ 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"));
return false;
}
+#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
bool result = d->socketEngine->initialize(socketDescriptor, socketState);
if (!result) {
d->socketError = d->socketEngine->error();
diff --git a/src/network/socket/qsymbiansocketengine.cpp b/src/network/socket/qsymbiansocketengine.cpp
index f1b2982626..b6d12fe3cc 100644
--- a/src/network/socket/qsymbiansocketengine.cpp
+++ b/src/network/socket/qsymbiansocketengine.cpp
@@ -251,7 +251,8 @@ QSymbianSocketEnginePrivate::QSymbianSocketEnginePrivate() :
readNotificationsEnabled(false),
writeNotificationsEnabled(false),
exceptNotificationsEnabled(false),
- asyncSelect(0)
+ asyncSelect(0),
+ hasReceivedBufferedDatagram(false)
{
}
@@ -781,21 +782,34 @@ qint64 QSymbianSocketEngine::pendingDatagramSize() const
Q_D(const QSymbianSocketEngine);
Q_CHECK_VALID_SOCKETLAYER(QSymbianSocketEngine::pendingDatagramSize(), false);
Q_CHECK_TYPE(QSymbianSocketEngine::hasPendingDatagrams(), QAbstractSocket::UdpSocket, false);
- int nbytes;
+ //can only buffer one datagram at a time
+ if (d->hasReceivedBufferedDatagram)
+ return d->receivedDataBuffer.size();
+ int nbytes = 0;
TInt err = d->nativeSocket.GetOpt(KSOReadBytesPending,KSOLSocket, nbytes);
if (nbytes > 0) {
//nbytes includes IP header, which is of variable length (IPv4 with or without options, IPv6...)
- QByteArray next(nbytes,0);
- TPtr8 buffer((TUint8*)next.data(), next.size());
+ //therefore read the datagram into a buffer to find its true size
+ d->receivedDataBuffer.resize(nbytes);
+ TPtr8 buffer((TUint8*)d->receivedDataBuffer.data(), nbytes);
+ //nbytes = size including IP header, buffer is a pointer descriptor backed by the receivedDataBuffer
TInetAddr addr;
TRequestStatus status;
- //TODO: rather than peek, should we save this for next call to readDatagram?
- //what if calls don't match though?
- d->nativeSocket.RecvFrom(buffer, addr, KSockReadPeek, status);
+ //RecvFrom copies only the payload (we don't want the header so don't specify the option to retrieve it)
+ d->nativeSocket.RecvFrom(buffer, addr, 0, status);
User::WaitForRequest(status);
- if (status.Int())
+ if (status != KErrNone) {
+ d->receivedDataBuffer.clear();
return 0;
- return buffer.Length();
+ }
+ nbytes = buffer.Length();
+ //nbytes = size of payload, resize the receivedDataBuffer to the final size
+ d->receivedDataBuffer.resize(nbytes);
+ d->hasReceivedBufferedDatagram = true;
+ //now receivedDataBuffer contains one datagram, which has been removed from the socket's internal buffer
+#if defined (QNATIVESOCKETENGINE_DEBUG)
+ qDebug() << "QSymbianSocketEngine::pendingDatagramSize buffering" << nbytes << "bytes";
+#endif
}
return qint64(nbytes);
}
@@ -807,6 +821,19 @@ qint64 QSymbianSocketEngine::readDatagram(char *data, qint64 maxSize,
Q_D(QSymbianSocketEngine);
Q_CHECK_VALID_SOCKETLAYER(QSymbianSocketEngine::readDatagram(), -1);
Q_CHECK_TYPE(QSymbianSocketEngine::readDatagram(), QAbstractSocket::UdpSocket, false);
+
+ // if a datagram was buffered in pendingDatagramSize(), return it now
+ if (d->hasReceivedBufferedDatagram) {
+ qint64 size = qMin(maxSize, (qint64)d->receivedDataBuffer.size());
+ memcpy(data, d->receivedDataBuffer.constData(), size);
+ d->receivedDataBuffer.clear();
+ d->hasReceivedBufferedDatagram = false;
+#if defined (QNATIVESOCKETENGINE_DEBUG)
+ qDebug() << "QSymbianSocketEngine::readDatagram returning" << size << "bytes from buffer";
+#endif
+ return size;
+ }
+
TPtr8 buffer((TUint8*)data, (int)maxSize);
TInetAddr addr;
TRequestStatus status;
@@ -985,6 +1012,9 @@ void QSymbianSocketEngine::close()
d->localAddress.clear();
d->peerPort = 0;
d->peerAddress.clear();
+
+ d->hasReceivedBufferedDatagram = false;
+ d->receivedDataBuffer.clear();
}
qint64 QSymbianSocketEngine::write(const char *data, qint64 len)
@@ -1036,6 +1066,18 @@ qint64 QSymbianSocketEngine::read(char *data, qint64 maxSize)
Q_CHECK_VALID_SOCKETLAYER(QSymbianSocketEngine::read(), -1);
Q_CHECK_STATES(QSymbianSocketEngine::read(), QAbstractSocket::ConnectedState, QAbstractSocket::BoundState, -1);
+ // if a datagram was buffered in pendingDatagramSize(), return it now
+ if (d->hasReceivedBufferedDatagram) {
+ qint64 size = qMin(maxSize, (qint64)d->receivedDataBuffer.size());
+ memcpy(data, d->receivedDataBuffer.constData(), size);
+ d->receivedDataBuffer.clear();
+ d->hasReceivedBufferedDatagram = false;
+#if defined (QNATIVESOCKETENGINE_DEBUG)
+ qDebug() << "QSymbianSocketEngine::read returning" << size << "bytes from buffer";
+#endif
+ return size;
+ }
+
TPtr8 buffer((TUint8*)data, (int)maxSize);
TSockXfrLength received = 0;
TRequestStatus status;
@@ -1440,6 +1482,7 @@ void QSymbianSocketEngine::startNotifications()
qDebug() << "QSymbianSocketEngine::startNotifications" << d->readNotificationsEnabled << d->writeNotificationsEnabled << d->exceptNotificationsEnabled;
#endif
if (!d->asyncSelect && (d->readNotificationsEnabled || d->writeNotificationsEnabled || d->exceptNotificationsEnabled)) {
+ Q_CHECK_VALID_SOCKETLAYER(QSymbianSocketEngine::startNotifications(), Q_VOID);
if (d->threadData->eventDispatcher) {
d->asyncSelect = q_check_ptr(new QAsyncSelect(
static_cast<QEventDispatcherSymbian*> (d->threadData->eventDispatcher), d->nativeSocket,
@@ -1456,14 +1499,12 @@ void QSymbianSocketEngine::startNotifications()
bool QSymbianSocketEngine::isReadNotificationEnabled() const
{
Q_D(const QSymbianSocketEngine);
- Q_CHECK_VALID_SOCKETLAYER(QSymbianSocketEngine::isReadNotificationEnabled(), false);
return d->readNotificationsEnabled;
}
void QSymbianSocketEngine::setReadNotificationEnabled(bool enable)
{
Q_D(QSymbianSocketEngine);
- Q_CHECK_VALID_SOCKETLAYER(QSymbianSocketEngine::setReadNotificationEnabled(), Q_VOID);
#ifdef QNATIVESOCKETENGINE_DEBUG
qDebug() << "QSymbianSocketEngine::setReadNotificationEnabled" << enable << "socket" << d->socketDescriptor;
#endif
@@ -1474,14 +1515,12 @@ void QSymbianSocketEngine::setReadNotificationEnabled(bool enable)
bool QSymbianSocketEngine::isWriteNotificationEnabled() const
{
Q_D(const QSymbianSocketEngine);
- Q_CHECK_VALID_SOCKETLAYER(QSymbianSocketEngine::isWriteNotificationEnabled(), false);
return d->writeNotificationsEnabled;
}
void QSymbianSocketEngine::setWriteNotificationEnabled(bool enable)
{
Q_D(QSymbianSocketEngine);
- Q_CHECK_VALID_SOCKETLAYER(QSymbianSocketEngine::setWriteNotificationEnabled(), Q_VOID);
#ifdef QNATIVESOCKETENGINE_DEBUG
qDebug() << "QSymbianSocketEngine::setWriteNotificationEnabled" << enable << "socket" << d->socketDescriptor;
#endif
@@ -1492,7 +1531,6 @@ void QSymbianSocketEngine::setWriteNotificationEnabled(bool enable)
bool QSymbianSocketEngine::isExceptionNotificationEnabled() const
{
Q_D(const QSymbianSocketEngine);
- Q_CHECK_VALID_SOCKETLAYER(QSymbianSocketEngine::isExceptionNotificationEnabled(), false);
return d->exceptNotificationsEnabled;
return false;
}
@@ -1500,7 +1538,6 @@ bool QSymbianSocketEngine::isExceptionNotificationEnabled() const
void QSymbianSocketEngine::setExceptionNotificationEnabled(bool enable)
{
Q_D(QSymbianSocketEngine);
- Q_CHECK_VALID_SOCKETLAYER(QSymbianSocketEngine::setExceptionNotificationEnabled(), Q_VOID);
#ifdef QNATIVESOCKETENGINE_DEBUG
qDebug() << "QSymbianSocketEngine::setExceptionNotificationEnabled" << enable << "socket" << d->socketDescriptor;
#endif
@@ -1660,6 +1697,9 @@ void QAsyncSelect::run()
//when event loop disabled socket events, defer until later
if (maybeDeferSocketEvent())
return;
+#if defined (QNATIVESOCKETENGINE_DEBUG)
+ qDebug() << "QAsyncSelect::run" << m_selectBuf() << m_selectFlags;
+#endif
m_inSocketEvent = true;
m_selectBuf() &= m_selectFlags; //the select ioctl reports everything, so mask to only what we requested
//KSockSelectReadContinuation is for reading datagrams in a mode that doesn't discard when the
diff --git a/src/network/socket/qsymbiansocketengine_p.h b/src/network/socket/qsymbiansocketengine_p.h
index 85ab54af12..2e7c155f3a 100644
--- a/src/network/socket/qsymbiansocketengine_p.h
+++ b/src/network/socket/qsymbiansocketengine_p.h
@@ -196,6 +196,8 @@ public:
bool exceptNotificationsEnabled;
QAsyncSelect* asyncSelect;
+ mutable QByteArray receivedDataBuffer;
+ mutable bool hasReceivedBufferedDatagram;
// FIXME this is duplicated from qnativesocketengine_p.h
enum ErrorString {
NonBlockingInitFailedErrorString,
diff --git a/src/network/socket/qtcpserver.cpp b/src/network/socket/qtcpserver.cpp
index 5a60764a3b..026ceb4932 100644
--- a/src/network/socket/qtcpserver.cpp
+++ b/src/network/socket/qtcpserver.cpp
@@ -416,6 +416,11 @@ bool QTcpServer::setSocketDescriptor(int socketDescriptor)
if (d->socketEngine)
delete d->socketEngine;
d->socketEngine = QAbstractSocketEngine::createSocketEngine(socketDescriptor, this);
+ if (!d->socketEngine) {
+ d->serverSocketError = QAbstractSocket::UnsupportedSocketOperationError;
+ d->serverSocketErrorString = tr("Operation on socket is not supported");
+ return false;
+ }
#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"));