Changeset 1143


Ignore:
Timestamp:
Nov 30, 2006, 3:33:08 PM (15 years ago)
Author:
titer
Message:

Restores a blocking tr_torrentScrape for transmissioncli -s

Location:
branches/scrape
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • branches/scrape/cli/transmissioncli.c

    r983 r1143  
    147147    if( showScrape )
    148148    {
    149         int seeders, leechers;
    150 
    151         if( tr_torrentScrape( tor, &seeders, &leechers ) )
     149        int seeders, leechers, downloaded;
     150
     151        if( tr_torrentScrape( tor, &seeders, &leechers, &downloaded ) )
    152152        {
    153153            printf( "Scrape failed.\n" );
     
    155155        else
    156156        {
    157             printf( "%d seeder(s), %d leecher(s).\n", seeders, leechers );
     157            printf( "%d seeder(s), %d leecher(s), %d download(s).\n",
     158                    seeders, leechers, downloaded );
    158159        }
    159160
  • branches/scrape/libtransmission/tracker.c

    r1140 r1143  
    765765    return tc->downloaded;
    766766}
     767
     768/* Blocking version */
     769int tr_trackerScrape( tr_torrent_t * tor, int * s, int * l, int * d )
     770{
     771    tr_info_t    * inf = &tor->info;
     772    tr_tracker_t * tc;
     773    tr_http_t    * http;
     774    const char   * data;
     775    int            len;
     776    int            ret;
     777
     778    if( !tor->scrape[0] )
     779    {
     780        return 1;
     781    }
     782
     783    tc = tr_trackerInit( tor );
     784    http = tr_httpClient( TR_HTTP_GET, inf->trackerAddress, inf->trackerPort,
     785                          "%s%sinfo_hash=%s", tor->scrape, strchr( tor->scrape, '?' ) ?
     786                          "&" : "?", tor->escapedHashString );
     787
     788    for( data = NULL; !data; tr_wait( 10 ) )
     789    {
     790        switch( tr_httpPulse( http, &data, &len ) )
     791        {
     792            case TR_WAIT:
     793                break;
     794
     795            case TR_ERROR:
     796                goto scrapeDone;
     797                break;
     798
     799            case TR_OK:
     800                readScrapeAnswer( tc, data, len );
     801                goto scrapeDone;
     802                break;
     803        }
     804    }
     805
     806scrapeDone:
     807    tr_httpClose( http );
     808
     809    ret = 1;
     810    if( tc->seeders > -1 && tc->leechers > -1 && tc->downloaded > -1 )
     811    {
     812        *s = tc->seeders;
     813        *l = tc->leechers;
     814        *d = tc->downloaded;
     815        ret = 0;
     816    }
     817
     818    tr_trackerClose( tc );
     819    return ret;
     820}
  • branches/scrape/libtransmission/tracker.h

    r1133 r1143  
    5757int tr_trackerDownloaded( tr_tracker_t * tc );
    5858
     59
     60int tr_trackerScrape( tr_torrent_t * tor, int * s, int * l, int * d );
     61
    5962#endif
  • branches/scrape/libtransmission/transmission.c

    r1132 r1143  
    364364{
    365365    return &tor->info;
     366}
     367
     368/***********************************************************************
     369 * tr_torrentScrape     
     370 **********************************************************************/
     371int tr_torrentScrape( tr_torrent_t * tor, int * s, int * l, int * d )
     372{
     373    return tr_trackerScrape( tor, s, l, d );
    366374}
    367375
  • branches/scrape/libtransmission/transmission.h

    r1132 r1143  
    203203
    204204/***********************************************************************
     205 * tr_torrentScrape
     206 ***********************************************************************
     207 * Asks the tracker for the count of seeders and leechers. Returns 0
     208 * and fills 's' and 'l' if successful. Otherwise returns 1 if the
     209 * tracker doesn't support the scrape protocol, is unreachable or
     210 * replied with some error. tr_torrentScrape may block up to 20 seconds
     211 * before returning.
     212 **********************************************************************/
     213int tr_torrentScrape( tr_torrent_t *, int * s, int * l, int * d );
     214
     215/***********************************************************************
    205216 * tr_torrentStart
    206217 ***********************************************************************
Note: See TracChangeset for help on using the changeset viewer.