Changeset 524

Show
Ignore:
Timestamp:
04/16/07 18:44:12 (16 months ago)
Author:
hyriand
Message:

Don't heap-allocate 1 megabyte for every incoming packet, stack-allocate 16kb instead. Handle incoming data before issuing a disconnect on closed socket.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • museek+/trunk/sources/Museekal/ClientConnection.cc

    r2 r524  
    230230 
    231231        if (mask & MASKIN) { 
    232                 char *data = new char[1024 * 1024]; 
    233                 int i = 1, read = 0; 
     232                char data[16384]; 
     233                int i = 1, read = 0, _errno = EAGAIN; 
    234234 
    235235                while(i > 0) { 
    236                         i = recv(sock, data, 1024 * 1024, 0); 
     236                        i = recv(sock, data, 16384, 0); 
    237237                        if (i > 0) { 
    238238                                TrafficTracker::instance()->collect(1, i); 
     
    242242                        } 
    243243                } 
    244                 if ((i == 0) || (errno != EAGAIN)) 
    245                         disconnect(); 
    246  
    247                 delete [] data; 
     244                if (i < 0) 
     245                        _errno = errno; 
    248246 
    249247                if (! inbuf.empty()) 
    250248                        process(); 
    251         } 
    252 } 
     249 
     250                if ((i == 0) || (_errno != EAGAIN)) 
     251                        disconnect(); 
     252        } 
     253}