improve upload speeds when the speed limits are uncapped.

This commit is contained in:
Charles Kerr 2007-12-01 23:08:34 +00:00
parent e843d4869c
commit abef433926
4 changed files with 27 additions and 5 deletions

View File

@ -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 );

View File

@ -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 );

View File

@ -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 );

View File

@ -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 ) )