crossroads

Git mirror of https://crossroads.e-tunity.com/
git clone git://git.finwo.net/app/crossroads
Log | Files | Refs | LICENSE

checkspace.cc (1046B)


      1 #include "netbuffer"
      2 
      3 void Netbuffer::check_space(unsigned extra) {
      4     PROFILE("Netbuffer::check_space");
      5 
      6     if (!buf_alloced) {
      7 	buf_alloced = extra;
      8 	// When the first network buffer is allocated in HTTP mode, get
      9 	// twice as much. Most often that will be enough to fetch the whole
     10 	// client request, so that one realloc() will be spared.
     11 	if (extra == config.buffersize() &&
     12 	    config.stype() == Servertype::t_http)
     13 	    buf_alloced <<= 1;
     14 	debugmsg("Netbuffer: reserving " << buf_alloced <<
     15 		  " bytes for network buffer\n");
     16 	LOCK_MALLOC;
     17 	buf_data = (char*)malloc(buf_alloced);
     18 	UNLOCK_MALLOC;
     19 	if (! buf_data)
     20 	    throw Error("Memory fault in Netbuffer::check_space");
     21     } else if (buf_sz + extra > buf_alloced) {
     22 	debugmsg("Netbuffer: reallocating net buffer from " <<
     23 		 buf_alloced << " to " <<
     24 		 (buf_alloced + extra) << " bytes\n");
     25 	buf_alloced += extra;
     26 	LOCK_MALLOC;
     27 	buf_data = (char*)realloc(buf_data, buf_alloced);
     28 	UNLOCK_MALLOC;
     29 	if (! buf_data)
     30 	    throw Error("Memory fault in Netbuffer::check_space");
     31     }
     32 }