Ignore:
Timestamp:
Sep 5, 2012, 11:39:57 AM (9 years ago)
Author:
livings124
Message:

#4321 uTP implementation is very slow.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/peer-io.c

    r13329 r13464  
    455455}
    456456
     457static int tr_peerIoTryWrite( tr_peerIo * io, size_t howmuch );
     458
     459static void
     460utp_on_writable( tr_peerIo *io )
     461{
     462    int n;
     463
     464    dbgmsg( io, "libutp says this peer is ready to write" );
     465
     466    n = tr_peerIoTryWrite( io, SIZE_MAX );
     467    tr_peerIoSetEnabled( io, TR_UP, n && evbuffer_get_length( io->outbuf ) );
     468}
     469
    457470static void
    458471utp_on_state_change(void *closure, int state)
     
    466479    } else if( state == UTP_STATE_WRITABLE ) {
    467480        dbgmsg( io, "utp_on_state_change -- changed to writable" );
     481        if ( io->pendingEvents & EV_WRITE )
     482            utp_on_writable( io );
    468483    } else if( state == UTP_STATE_EOF ) {
    469484        if( io->gotError )
     
    696711    assert( io->session->events != NULL );
    697712
    698     if( io->socket < 0 )
    699         return;
    700 
    701     assert( io->session->events != NULL );
    702     assert( event_initialized( io->event_read ) );
    703     assert( event_initialized( io->event_write ) );
     713    if( io->socket >= 0 )
     714    {
     715        assert( event_initialized( io->event_read ) );
     716        assert( event_initialized( io->event_write ) );
     717    }
    704718
    705719    if( ( event & EV_READ ) && ! ( io->pendingEvents & EV_READ ) )
    706720    {
    707         dbgmsg( io, "enabling libevent ready-to-read polling" );
    708         event_add( io->event_read, NULL );
     721        dbgmsg( io, "enabling ready-to-read polling" );
     722        if( io->socket >= 0 )
     723            event_add( io->event_read, NULL );
    709724        io->pendingEvents |= EV_READ;
    710725    }
     
    712727    if( ( event & EV_WRITE ) && ! ( io->pendingEvents & EV_WRITE ) )
    713728    {
    714         dbgmsg( io, "enabling libevent ready-to-write polling" );
    715         event_add( io->event_write, NULL );
     729        dbgmsg( io, "enabling ready-to-write polling" );
     730        if( io->socket >= 0 )
     731            event_add( io->event_write, NULL );
    716732        io->pendingEvents |= EV_WRITE;
    717733    }
     
    723739    assert( tr_amInEventThread( io->session ) );
    724740    assert( io->session != NULL );
    725 
    726     if( io->socket < 0 )
    727         return;
    728 
    729741    assert( io->session->events != NULL );
    730     assert( event_initialized( io->event_read ) );
    731     assert( event_initialized( io->event_write ) );
     742
     743    if( io->socket >= 0 )
     744    {
     745        assert( event_initialized( io->event_read ) );
     746        assert( event_initialized( io->event_write ) );
     747    }
    732748
    733749    if( ( event & EV_READ ) && ( io->pendingEvents & EV_READ ) )
    734750    {
    735         dbgmsg( io, "disabling libevent ready-to-read polling" );
    736         event_del( io->event_read );
     751        dbgmsg( io, "disabling ready-to-read polling" );
     752        if( io->socket >= 0 )
     753            event_del( io->event_read );
    737754        io->pendingEvents &= ~EV_READ;
    738755    }
     
    740757    if( ( event & EV_WRITE ) && ( io->pendingEvents & EV_WRITE ) )
    741758    {
    742         dbgmsg( io, "disabling libevent ready-to-write polling" );
    743         event_del( io->event_write );
     759        dbgmsg( io, "disabling ready-to-write polling" );
     760        if( io->socket >= 0 )
     761            event_del( io->event_write );
    744762        io->pendingEvents &= ~EV_WRITE;
    745763    }
     
    12581276        if( io->utp_socket != NULL ) /* utp peer connection */
    12591277        {
    1260             const size_t old_len = evbuffer_get_length( io->outbuf );
    12611278            UTP_Write( io->utp_socket, howmuch );
    12621279            n = old_len - evbuffer_get_length( io->outbuf );
Note: See TracChangeset for help on using the changeset viewer.