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

First pass at uTP callbacks.

File:
1 edited

Legend:

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

    r11906 r11908  
    361361}
    362362
     363/* UTP callbacks */
     364
     365static void
     366utp_on_read(void *closure, const unsigned char *buf, size_t buflen)
     367{
     368    tr_peerIo *io = (tr_peerIo *)closure;
     369    assert( tr_isPeerIo( io ) );
     370    tr_ndbg( "UTP", "On read: %ld", (long)buflen );
     371}
     372
     373static void
     374utp_on_write(void *closure, unsigned char *buf, size_t buflen)
     375{
     376    tr_peerIo *io = (tr_peerIo *)closure;
     377    assert( tr_isPeerIo( io ) );
     378    tr_ndbg( "UTP", "On write: %ld", (long)buflen );
     379}
     380
     381static size_t
     382utp_get_rb_size(void *closure)
     383{
     384    tr_peerIo *io = (tr_peerIo *)closure;
     385    assert( tr_isPeerIo( io ) );
     386
     387    tr_ndbg( "UTP", "Get RB size" );
     388    return 0;
     389}
     390
     391static void
     392utp_on_state_change(void *closure, int state)
     393{
     394    tr_peerIo *io;
     395    /* This can be called after UTP_Close, in which case closure can point
     396       to an already-destroyed peerIo. */
     397    if( state == UTP_STATE_DESTROYING ) {
     398        tr_ndbg( "UTP", "Connection destroyed" );
     399        return;
     400    }
     401
     402    io = (tr_peerIo *)closure;
     403    assert( tr_isPeerIo( io ) );
     404
     405    tr_ndbg( "UTP", "On state change: %d", state );
     406}
     407
     408static void
     409utp_on_error(void *closure, int errcode)
     410{
     411    tr_peerIo *io = (tr_peerIo *)closure;
     412    assert( tr_isPeerIo( io ) );
     413
     414    tr_ndbg( "UTP", "Error callback: %s", tr_strerror( errcode ) );
     415}
     416
     417static void
     418utp_on_overhead(void *closure, bool send, size_t count, int type)
     419{
     420    tr_peerIo *io = (tr_peerIo *)closure;
     421    assert( tr_isPeerIo( io ) );
     422
     423    tr_ndbg( "UTP", "On overhead: %d %ld %d", (int)send, (long)count, type );
     424}
     425
     426static struct UTPFunctionTable utp_function_table = {
     427    .on_read = utp_on_read,
     428    .on_write = utp_on_write,
     429    .get_rb_size = utp_get_rb_size,
     430    .on_state = utp_on_state_change,
     431    .on_error = utp_on_error,
     432    .on_overhead = utp_on_overhead
     433};
     434
    363435static tr_peerIo*
    364436tr_peerIoNew( tr_session       * session,
     
    409481        io->event_write = event_new( session->event_base,
    410482                                     io->socket, EV_WRITE, event_write_cb, io );
     483    } else {
     484        tr_ndbg( "UTP", "New %s connection",
     485                 isIncoming ? "incoming" : "outgoing" );
     486        UTP_SetCallbacks( utp_socket,
     487                          &utp_function_table,
     488                          io );
    411489    }
    412490
     
    553631        tr_netClose( io->session, io->socket );
    554632    }
    555     if( io->utp_socket != NULL )
     633    if( io->utp_socket != NULL ) {
     634        tr_ndbg( "UTP", "Destroying connection");
    556635        UTP_Close( io->utp_socket );
     636    }
    557637    tr_cryptoFree( io->crypto );
    558638    tr_list_free( &io->outbuf_datatypes, tr_free );
Note: See TracChangeset for help on using the changeset viewer.