Ignore:
Timestamp:
Jun 19, 2011, 6:26:04 PM (10 years ago)
Author:
jordan
Message:

(trunk libT) modify how the "stops" sorted container is used s.t. the container's uniqueness requirements are met.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/announcer.c

    r12404 r12507  
    102102}
    103103
     104/**
     105 * Comparison function for tr_announce_requests.
     106 *
     107 * The primary key (amount of data transferred) is used to prioritize
     108 * tracker announcements of active torrents. The remaining keys are
     109 * used to satisfy the uniqueness requirement of a sorted tr_ptrArray.
     110 */
    104111static int
    105112compareStops( const void * va, const void * vb )
    106113{
     114    int i;
    107115    const tr_announce_request * a = va;
    108116    const tr_announce_request * b = vb;
    109     return compareTransfer( a->up, a->down, b->up, b->down);
     117
     118    /* primary key: volume of data transferred. */
     119    if(( i = compareTransfer( a->up, a->down, b->up, b->down)))
     120        return i;
     121
     122    /* secondary key: the torrent's info_hash */
     123    if(( i = memcmp( a->info_hash, b->info_hash, SHA_DIGEST_LENGTH )))
     124        return i;
     125
     126    /* tertiary key: the tracker's announec url */
     127    return tr_strcmp0( a->url, b->url );
    110128}
    111129
     
    897915}
    898916
     917static void announce_request_free( tr_announce_request * req );
     918
    899919void
    900920tr_announcerRemoveTorrent( tr_announcer * announcer, tr_torrent * tor )
     
    912932                const tr_announce_event e = TR_ANNOUNCE_EVENT_STOPPED;
    913933                tr_announce_request * req = announce_request_new( announcer, tor, tier, e );
    914                 tr_ptrArrayInsertSorted( &announcer->stops, req, compareStops );
     934
     935                if( tr_ptrArrayFindSorted( &announcer->stops, req, compareStops ) != NULL )
     936                    announce_request_free( req );
     937                else
     938                    tr_ptrArrayInsertSorted( &announcer->stops, req, compareStops );
    915939            }
    916940        }
     
    11141138
    11151139static void
     1140announce_request_free( tr_announce_request * req )
     1141{
     1142    tr_free( req->tracker_id_str );
     1143    tr_free( req->url );
     1144    tr_free( req );
     1145}
     1146
     1147static void
    11161148announce_request_delegate( tr_announcer               * announcer,
    11171149                           tr_announce_request        * request,
     
    11281160        tr_err( "Unsupported url: %s", request->url );
    11291161
    1130     tr_free( request->tracker_id_str );
    1131     tr_free( request->url );
    1132     tr_free( request );
     1162    announce_request_free( request );
    11331163}
    11341164
Note: See TracChangeset for help on using the changeset viewer.