Changeset 11911


Ignore:
Timestamp:
Feb 18, 2011, 12:24:22 AM (11 years ago)
Author:
jch
Message:

Complete the uTP callbacks.

File:
1 edited

Legend:

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

    r11910 r11911  
    368368utp_on_read(void *closure, const unsigned char *buf, size_t buflen)
    369369{
     370    int rc;
    370371    tr_peerIo *io = (tr_peerIo *)closure;
    371372    assert( tr_isPeerIo( io ) );
     373
    372374    tr_ndbg( "UTP", "On read: %ld", (long)buflen );
     375
     376    rc = evbuffer_add( io->inbuf, buf, buflen );
     377    if( rc < 0 ) {
     378        tr_nerr( "UTP", "On read evbuffer_add" );
     379        UTP_Close( io->utp_socket );
     380        return;
     381    }
     382
     383    tr_peerIoSetEnabled( io, TR_DOWN, TRUE );
     384    canReadWrapper( io );
    373385}
    374386
     
    377389{
    378390    tr_peerIo *io = (tr_peerIo *)closure;
     391    int rc;
     392
    379393    assert( tr_isPeerIo( io ) );
    380394    tr_ndbg( "UTP", "On write: %ld", (long)buflen );
     395
     396    rc = evbuffer_remove( io->outbuf, buf, buflen );
     397    if( rc < (long)buflen ) {
     398        tr_nerr( "UTP", "Short write: %d < %ld", rc, (long)buflen);
     399    }
    381400}
    382401
     
    394413utp_on_state_change(void *closure, int state)
    395414{
    396     tr_peerIo *io;
    397     /* This can be called after UTP_Close, in which case closure can point
    398        to an already-destroyed peerIo. */
    399     if( state == UTP_STATE_DESTROYING ) {
    400         tr_ndbg( "UTP", "Connection destroyed" );
     415    tr_peerIo *io = (tr_peerIo *)closure;
     416    assert( tr_isPeerIo( io ) );
     417
     418    tr_ndbg( "UTP", "On state change: %d", state );
     419
     420    if( state == UTP_STATE_CONNECT || state == UTP_STATE_WRITABLE ) {
     421        size_t count = evbuffer_get_length( io->outbuf );
     422        if( count > 0 )
     423            UTP_Write( io->utp_socket, count );
     424    } else if( state == UTP_STATE_EOF ) {
     425        if( io->gotError )
     426            io->gotError( io, BEV_EVENT_EOF, io->userData );
     427    } else if( state == UTP_STATE_DESTROYING ) {
     428        tr_nerr( "UTP", "Impossible state UTP_STATE_DESTROYING" );
    401429        return;
    402     }
    403 
    404     io = (tr_peerIo *)closure;
    405     assert( tr_isPeerIo( io ) );
    406 
    407     tr_ndbg( "UTP", "On state change: %d", state );
     430    } else {
     431        tr_nerr( "UTP", "Unknown state %d", state );
     432    }
    408433}
    409434
     
    415440
    416441    tr_ndbg( "UTP", "Error callback: %s", tr_strerror( errcode ) );
     442
     443    if( io->gotError ) {
     444        errno = errcode;
     445        io->gotError( io, BEV_EVENT_ERROR, io->userData );
     446    }
    417447}
    418448
Note: See TracChangeset for help on using the changeset viewer.