Print

Print


Commit in lcio/sio/src on MAIN
SIO_functions.cc+21-31.6 -> 1.7
fixed bug with stream buffer resizing

lcio/sio/src
SIO_functions.cc 1.6 -> 1.7
diff -u -r1.6 -r1.7
--- SIO_functions.cc	6 Dec 2006 19:09:18 -0000	1.6
+++ SIO_functions.cc	1 Feb 2007 08:57:51 -0000	1.7
@@ -1,5 +1,5 @@
 // ----------------------------------------------------------------------------
-// CVS $Id: SIO_functions.cc,v 1.6 2006/12/06 19:09:18 hvogt Exp $
+// CVS $Id: SIO_functions.cc,v 1.7 2007/02/01 08:57:51 gaede Exp $
 // ----------------------------------------------------------------------------
 // => Function package for SIO                            
 // ----------------------------------------------------------------------------
@@ -187,7 +187,23 @@
         unsigned char
            *newbuf;
 
-        newlen = (stream->bufmax - stream->bufloc) << 1;
+//fg: --- this is not correct if the new request is larger than double the size...
+//         newlen = (stream->bufmax - stream->bufloc) << 1;
+
+	int minNeeded = (stream->buffer + padlen) - stream->bufmax ;
+	int bufSize = stream->bufmax - stream->bufloc ;
+	int resizeFactor = 2 ;
+	while( bufSize * (resizeFactor-1)  < minNeeded ) 
+	  ++resizeFactor ;
+
+	newlen = bufSize * resizeFactor  ;
+
+// 	std::cout << " resizing buffer - needed : " << minNeeded 
+// 		  << " bufSize : " << bufSize 
+// 		  << " resize factor : " << resizeFactor
+// 		  << " new size: " << std::endl ;
+//fg: ---
+
         newbuf = (unsigned char *)malloc( newlen );
         if( newbuf == NULL )
         {
@@ -205,7 +221,9 @@
             return( SIO_STREAM_NOALLOC );
         }
 
-        oldlen = stream->buffer - stream->bufloc;
+
+	oldlen = stream->buffer - stream->bufloc;
+ 
         memcpy( newbuf, stream->bufloc, oldlen );
         free( stream->bufloc );
         stream->blkmax = newbuf + (stream->blkmax - stream->bufloc);
CVSspam 0.2.8