Changeset 7692


Ignore:
Timestamp:
Jan 12, 2009, 9:59:53 PM (13 years ago)
Author:
charles
Message:

(trunk libT) close open files immediately after they're done downloading

Location:
trunk/libtransmission
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/completion.c

    r7647 r7692  
    316316    return cp->completeBlocks[piece] == tr_torPieceCountBlocks( cp->tor, piece );
    317317}
     318
     319tr_bool
     320tr_cpFileIsComplete( const tr_completion * cp, tr_file_index_t fileIndex )
     321{
     322    tr_block_index_t block;
     323
     324    const tr_torrent * tor = cp->tor;
     325    const tr_file * file = &tor->info.files[fileIndex];
     326    const tr_block_index_t firstBlock = file->offset / tor->blockSize;
     327    const tr_block_index_t lastBlock = ( file->offset + file->length - 1 ) / tor->blockSize;
     328
     329    assert( tr_torBlockPiece( tor, firstBlock ) == file->firstPiece );
     330    assert( tr_torBlockPiece( tor, lastBlock ) == file->lastPiece );
     331
     332    for( block=firstBlock; block<=lastBlock; ++block )
     333        if( !tr_cpBlockIsComplete( cp, block ) )
     334            return FALSE;
     335
     336    return TRUE;
     337}
  • trunk/libtransmission/completion.h

    r7663 r7692  
    129129                      tr_piece_index_t   piece );
    130130
     131tr_bool tr_cpFileIsComplete( const tr_completion * cp, tr_file_index_t );
     132
    131133/**
    132134*** Blocks
    133135**/
    134136
    135 static TR_INLINE int tr_cpBlockIsComplete( const tr_completion * cp, tr_block_index_t block ) {
     137static TR_INLINE tr_bool tr_cpBlockIsComplete( const tr_completion * cp, tr_block_index_t block ) {
    136138    return tr_bitfieldHas( &cp->blockBitfield, block );
    137139}
  • trunk/libtransmission/peer-mgr.c

    r7663 r7692  
    2727#include "completion.h"
    2828#include "crypto.h"
     29#include "fdlimit.h"
    2930#include "handshake.h"
    3031#include "inout.h" /* tr_ioTestPiece */
     
    10631064        case TR_PEER_CLIENT_GOT_BLOCK:
    10641065        {
    1065             tr_torrent *     tor = t->tor;
     1066            tr_torrent * tor = t->tor;
    10661067
    10671068            tr_block_index_t block = _tr_block( tor, e->pieceIndex, e->offset );
     
    10881089
    10891090                if( !ok )
     1091                {
    10901092                    gotBadPiece( t, p );
     1093                }
    10911094                else
    10921095                {
    10931096                    int i;
    1094                     int peerCount = tr_ptrArraySize( &t->peers );
    1095                     tr_peer ** peers = (tr_peer**) tr_ptrArrayBase( &t->peers );
     1097                    int peerCount;
     1098                    tr_peer ** peers;
     1099                    tr_file_index_t fileIndex;
     1100
     1101                    peerCount = tr_ptrArraySize( &t->peers );
     1102                    peers = (tr_peer**) tr_ptrArrayBase( &t->peers );
    10961103                    for( i=0; i<peerCount; ++i )
    10971104                        tr_peerMsgsHave( peers[i]->msgs, p );
     1105
     1106                    for( fileIndex=0; fileIndex<tor->info.fileCount; ++fileIndex )
     1107                    {
     1108                        const tr_file * file = &tor->info.files[fileIndex];
     1109                        if( ( file->firstPiece <= p ) && ( p <= file->lastPiece ) && tr_cpFileIsComplete( &tor->completion, fileIndex ) )
     1110                        {
     1111                            char * path = tr_buildPath( tor->downloadDir, file->name, NULL );
     1112                            tordbg( t, "closing recently-completed file \"%s\"", path );
     1113                            tr_fdFileClose( path );
     1114                            tr_free( path );
     1115                        }
     1116                    }
    10981117                }
    10991118
Note: See TracChangeset for help on using the changeset viewer.