Changeset 7078


Ignore:
Timestamp:
Nov 8, 2008, 10:24:07 PM (10 years ago)
Author:
charles
Message:

(libT) #1442: removing a webseed torrent while it's running causes it to crash

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/webseed.c

    r6971 r7078  
    3030    unsigned int        dead : 1;
    3131
    32     tr_torrent *        torrent;
    33     char *              url;
    34 
    35     tr_delivery_func *  callback;
     32    uint8_t             hash[SHA_DIGEST_LENGTH];
     33
     34    char              * url;
     35
     36    tr_delivery_func  * callback;
    3637    void *              callback_userdata;
    3738
     
    4041    uint32_t            byteCount;
    4142
    42     tr_ratecontrol *    rateDown;
    43 
    44     struct evbuffer *   content;
     43    tr_ratecontrol    * rateDown;
     44
     45    tr_session        * session;
     46
     47    struct evbuffer   * content;
    4548};
    4649
     
    205208
    206209static void
    207 webResponseFunc( tr_handle   * session UNUSED,
    208                  long                  response_code,
    209                  const void *          response,
    210                  size_t                response_byte_count,
    211                  void *                vw )
     210webResponseFunc( tr_handle     * session,
     211                 long            response_code,
     212                 const void    * response,
     213                 size_t          response_byte_count,
     214                 void          * vw )
    212215{
    213216    tr_webseed * w = vw;
     217    tr_torrent * tor = tr_torrentFindFromHash( session, w->hash );
    214218    const int    success = ( response_code == 206 );
    215219
     
    220224        /* FIXME */
    221225    }
    222     else
     226    else if( tor != NULL )
    223227    {
    224228        evbuffer_add( w->content, response, response_byte_count );
     
    232236            requestNextChunk( w );
    233237        else {
    234             tr_ioWrite( w->torrent, w->pieceIndex, w->pieceOffset, w->byteCount, EVBUFFER_DATA(w->content) );
     238            tr_ioWrite( tor, w->pieceIndex, w->pieceOffset, w->byteCount, EVBUFFER_DATA(w->content) );
    235239            evbuffer_drain( w->content, EVBUFFER_LENGTH( w->content ) );
    236240            w->busy = 0;
     
    248252requestNextChunk( tr_webseed * w )
    249253{
    250     const tr_info * inf = tr_torrentInfo( w->torrent );
    251     const uint32_t have = EVBUFFER_LENGTH( w->content );
    252     const uint32_t left = w->byteCount - have;
    253     const uint32_t pieceOffset = w->pieceOffset + have;
    254     tr_file_index_t fileIndex;
    255     uint64_t fileOffset;
    256     uint32_t thisPass;
    257     char * url;
    258     char * range;
    259 
    260     tr_ioFindFileLocation( w->torrent, w->pieceIndex, pieceOffset,
    261                            &fileIndex, &fileOffset );
    262     thisPass = MIN( left, inf->files[fileIndex].length - fileOffset );
    263 
    264     url = makeURL( w, &inf->files[fileIndex] );
     254    tr_torrent * tor = tr_torrentFindFromHash( w->session, w->hash );
     255
     256    if( tor != NULL )
     257    {
     258        const tr_info * inf = tr_torrentInfo( tor );
     259        const uint32_t have = EVBUFFER_LENGTH( w->content );
     260        const uint32_t left = w->byteCount - have;
     261        const uint32_t pieceOffset = w->pieceOffset + have;
     262        tr_file_index_t fileIndex;
     263        uint64_t fileOffset;
     264        uint32_t thisPass;
     265        char * url;
     266        char * range;
     267
     268        tr_ioFindFileLocation( tor, w->pieceIndex, pieceOffset,
     269                               &fileIndex, &fileOffset );
     270        thisPass = MIN( left, inf->files[fileIndex].length - fileOffset );
     271
     272        url = makeURL( w, &inf->files[fileIndex] );
    265273/*fprintf( stderr, "url is [%s]\n", url );*/
    266     range = tr_strdup_printf( "%"PRIu64"-%"PRIu64, fileOffset, fileOffset + thisPass - 1 );
     274        range = tr_strdup_printf( "%"PRIu64"-%"PRIu64, fileOffset, fileOffset + thisPass - 1 );
    267275/*fprintf( stderr, "range is [%s] ... we want %lu total, we have %lu, so %lu are left, and we're asking for %lu this time\n", range, (unsigned long)w->byteCount, (unsigned long)have, (unsigned long)left, (unsigned long)thisPass );*/
    268     tr_webRun( w->torrent->session, url, range, webResponseFunc, w );
    269     tr_free( range );
    270     tr_free( url );
     276        tr_webRun( w->session, url, range, webResponseFunc, w );
     277        tr_free( range );
     278        tr_free( url );
     279    }
    271280}
    272281
     
    325334    tr_webseed * w = tr_new0( tr_webseed, 1 );
    326335
     336    memcpy( w->hash, torrent->info.hash, SHA_DIGEST_LENGTH );
     337    w->session = torrent->session;
    327338    w->content = evbuffer_new( );
    328339    w->rateDown = tr_rcInit( );
    329     w->torrent = torrent;
    330340    w->url = tr_strdup( url );
    331341    w->callback = callback;
Note: See TracChangeset for help on using the changeset viewer.