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

Modify peer-io to work with UTP sockets.

This is not supposed to work yet -- it just adds new fields to the data
structures to get the UTP code to compile.

File:
1 edited

Legend:

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

    r11857 r11903  
    2626#include <event2/event.h>
    2727#include <event2/bufferevent.h>
     28#include "utp.h"
    2829
    2930#include "transmission.h"
     
    368369              tr_bool            isIncoming,
    369370              tr_bool            isSeed,
    370               int                socket )
     371              int                socket,
     372              struct UTPSocket * utp_socket)
    371373{
    372374    tr_peerIo * io;
     
    377379    assert( tr_isBool( isSeed ) );
    378380    assert( tr_amInEventThread( session ) );
     381    assert( (socket < 0) == (utp_socket != NULL) );
    379382
    380383    if( socket >= 0 ) {
     
    392395    io->port = port;
    393396    io->socket = socket;
     397    io->utp_socket = utp_socket;
    394398    io->isIncoming = isIncoming != 0;
    395399    io->timeCreated = tr_time( );
    396400    io->inbuf = evbuffer_new( );
    397401    io->outbuf = evbuffer_new( );
    398     io->event_read = event_new( session->event_base, io->socket, EV_READ, event_read_cb, io );
    399     io->event_write = event_new( session->event_base, io->socket, EV_WRITE, event_write_cb, io );
    400402    tr_bandwidthConstruct( &io->bandwidth, session, parent );
    401403    tr_bandwidthSetPeer( &io->bandwidth, io );
    402404    dbgmsg( io, "bandwidth is %p; its parent is %p", &io->bandwidth, parent );
     405
     406    if( io->socket >= 0 ) {
     407        io->event_read = event_new( session->event_base,
     408                                    io->socket, EV_READ, event_read_cb, io );
     409        io->event_write = event_new( session->event_base,
     410                                     io->socket, EV_WRITE, event_write_cb, io );
     411    }
    403412
    404413    return io;
     
    410419                      const tr_address  * addr,
    411420                      tr_port             port,
    412                       int                 fd )
     421                      int                 fd,
     422                      struct UTPSocket  * utp_socket )
    413423{
    414424    assert( session );
    415425    assert( tr_isAddress( addr ) );
    416     assert( fd >= 0 );
    417 
    418     return tr_peerIoNew( session, parent, addr, port, NULL, TRUE, FALSE, fd );
     426
     427    return tr_peerIoNew( session, parent, addr, port, NULL, TRUE, FALSE,
     428                         fd, utp_socket );
    419429}
    420430
     
    437447
    438448    return fd < 0 ? NULL
    439                   : tr_peerIoNew( session, parent, addr, port, torrentHash, FALSE, isSeed, fd );
     449                  : tr_peerIoNew( session, parent, addr, port,
     450                                  torrentHash, FALSE, isSeed, fd, NULL );
    440451}
    441452
     
    450461    assert( io->session != NULL );
    451462    assert( io->session->events != NULL );
     463
     464    if( io->socket < 0 )
     465        return;
     466
     467    assert( io->session->events != NULL );
    452468    assert( event_initialized( io->event_read ) );
    453469    assert( event_initialized( io->event_write ) );
    454 
    455     if( io->socket < 0 )
    456         return;
    457470
    458471    if( ( event & EV_READ ) && ! ( io->pendingEvents & EV_READ ) )
     
    476489    assert( tr_amInEventThread( io->session ) );
    477490    assert( io->session != NULL );
     491
     492    if( io->socket < 0 )
     493        return;
     494
    478495    assert( io->session->events != NULL );
    479496    assert( event_initialized( io->event_read ) );
     
    533550    evbuffer_free( io->outbuf );
    534551    evbuffer_free( io->inbuf );
    535     tr_netClose( io->session, io->socket );
     552    if( io->socket >= 0 )
     553        tr_netClose( io->session, io->socket );
     554    if( io->utp_socket != NULL )
     555        UTP_Close( io->utp_socket );
    536556    tr_cryptoFree( io->crypto );
    537557    tr_list_free( &io->outbuf_datatypes, tr_free );
     
    640660    event_disable( io, EV_READ | EV_WRITE );
    641661
    642     if( io->socket >= 0 )
     662    if( io->socket >= 0 ) {
    643663        tr_netClose( session, io->socket );
     664        io->socket = -1;
     665    }
     666    if( io->utp_socket != NULL ) {
     667        UTP_Close(io->utp_socket);
     668        io->utp_socket = NULL;
     669    }
    644670
    645671    event_free( io->event_read );
Note: See TracChangeset for help on using the changeset viewer.