From abef43392631e27408aad582e3c8c6da56bd77b0 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Sat, 1 Dec 2007 23:08:34 +0000 Subject: [PATCH] improve upload speeds when the speed limits are uncapped. --- libtransmission/handshake.c | 4 ++-- libtransmission/peer-io.c | 18 ++++++++++++++++-- libtransmission/peer-io.h | 2 ++ libtransmission/peer-msgs.c | 8 +++++++- 4 files changed, 27 insertions(+), 5 deletions(-) diff --git a/libtransmission/handshake.c b/libtransmission/handshake.c index 4768cbf1e..aaa6fa6a2 100644 --- a/libtransmission/handshake.c +++ b/libtransmission/handshake.c @@ -968,7 +968,7 @@ void tr_handshakeDone( tr_handshake * handshake, int isOK ) { dbgmsg( handshake, "handshakeDone: %s", isOK ? "connected" : "aborting" ); - tr_peerIoSetIOFuncs( handshake->io, NULL, NULL, NULL ); + tr_peerIoSetIOFuncs( handshake->io, NULL, NULL, NULL, NULL ); fireDoneFunc( handshake, isOK ); @@ -1030,7 +1030,7 @@ tr_handshakeNew( tr_peerIo * io, handshake->doneUserData = doneUserData; handshake->handle = tr_peerIoGetHandle( io ); - tr_peerIoSetIOFuncs( handshake->io, canRead, gotError, handshake ); + tr_peerIoSetIOFuncs( handshake->io, canRead, NULL, gotError, handshake ); if( tr_peerIoIsIncoming( handshake->io ) ) setReadState( handshake, AWAITING_HANDSHAKE ); diff --git a/libtransmission/peer-io.c b/libtransmission/peer-io.c index 3871af3e6..78779c6ca 100644 --- a/libtransmission/peer-io.c +++ b/libtransmission/peer-io.c @@ -61,6 +61,7 @@ struct tr_peerIo unsigned int peerIdIsSet : 1; tr_can_read_cb canRead; + tr_did_write_cb didWrite; tr_net_error_cb gotError; void * userData; @@ -71,6 +72,14 @@ struct tr_peerIo *** **/ +static void +didWriteWrapper( struct bufferevent * e, void * userData ) +{ + tr_peerIo * c = (tr_peerIo *) userData; + if( c->didWrite != NULL ) + (*c->didWrite)( e, c->userData ); +} + static void canReadWrapper( struct bufferevent * e, void * userData ) { @@ -134,7 +143,7 @@ tr_peerIoNew( struct tr_handle * handle, c->timeout = IO_TIMEOUT_SECS; c->bufev = bufferevent_new( c->socket, canReadWrapper, - NULL, + didWriteWrapper, gotErrorWrapper, c ); bufferevent_settimeout( c->bufev, c->timeout, c->timeout ); @@ -192,6 +201,7 @@ tr_peerIoFree( tr_peerIo * io ) if( io != NULL ) { io->canRead = NULL; + io->didWrite = NULL; io->gotError = NULL; tr_runInEventThread( io->handle, io_dtor, io ); } @@ -241,10 +251,12 @@ tr_peerIoTryRead( tr_peerIo * io ) void tr_peerIoSetIOFuncs( tr_peerIo * io, tr_can_read_cb readcb, + tr_did_write_cb writecb, tr_net_error_cb errcb, void * userData ) { io->canRead = readcb; + io->didWrite = writecb; io->gotError = errcb; io->userData = userData; @@ -272,7 +284,9 @@ tr_peerIoReconnect( tr_peerIo * io ) bufferevent_free( io->bufev ); io->bufev = bufferevent_new( io->socket, - canReadWrapper, NULL, gotErrorWrapper, + canReadWrapper, + didWriteWrapper, + gotErrorWrapper, io ); bufferevent_settimeout( io->bufev, io->timeout, io->timeout ); bufferevent_enable( io->bufev, EV_READ|EV_WRITE ); diff --git a/libtransmission/peer-io.h b/libtransmission/peer-io.h index 9a2d73b1e..8ac4eb1d0 100644 --- a/libtransmission/peer-io.h +++ b/libtransmission/peer-io.h @@ -99,10 +99,12 @@ const uint8_t* typedef enum { READ_MORE, READ_AGAIN, READ_DONE } ReadState; typedef ReadState (*tr_can_read_cb)(struct bufferevent*, void* user_data); +typedef void (*tr_did_write_cb)(struct bufferevent *, void *); typedef void (*tr_net_error_cb)(struct bufferevent *, short what, void *); void tr_peerIoSetIOFuncs( tr_peerIo * io, tr_can_read_cb readcb, + tr_did_write_cb writecb, tr_net_error_cb errcb, void * user_data ); diff --git a/libtransmission/peer-msgs.c b/libtransmission/peer-msgs.c index c59b021df..09ff0922d 100644 --- a/libtransmission/peer-msgs.c +++ b/libtransmission/peer-msgs.c @@ -1410,6 +1410,12 @@ clientGotBlock( tr_peermsgs * msgs, return 0; } +static void +didWrite( struct bufferevent * evin UNUSED, void * vmsgs ) +{ + pulse( vmsgs ); +} + static ReadState canRead( struct bufferevent * evin, void * vmsgs ) { @@ -1843,7 +1849,7 @@ tr_peerMsgsNew( struct tr_torrent * torrent, } tr_peerIoSetTimeoutSecs( m->io, 150 ); /* timeout after N seconds of inactivity */ - tr_peerIoSetIOFuncs( m->io, canRead, gotError, m ); + tr_peerIoSetIOFuncs( m->io, canRead, didWrite, gotError, m ); ratePulse( m ); if ( tr_peerIoSupportsLTEP( m->io ) )