(trunk libT) experimental commit that will *possibly* fix the "assert( tr_isPeerIo( io ) )" crash reported by Biiaru and others

This commit is contained in:
Charles Kerr 2009-01-24 14:49:35 +00:00
parent 7f82b7172c
commit 40f3c725d7
2 changed files with 22 additions and 4 deletions

View File

@ -191,6 +191,7 @@ event_read_cb( int fd, short event UNUSED, void * vio )
assert( tr_isPeerIo( io ) );
io->hasFinishedConnecting = TRUE;
io->pendingEvents &= ~EV_READ;
curlen = EVBUFFER_LENGTH( io->inbuf );
howmuch = curlen >= max ? 0 : max - curlen;
@ -273,6 +274,7 @@ event_write_cb( int fd, short event UNUSED, void * vio )
assert( tr_isPeerIo( io ) );
io->hasFinishedConnecting = TRUE;
io->pendingEvents &= ~EV_WRITE;
dbgmsg( io, "libevent says this peer is ready to write" );
@ -834,28 +836,42 @@ tr_peerIoFlush( tr_peerIo * io, tr_direction dir, size_t limit )
static void
event_enable( tr_peerIo * io, short event )
{
if( event & EV_READ ) {
assert( event_initialized( &io->event_read ) );
assert( event_initialized( &io->event_write ) );
if( ( event & EV_READ ) && ! ( io->pendingEvents & EV_READ ) )
{
dbgmsg( io, "enabling libevent ready-to-read polling" );
event_add( &io->event_read, NULL );
io->pendingEvents |= EV_READ;
}
if( event & EV_WRITE ) {
if( ( event & EV_WRITE ) && ! ( io->pendingEvents & EV_WRITE ) )
{
dbgmsg( io, "enabling libevent ready-to-write polling" );
event_add( &io->event_write, NULL );
io->pendingEvents |= EV_WRITE;
}
}
static void
event_disable( struct tr_peerIo * io, short event )
{
if( event & EV_READ ) {
assert( event_initialized( &io->event_read ) );
assert( event_initialized( &io->event_write ) );
if( ( event & EV_READ ) && ( io->pendingEvents & EV_READ ) )
{
dbgmsg( io, "disabling libevent ready-to-read polling" );
event_del( &io->event_read );
io->pendingEvents &= ~EV_READ;
}
if( event & EV_WRITE ) {
if( ( event & EV_WRITE ) && ( io->pendingEvents & EV_WRITE ) )
{
dbgmsg( io, "disabling libevent ready-to-write polling" );
event_del( &io->event_write );
io->pendingEvents &= ~EV_WRITE;
}
}

View File

@ -69,6 +69,8 @@ typedef struct tr_peerIo
* for reading or writing */
tr_bool hasFinishedConnecting;
int pendingEvents;
int magicNumber;
uint8_t encryptionMode;