(trunk libT) socket performance tweak by wereHamster

This commit is contained in:
Charles Kerr 2008-12-23 17:11:31 +00:00
parent 303356d110
commit c4e11a12e3
1 changed files with 7 additions and 3 deletions

View File

@ -214,7 +214,10 @@ event_read_cb( int fd, short event UNUSED, void * vio )
{
int res;
tr_peerIo * io = vio;
const size_t howmuch = tr_bandwidthClamp( io->bandwidth, TR_DOWN, io->session->so_rcvbuf );
/* Limit the input buffer to 256K, so it doesn't grow too large */
const size_t canread = 256 * 1024 - EVBUFFER_LENGTH( io->inbuf );
const size_t howmuch = tr_bandwidthClamp( io->bandwidth, TR_DOWN, canread );
const tr_direction dir = TR_DOWN;
assert( tr_isPeerIo( io ) );
@ -290,8 +293,9 @@ event_write_cb( int fd, short event UNUSED, void * vio )
dbgmsg( io, "libevent says this peer is ready to write" );
howmuch = MIN( (size_t)io->session->so_sndbuf, EVBUFFER_LENGTH( io->outbuf ) );
howmuch = tr_bandwidthClamp( io->bandwidth, dir, howmuch );
/* Write as much as possible, since the socket is non-blocking, write() will
* return if it can't write any more data without blocking */
howmuch = tr_bandwidthClamp( io->bandwidth, dir, EVBUFFER_LENGTH( io->outbuf ) );
/* if we don't have any bandwidth left, stop writing */
if( howmuch < 1 ) {