diff options
author | Andrew Stitcher <astitcher@apache.org> | 2009-12-15 23:02:29 +0000 |
---|---|---|
committer | Andrew Stitcher <astitcher@apache.org> | 2009-12-15 23:02:29 +0000 |
commit | b07ef1b95d1c6496697e9b9502f50deccec59ed9 (patch) | |
tree | 31ed921548f138fdc484fae3e4a0fb54c02aa8aa | |
parent | 9ab2bdf409eb626975d4ac5cb6869b06639dcfde (diff) | |
download | qpid-python-b07ef1b95d1c6496697e9b9502f50deccec59ed9.tar.gz |
QPID-2281: LockFile class now actually locks the file!
[before it just opened the file without locking it]
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@891061 13f79535-47bb-0310-9956-ffa450edef68
-rwxr-xr-x | qpid/cpp/src/qpid/sys/windows/LockFile.cpp | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/qpid/cpp/src/qpid/sys/windows/LockFile.cpp b/qpid/cpp/src/qpid/sys/windows/LockFile.cpp index e9fe01ca72..048c2d5b18 100755 --- a/qpid/cpp/src/qpid/sys/windows/LockFile.cpp +++ b/qpid/cpp/src/qpid/sys/windows/LockFile.cpp @@ -36,7 +36,7 @@ public: LockFile::LockFile(const std::string& path_, bool create) : path(path_), created(create) { - HANDLE h = CreateFile(path.c_str(), + HANDLE h = ::CreateFile(path.c_str(), create ? (GENERIC_READ|GENERIC_WRITE) : GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, 0, /* Default security */ @@ -44,14 +44,19 @@ LockFile::LockFile(const std::string& path_, bool create) FILE_FLAG_DELETE_ON_CLOSE, /* Delete file when closed */ NULL); if (h == INVALID_HANDLE_VALUE) - throw qpid::Exception(path + qpid::sys::strError(GetLastError())); + throw qpid::Exception(path + ": " + qpid::sys::strError(GetLastError())); + + // Lock up to 4Gb + if (!::LockFile(h, 0, 0, 0xffffffff, 0)) + throw qpid::Exception(path + ": " + qpid::sys::strError(GetLastError())); impl.reset(new LockFilePrivate(h)); } LockFile::~LockFile() { if (impl) { if (impl->fd != INVALID_HANDLE_VALUE) { - CloseHandle(impl->fd); + ::UnlockFile(impl->fd, 0, 0, 0xffffffff, 0); + ::CloseHandle(impl->fd); } } } |