summaryrefslogtreecommitdiff
path: root/cpp/src
diff options
context:
space:
mode:
authorAndrew Stitcher <astitcher@apache.org>2007-08-01 17:17:06 +0000
committerAndrew Stitcher <astitcher@apache.org>2007-08-01 17:17:06 +0000
commit6679e59b028079a76c48e1404e0b21cb6c6fa0f7 (patch)
treea63cdccac14a1905ec614b0762aad0a8f3d6d597 /cpp/src
parent28b22a308cb6cf0232067636fb6676a4c96d82f7 (diff)
downloadqpid-python-6679e59b028079a76c48e1404e0b21cb6c6fa0f7.tar.gz
Recoded writing code so that it doesn't allocate framing::Buffer on the heap
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@561877 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/src')
-rw-r--r--cpp/src/qpid/sys/AsynchIOAcceptor.cpp60
1 files changed, 27 insertions, 33 deletions
diff --git a/cpp/src/qpid/sys/AsynchIOAcceptor.cpp b/cpp/src/qpid/sys/AsynchIOAcceptor.cpp
index bf4a3ff842..8d6b543dc9 100644
--- a/cpp/src/qpid/sys/AsynchIOAcceptor.cpp
+++ b/cpp/src/qpid/sys/AsynchIOAcceptor.cpp
@@ -190,7 +190,7 @@ void AsynchIOHandler::send(framing::AMQFrame& frame) {
if (!frameQueueClosed)
frameQueue.push(frame);
}
-
+
// Activate aio for writing here
aio->queueWrite();
}
@@ -263,46 +263,40 @@ void AsynchIOHandler::idle(AsynchIO&){
return;
}
- // Try and get a queued buffer if not then construct new one
- AsynchIO::Buffer* buff = aio->getQueuedBuffer();
- if (!buff)
- buff = new Buff;
- std::auto_ptr<framing::Buffer> out(new framing::Buffer(buff->bytes, buff->byteCount));
- int buffUsed = 0;
-
- while (!frameQueue.empty()) {
+ do {
+ // Try and get a queued buffer if not then construct new one
+ AsynchIO::Buffer* buff = aio->getQueuedBuffer();
+ if (!buff)
+ buff = new Buff;
+ framing::Buffer out(buff->bytes, buff->byteCount);
+ int buffUsed = 0;
+
framing::AMQFrame frame = frameQueue.front();
- frameQueue.pop();
-
- // Encode output frame
int frameSize = frame.size();
+ while (frameSize <= int(out.available())) {
+ frameQueue.pop();
+
+ // Encode output frame
+ frame.encode(out);
+ buffUsed += frameSize;
+ QPID_LOG(debug, "SENT: " << frame);
+
+ if (frameQueue.empty())
+ break;
+ frame = frameQueue.front();
+ frameSize = frame.size();
+ }
+ // If frame was egregiously large complain
if (frameSize > buff->byteCount)
THROW_QPID_ERROR(FRAMING_ERROR, "Could not write frame, too large for buffer.");
-
- // If we've filled current buffer then flush and get new one
- if (frameSize > int(out->available())) {
- buff->dataCount = buffUsed;
- aio->queueWrite(buff);
-
- buff = aio->getQueuedBuffer();
- if (!buff)
- buff = new Buff;
- out.reset(new framing::Buffer(buff->bytes, buff->byteCount));
- buffUsed = 0;
- }
-
- frame.encode(*out);
- buffUsed += frameSize;
- QPID_LOG(debug, "SENT: " << frame);
- }
-
- buff->dataCount = buffUsed;
- aio->queueWrite(buff);
+
+ buff->dataCount = buffUsed;
+ aio->queueWrite(buff);
+ } while (!frameQueue.empty());
if (frameQueueClosed) {
aio->queueWriteClose();
}
-
}
}} // namespace qpid::sys