diff options
| author | Andrew Stitcher <astitcher@apache.org> | 2012-08-10 17:27:28 +0000 |
|---|---|---|
| committer | Andrew Stitcher <astitcher@apache.org> | 2012-08-10 17:27:28 +0000 |
| commit | a1947442559323f1eb5e8eb4c67983d69ac2c65a (patch) | |
| tree | 02bcec3bff8863990410f1ecf5f86ff7cef83bf4 /cpp/src/qpid/sys/windows/AsynchIO.cpp | |
| parent | 83cd0d00a444d1e1b5f8e15135bf377eba03388d (diff) | |
| download | qpid-python-a1947442559323f1eb5e8eb4c67983d69ac2c65a.tar.gz | |
Rearrange buffer memory ownership to avoid leaking buffer memory
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@1371774 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/src/qpid/sys/windows/AsynchIO.cpp')
| -rw-r--r-- | cpp/src/qpid/sys/windows/AsynchIO.cpp | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/cpp/src/qpid/sys/windows/AsynchIO.cpp b/cpp/src/qpid/sys/windows/AsynchIO.cpp index ae53414e52..355acbe0e6 100644 --- a/cpp/src/qpid/sys/windows/AsynchIO.cpp +++ b/cpp/src/qpid/sys/windows/AsynchIO.cpp @@ -40,6 +40,7 @@ #include <windows.h> #include <boost/bind.hpp> +#include <boost/shared_array.hpp> namespace { @@ -252,6 +253,7 @@ public: /// Take any actions needed to prepare for working with the poller. virtual void start(Poller::shared_ptr poller); + virtual void createBuffers(uint32_t size); virtual void queueReadBuffer(BufferBase* buff); virtual void unread(BufferBase* buff); virtual void queueWrite(BufferBase* buff); @@ -286,6 +288,8 @@ private: * access to the buffer queue and write queue. */ Mutex bufferQueueLock; + std::vector<BufferBase> buffers; + boost::shared_array<char> bufferMemory; // Number of outstanding I/O operations. volatile LONG opsInProgress; @@ -385,15 +389,7 @@ AsynchIO::AsynchIO(const Socket& s, working(false) { } -struct deleter -{ - template <typename T> - void operator()(T *ptr){ delete ptr;} -}; - AsynchIO::~AsynchIO() { - std::for_each( bufferQueue.begin(), bufferQueue.end(), deleter()); - std::for_each( writeQueue.begin(), writeQueue.end(), deleter()); } void AsynchIO::queueForDeletion() { @@ -426,6 +422,19 @@ void AsynchIO::start(Poller::shared_ptr poller0) { startReading(); } +void AsynchIO::createBuffers(uint32_t size) { + // Allocate all the buffer memory at once + bufferMemory.reset(new char[size*BufferCount]); + + // Create the Buffer structs in a vector + // And push into the buffer queue + buffers.reserve(BufferCount); + for (uint32_t i = 0; i < BufferCount; i++) { + buffers.push_back(BufferBase(&bufferMemory[i*size], size)); + queueReadBuffer(&buffers[i]); + } +} + void AsynchIO::queueReadBuffer(AsynchIO::BufferBase* buff) { assert(buff); buff->dataStart = 0; |
