summaryrefslogtreecommitdiffstats
path: root/src/corelib/kernel
diff options
context:
space:
mode:
authorShane Kearns <shane.kearns@accenture.com>2010-12-06 12:36:13 (GMT)
committerShane Kearns <shane.kearns@accenture.com>2010-12-06 12:36:13 (GMT)
commitde55502a960a1044770aa840d7e443343b3c436b (patch)
tree945075881c1560dc8de0bf2d35fbe84a0df6885d /src/corelib/kernel
parent9470dfb8b116cde0d08670d05ded530bad264c6c (diff)
downloadQt-de55502a960a1044770aa840d7e443343b3c436b.zip
Qt-de55502a960a1044770aa840d7e443343b3c436b.tar.gz
Qt-de55502a960a1044770aa840d7e443343b3c436b.tar.bz2
Add socket manager to corelib
This class stores socket handles so they can be passed around as integers. Also, it owns the global RSocketServ used throughout the application. Reason for this not being in QtNetwork is that QtCore exports some socket related classes. Reviewed-by: Markus Goetz
Diffstat (limited to 'src/corelib/kernel')
-rw-r--r--src/corelib/kernel/qcore_symbian_p.cpp27
-rw-r--r--src/corelib/kernel/qcore_symbian_p.h34
2 files changed, 48 insertions, 13 deletions
diff --git a/src/corelib/kernel/qcore_symbian_p.cpp b/src/corelib/kernel/qcore_symbian_p.cpp
index 29996a4..809dc30 100644
--- a/src/corelib/kernel/qcore_symbian_p.cpp
+++ b/src/corelib/kernel/qcore_symbian_p.cpp
@@ -203,6 +203,11 @@ private:
RFs iFs;
};
+uint qHash(const RSubSessionBase& key)
+{
+ return qHash(key.SubSessionHandle());
+}
+
Q_GLOBAL_STATIC(QS60RFsSession, qt_s60_RFsSession);
Q_CORE_EXPORT RFs& qt_s60GetRFs()
@@ -229,7 +234,8 @@ RSocketServ& QSymbianSocketManager::getSocketServer() {
return iSocketServ;
}
-int QSymbianSocketManager::addSocket(RSocket* sock) {
+int QSymbianSocketManager::addSocket(const RSocket& socket) {
+ QHashableSocket sock(static_cast<const QHashableSocket &>(socket));
QMutexLocker l(&iMutex);
Q_ASSERT(!socketMap.contains(sock));
if(socketMap.contains(sock))
@@ -250,7 +256,8 @@ int QSymbianSocketManager::addSocket(RSocket* sock) {
return id + socket_offset;
}
-bool QSymbianSocketManager::removeSocket(RSocket* sock) {
+bool QSymbianSocketManager::removeSocket(const RSocket &socket) {
+ QHashableSocket sock(static_cast<const QHashableSocket &>(socket));
QMutexLocker l(&iMutex);
if(!socketMap.contains(sock))
return false;
@@ -260,7 +267,8 @@ bool QSymbianSocketManager::removeSocket(RSocket* sock) {
return true;
}
-int QSymbianSocketManager::lookupSocket(RSocket* sock) const {
+int QSymbianSocketManager::lookupSocket(const RSocket& socket) const {
+ QHashableSocket sock(static_cast<const QHashableSocket &>(socket));
QMutexLocker l(&iMutex);
if(!socketMap.contains(sock))
return -1;
@@ -268,12 +276,13 @@ int QSymbianSocketManager::lookupSocket(RSocket* sock) const {
return id + socket_offset;
}
-RSocket* QSymbianSocketManager::lookupSocket(int fd) const {
+bool QSymbianSocketManager::lookupSocket(int fd, RSocket& socket) const {
QMutexLocker l(&iMutex);
int id = fd + socket_offset;
if(!reverseSocketMap.contains(id))
- return 0;
- return reverseSocketMap.value(id);
+ return false;
+ socket = reverseSocketMap.value(id);
+ return true;
}
Q_GLOBAL_STATIC(QSymbianSocketManager, qt_symbianSocketManager);
@@ -282,4 +291,10 @@ QSymbianSocketManager& QSymbianSocketManager::instance()
{
return *(qt_symbianSocketManager());
}
+
+Q_CORE_EXPORT RSocketServ& qt_symbianGetSocketServer()
+{
+ return QSymbianSocketManager::instance().getSocketServer();
+}
+
QT_END_NAMESPACE
diff --git a/src/corelib/kernel/qcore_symbian_p.h b/src/corelib/kernel/qcore_symbian_p.h
index b6cba6e..8ffa247 100644
--- a/src/corelib/kernel/qcore_symbian_p.h
+++ b/src/corelib/kernel/qcore_symbian_p.h
@@ -161,6 +161,25 @@ Q_CORE_EXPORT RSocketServ& qt_symbianGetSocketServer();
// Defined in qlocale_symbian.cpp.
Q_CORE_EXPORT QByteArray qt_symbianLocaleName(int code);
+//Wrapper for RSocket so it can be used as a key in QHash or QMap
+class QHashableSocket : public RSocket
+{
+public:
+ bool operator==(const QHashableSocket &other) const
+ {
+ return SubSessionHandle() == other.SubSessionHandle()
+ && Session().Handle() == other.Session().Handle();
+ }
+ bool operator<(const QHashableSocket &other) const
+ {
+ if(Session().Handle() == other.Session().Handle())
+ return SubSessionHandle() < other.SubSessionHandle();
+ return Session().Handle() < other.Session().Handle();
+ }
+};
+
+uint qHash(const RSubSessionBase& key);
+
/*!
\internal
This class exists in QtCore for the benefit of QSocketNotifier, which uses integer
@@ -185,28 +204,29 @@ public:
\param an open socket
\return pseudo file descriptor, -1 if out of resources
*/
- int addSocket(RSocket *sock);
+ int addSocket(const RSocket &sock);
/*!
\internal
Removes a symbian socket from the global map
\param an open socket
\return true if the socket was in the map
*/
- bool removeSocket(RSocket *sock);
+ bool removeSocket(const RSocket &sock);
/*!
\internal
Get pseudo file descriptor for a socket
\param an open socket
\return integer handle, or -1 if not in map
*/
- int lookupSocket(RSocket *sock) const;
+ int lookupSocket(const RSocket &sock) const;
/*!
\internal
Get socket for a pseudo file descriptor
\param an open socket fd
- \return socket handle or NULL if not in map
+ \param sock (out) socket handle
+ \return true on success or false if not in map
*/
- RSocket *lookupSocket(int fd) const;
+ bool lookupSocket(int fd, RSocket& sock) const;
/*!
\internal
@@ -219,8 +239,8 @@ private:
const static int max_sockets = 0x20000; //covers all TCP and UDP ports, probably run out of memory first
const static int socket_offset = 0x40000000; //hacky way of separating sockets from file descriptors
int iNextSocket;
- QHash<RSocket *, int> socketMap;
- QHash<int, RSocket *> reverseSocketMap;
+ QHash<QHashableSocket, int> socketMap;
+ QHash<int, RSocket> reverseSocketMap;
mutable QMutex iMutex;
RSocketServ iSocketServ;
};