Ignore:
Timestamp:
Dec 16, 2008, 10:08:17 PM (12 years ago)
Author:
charles
Message:

(trunk libT) really fuck up the peer i/o code. also this breaks the mac build until someone removes iobuf.c from libtransmission's list of files.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/bandwidth.c

    r7404 r7419  
    1919#include "bandwidth.h"
    2020#include "crypto.h"
    21 #include "iobuf.h"
     21#include "peer-io.h"
    2222#include "ptrarray.h"
    2323#include "utils.h"
     
    100100    tr_session * session;
    101101    tr_ptrArray * children; /* struct tr_bandwidth */
    102     tr_ptrArray * iobufs; /* struct tr_iobuf */
     102    tr_ptrArray * peers; /* tr_peerIo */
    103103};
    104104
     
    135135    b->session = session;
    136136    b->children = tr_ptrArrayNew( );
    137     b->iobufs = tr_ptrArrayNew( );
     137    b->peers = tr_ptrArrayNew( );
    138138    b->magicNumber = MAGIC_NUMBER;
    139139    b->band[TR_UP].honorParentLimits = 1;
     
    149149
    150150    tr_bandwidthSetParent( b, NULL );
    151     tr_ptrArrayFree( b->iobufs, NULL );
     151    tr_ptrArrayFree( b->peers, NULL );
    152152    tr_ptrArrayFree( b->children, NULL );
    153153    b->magicNumber = 0xDEAD;
     
    250250                   tr_direction    dir,
    251251                   int             period_msec,
    252                    tr_ptrArray   * iobuf_pool )
     252                   tr_ptrArray   * peer_pool )
    253253{
    254254    assert( isBandwidth( b ) );
     
    271271    {
    272272        int i;
    273         const int n = tr_ptrArraySize( b->iobufs );
     273        const int n = tr_ptrArraySize( b->peers );
    274274        for( i=0; i<n; ++i )
    275             tr_ptrArrayAppend( iobuf_pool, tr_ptrArrayNth( b->iobufs, i ) );
     275            tr_ptrArrayAppend( peer_pool, tr_ptrArrayNth( b->peers, i ) );
    276276    }
    277277
    278278#ifdef DEBUG_DIRECTION
    279279if( ( dir == DEBUG_DIRECTION ) && ( n > 1 ) )
    280 fprintf( stderr, "bandwidth %p has %d iobufs\n", b, n );
     280fprintf( stderr, "bandwidth %p has %d peers\n", b, n );
    281281#endif
    282282
     
    286286        struct tr_bandwidth ** children = (struct tr_bandwidth**) tr_ptrArrayPeek( b->children, &n );
    287287        for( i=0; i<n; ++i )
    288             allocateBandwidth( children[i], dir, period_msec, iobuf_pool );
     288            allocateBandwidth( children[i], dir, period_msec, peer_pool );
    289289    }
    290290}
     
    297297    int n;
    298298    tr_ptrArray * tmp;
    299     struct tr_iobuf ** buffers;
     299    struct tr_peerIo ** peers;
    300300    const size_t chunkSize = 1024; /* arbitrary */
    301301
    302302    tmp = tr_ptrArrayNew( );
    303303    allocateBandwidth( b, dir, period_msec, tmp );
    304     buffers = (struct tr_iobuf**) tr_ptrArrayPeek( tmp, &n );
     304    peers = (struct tr_peerIo**) tr_ptrArrayPeek( tmp, &n );
    305305
    306306    /* loop through all the peers, reading and writing in small chunks,
    307307     * until we run out of bandwidth or peers. we do it this way to
    308308     * prevent one peer from using up all the bandwidth */
     309fprintf( stderr, "%s - %d peers\n", (dir==TR_UP)?"up":"down", n );
    309310    while( n > 0 )
    310311    {
     
    312313        for( i=0; i<n; )
    313314        {
    314             int byteCount;
    315             if( dir == TR_UP )
    316                 byteCount = tr_iobuf_flush_output_buffer( buffers[i], chunkSize );
    317             else
    318                 byteCount = tr_iobuf_tryread( buffers[i], chunkSize );
     315            const int byteCount = tr_peerIoFlush( peers[i], dir, chunkSize );
     316
     317            if( byteCount )
     318                fprintf( stderr, "peer %p: %d bytes\n", peers[i], byteCount );
     319
    319320            if( byteCount == (int)chunkSize )
    320321                ++i;
    321322            else
    322                 buffers[i] = buffers[--n];
     323                peers[i] = peers[--n];
    323324        }
    324325    }
     
    333334
    334335void
    335 tr_bandwidthAddBuffer( tr_bandwidth        * b,
    336                        struct tr_iobuf     * iobuf )
    337 {
    338     assert( isBandwidth( b ) );
    339     assert( iobuf );
    340 
    341     tr_ptrArrayInsertSorted( b->iobufs, iobuf, comparePointers );
    342 }
    343 
    344 void
    345 tr_bandwidthRemoveBuffer( tr_bandwidth        * b,
    346                           struct tr_iobuf     * iobuf )
    347 {
    348     assert( isBandwidth( b ) );
    349     assert( iobuf );
    350 
    351     tr_ptrArrayRemoveSorted( b->iobufs, iobuf, comparePointers );
     336tr_bandwidthAddPeer( tr_bandwidth   * b,
     337                     tr_peerIo      * peerIo )
     338{
     339    assert( isBandwidth( b ) );
     340    assert( peerIo );
     341
     342    tr_ptrArrayInsertSorted( b->peers, peerIo, comparePointers );
     343}
     344
     345void
     346tr_bandwidthRemovePeer( tr_bandwidth  * b,
     347                        tr_peerIo     * peerIo )
     348{
     349    assert( isBandwidth( b ) );
     350    assert( peerIo );
     351
     352    tr_ptrArrayRemoveSorted( b->peers, peerIo, comparePointers );
    352353}
    353354
Note: See TracChangeset for help on using the changeset viewer.