Date: Tuesday, January 30, 2007 @ 10:54:55
Author: gilles
Path: /cvsroot/carob/carob/src
Modified: BufferedSocket.cpp (1.1 -> 1.2)
sendToSocket() is no more recursive, which could lead to memory overflows for
huge requests (eg. blobs)
Recursion has been replaced by a while loop
--------------------+
BufferedSocket.cpp | 30 +++++++++++++++++-------------
1 files changed, 17 insertions(+), 13 deletions(-)
Index: carob/src/BufferedSocket.cpp
diff -u carob/src/BufferedSocket.cpp:1.1 carob/src/BufferedSocket.cpp:1.2
--- carob/src/BufferedSocket.cpp:1.1 Mon Jan 29 17:43:57 2007
+++ carob/src/BufferedSocket.cpp Tue Jan 30 10:54:55 2007
@@ -89,20 +89,24 @@
const void* buf, int len, int flags) const
throw (SocketIOException, UnexpectedException)
{
- int lenToCopy = len;
- if (write_cache.getRemainingSize() < lenToCopy)
+ int bytesCopied = 0;
+ int bytesToCopyThisTime = len;
+ while (bytesCopied < len)
{
- // not enough room: copy only # of bytes remaining in buffer
- lenToCopy = write_cache.getRemainingSize();
- }
- memcpy(write_cache.getWritePtr(), buf, lenToCopy);
- write_cache.forward(lenToCopy);
- if (len > lenToCopy)
- {
- // did not copy everything => have to flush and copy the rest
- flush();
- sendToSocket(fctName, objName, static_cast<const
java_byte*>(buf)+lenToCopy,
- len-lenToCopy, flags);
+ if (bytesToCopyThisTime > write_cache.getRemainingSize())
+ {
+ // not enough room: copy only # of bytes available in buffer
+ bytesToCopyThisTime = write_cache.getRemainingSize();
+ }
+ memcpy(write_cache.getWritePtr(),
+ static_cast<const java_byte*>(buf)+bytesCopied,
+ bytesToCopyThisTime);
+ write_cache.forward(bytesToCopyThisTime);
+ bytesCopied += bytesToCopyThisTime;
+ if (bytesCopied < len)
+ // did not copy everything => have to flush and copy the remaining bytes
+ flush();
+ bytesToCopyThisTime = len - bytesCopied;
}
}
_______________________________________________
Carob-commits mailing list
[email protected]
https://forge.continuent.org/mailman/listinfo/carob-commits