diff options
author | Mirko Damiani <mirko@develer.com> | 2010-02-08 16:09:24 +0100 |
---|---|---|
committer | Andreas Aardal Hanssen <andreas.aardal.hanssen@nokia.com> | 2010-05-31 09:21:11 +0200 |
commit | 9b4ff3deb28b3d642dc4480207f2f23841cf26e9 (patch) | |
tree | 103e8f6b0639e85e0f9a0af7ca0d943e64c518fd /src/corelib/kernel/qsharedmemory_win.cpp | |
parent | 90abe364b7e9b0aa201a3e0ed0b043643519e21b (diff) |
Added native key support to QSharedMemory API.
Methods setNativeKey() and nativeKey() were added to
QSharedMemory API. Shared memory's native key is returned
by nativeKey() and it is set with either setKey() or
setNativeKey(). setKey() leads to a native key that is
platform independent while setNativeKey() directly sets
the native key without any mangling.
When using setNativeKey(), key() returns a null string
and shared memory's system semaphore is not set. This
means that is up to the user to define a such protection
mechanism (i.e. lock() can't be used on native keys).
QSharedMemory tests were updated.
Merge-request: 1497
Reviewed-by: Benjamin Poulain <benjamin.poulain@nokia.com>
Reviewed-by: Andreas Aardal Hanssen <andreas.aardal.hanssen@nokia.com>
Diffstat (limited to 'src/corelib/kernel/qsharedmemory_win.cpp')
-rw-r--r-- | src/corelib/kernel/qsharedmemory_win.cpp | 13 |
1 files changed, 5 insertions, 8 deletions
diff --git a/src/corelib/kernel/qsharedmemory_win.cpp b/src/corelib/kernel/qsharedmemory_win.cpp index 0f5fdc7f86..0cdb123703 100644 --- a/src/corelib/kernel/qsharedmemory_win.cpp +++ b/src/corelib/kernel/qsharedmemory_win.cpp @@ -99,18 +99,17 @@ HANDLE QSharedMemoryPrivate::handle() { if (!hand) { QString function = QLatin1String("QSharedMemory::handle"); - QString safeKey = makePlatformSafeKey(key); - if (safeKey.isEmpty()) { + if (nativeKey.isEmpty()) { error = QSharedMemory::KeyError; errorString = QSharedMemory::tr("%1: unable to make key").arg(function); return false; } #ifndef Q_OS_WINCE - hand = OpenFileMapping(FILE_MAP_ALL_ACCESS, false, (wchar_t*)safeKey.utf16()); + hand = OpenFileMapping(FILE_MAP_ALL_ACCESS, false, (wchar_t*)nativeKey.utf16()); #else // This works for opening a mapping too, but always opens it with read/write access in // attach as it seems. - hand = CreateFileMapping(INVALID_HANDLE_VALUE, 0, PAGE_READWRITE, 0, 0, (wchar_t*)safeKey.utf16()); + hand = CreateFileMapping(INVALID_HANDLE_VALUE, 0, PAGE_READWRITE, 0, 0, (wchar_t*)nativeKey.utf16()); #endif if (!hand) { setErrorString(function); @@ -133,17 +132,15 @@ bool QSharedMemoryPrivate::cleanHandle() bool QSharedMemoryPrivate::create(int size) { - // Get a windows acceptable key - QString safeKey = makePlatformSafeKey(key); QString function = QLatin1String("QSharedMemory::create"); - if (safeKey.isEmpty()) { + if (nativeKey.isEmpty()) { error = QSharedMemory::KeyError; errorString = QSharedMemory::tr("%1: key error").arg(function); return false; } // Create the file mapping. - hand = CreateFileMapping(INVALID_HANDLE_VALUE, 0, PAGE_READWRITE, 0, size, (wchar_t*)safeKey.utf16()); + hand = CreateFileMapping(INVALID_HANDLE_VALUE, 0, PAGE_READWRITE, 0, size, (wchar_t*)nativeKey.utf16()); setErrorString(function); // hand is valid when it already exists unlike unix so explicitly check |