Date: Tuesday, January 30, 2007 @ 12:42:44
  Author: marc
    Path: /cvsroot/carob/carob/src

Modified: BufferedSocket.cpp (1.3 -> 1.4)

Added some comments in recvFully()


--------------------+
 BufferedSocket.cpp |   14 ++++++++++----
 1 files changed, 10 insertions(+), 4 deletions(-)


Index: carob/src/BufferedSocket.cpp
diff -u carob/src/BufferedSocket.cpp:1.3 carob/src/BufferedSocket.cpp:1.4
--- carob/src/BufferedSocket.cpp:1.3    Tue Jan 30 12:03:27 2007
+++ carob/src/BufferedSocket.cpp        Tue Jan 30 12:42:43 2007
@@ -35,11 +35,14 @@
 int BufferedSocket::recvFully(void *buf, const int len, const int flags)
     const throw (SocketIOException, UnexpectedException)
 {
-  int alreadyRead = 0; // Keeps the whole size read
+  int alreadyRead = 0; // Keeps the whole size read as the offset in
+                       // user buffer
   int remainingBytesToRead = len;
   while (!canceled && (remainingBytesToRead > 0))
   {
     int availableBytes = read_cache.getDataSize();
+
+    // Empty cache? (always true except at first iteration)
     if (availableBytes < 1)
     {
       // Application has eaten everything we received so far in the
@@ -50,11 +53,14 @@
 
       availableBytes = fillReadBuffer(flags);
     }
+    
+    // be optimistic and assume we have enough in stock...
     int toBeReadThisTime = remainingBytesToRead;
-    if (toBeReadThisTime > availableBytes)
+
+    // ... unless proven wrong
+    if (remainingBytesToRead > availableBytes)
     {
-      // not enough data ready, just read those available. Next bytes will be
-      // read in the next loop round
+      // not enough data ready, just give those available and loop
       toBeReadThisTime = availableBytes;
     }
     memcpy(static_cast<java_byte*>(static_cast<java_byte*>(buf)+alreadyRead),

_______________________________________________
Carob-commits mailing list
[email protected]
https://forge.continuent.org/mailman/listinfo/carob-commits

Reply via email to