Changeset 5645
- Timestamp:
- Apr 18, 2008, 11:17:40 PM (14 years ago)
- Location:
- trunk/libtransmission
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/libtransmission/inout.c
r5644 r5645 69 69 if ((ioMode==TR_IO_READ) && !fileExists ) /* does file exist? */ 70 70 err = tr_ioErrorFromErrno( errno ); 71 else if ((fd = tr_fdFileCheckout ( tor->destination, file->name, ioMode==TR_IO_WRITE )) < 0) 71 else if ((fd = tr_fdFileCheckout ( tor->destination, 72 file->name, 73 ioMode==TR_IO_WRITE )) < 0) 72 74 err = fd; 73 75 else if( lseek( fd, (off_t)fileOffset, SEEK_SET ) == ((off_t)-1) ) … … 87 89 } 88 90 89 static tr_errno91 static void 90 92 findFileLocation( const tr_torrent * tor, 91 93 tr_piece_index_t pieceIndex, … … 110 112 size_t half = len / 2; 111 113 size_t middle = first + half; 112 if( inf->files[middle].offset + inf->files[middle].length < offset ) { 114 if( inf->files[middle].offset + inf->files[middle].length < offset ) 115 { 113 116 first = middle; 114 117 ++first; … … 125 128 assert( *fileIndex < inf->fileCount ); 126 129 assert( *fileOffset < inf->files[first].length ); 127 return 0;128 130 } 129 131 … … 162 164 163 165 static tr_errno 164 readOrWritePiece( tr_torrent * tor,165 int ioMode,166 tr_piece_index_t pieceIndex,167 uint32_t pieceOffset,168 uint8_t * buf,169 size_t buflen )166 readOrWritePiece( const tr_torrent * tor, 167 int ioMode, 168 tr_piece_index_t pieceIndex, 169 uint32_t pieceOffset, 170 uint8_t * buf, 171 size_t buflen ) 170 172 { 171 173 tr_errno err = 0; … … 174 176 const tr_info * info = &tor->info; 175 177 176 assert( pieceIndex < tor->info.pieceCount ); 177 assert( pieceOffset + buflen <= tr_torPieceCountBytes( tor, pieceIndex ) ); 178 179 if( !err ) 180 err = findFileLocation ( tor, pieceIndex, pieceOffset, &fileIndex, &fileOffset ); 178 if( pieceIndex >= tor->info.pieceCount ) 179 return TR_ERROR_ASSERT; 180 if( pieceOffset + buflen > tr_torPieceCountBytes( tor, pieceIndex ) ) 181 return TR_ERROR_ASSERT; 182 183 findFileLocation ( tor, pieceIndex, pieceOffset, 184 &fileIndex, &fileOffset ); 181 185 182 186 while( buflen && !err ) … … 195 199 buf += bytesThisPass; 196 200 buflen -= bytesThisPass; 197 fileIndex++;201 ++fileIndex; 198 202 fileOffset = 0; 199 203 } … … 209 213 uint8_t * buf ) 210 214 { 211 return readOrWritePiece( (tr_torrent*)tor, TR_IO_READ, pieceIndex, begin, buf, len );215 return readOrWritePiece( tor, TR_IO_READ, pieceIndex, begin, buf, len ); 212 216 } 213 217 214 218 tr_errno 215 tr_ioWrite( tr_torrent* tor,219 tr_ioWrite( const tr_torrent * tor, 216 220 tr_piece_index_t pieceIndex, 217 221 uint32_t begin, … … 227 231 228 232 static tr_errno 229 tr_ioRecalculateHash( const tr_torrent * tor,230 231 233 recalculateHash( const tr_torrent * tor, 234 tr_piece_index_t pieceIndex, 235 uint8_t * setme ) 232 236 { 233 237 static uint8_t * buf = NULL; … … 272 276 uint8_t hash[SHA_DIGEST_LENGTH]; 273 277 274 err = tr_ioRecalculateHash( tor, pieceIndex, hash ); 275 276 if( !err && memcmp( hash, tor->info.pieces[pieceIndex].hash, SHA_DIGEST_LENGTH ) ) 278 err = recalculateHash( tor, pieceIndex, hash ); 279 280 if( !err && memcmp( hash, tor->info.pieces[pieceIndex].hash, 281 SHA_DIGEST_LENGTH ) ) 277 282 err = TR_ERROR_IO_CHECKSUM; 278 283 -
trunk/libtransmission/inout.h
r5329 r5645 33 33 * or TR_ERROR_IO_* otherwise. 34 34 */ 35 int tr_ioRead( const struct tr_torrent * tor,36 tr_piece_index_t pieceIndex,37 uint32_t offset,38 uint32_t len,39 uint8_t * setme );35 tr_errno tr_ioRead( const struct tr_torrent * tor, 36 tr_piece_index_t pieceIndex, 37 uint32_t offset, 38 uint32_t len, 39 uint8_t * setme ); 40 40 41 41 /** … … 44 44 * or TR_ERROR_IO_* otherwise. 45 45 */ 46 tr_errno tr_ioWrite (struct tr_torrent * tor,47 tr_piece_index_tpieceIndex,48 uint32_toffset,49 uint32_tlen,50 const uint8_t* writeme );46 tr_errno tr_ioWrite( const struct tr_torrent * tor, 47 tr_piece_index_t pieceIndex, 48 uint32_t offset, 49 uint32_t len, 50 const uint8_t * writeme ); 51 51 52 52 /** -
trunk/libtransmission/platform.c
r5642 r5645 162 162 } 163 163 164 void165 tr_threadJoin( tr_thread * t )166 {167 if( t != NULL )168 {169 #ifdef __BEOS__170 long exit;171 wait_for_thread( t->thread, &exit );172 #elif defined(WIN32)173 WaitForSingleObject( t->thread_handle, INFINITE );174 CloseHandle( t->thread_handle );175 #else176 pthread_join( t->thread, NULL );177 #endif178 179 tr_dbg( "Thread '%s' joined", t->name );180 t->name = NULL;181 t->func = NULL;182 tr_free( t );183 }184 }185 186 164 /*** 187 165 **** LOCKS … … 211 189 l->lock = create_sem( 1, "" ); 212 190 #elif defined(WIN32) 213 InitializeCriticalSection( &l->lock ); /* critical sections supportrecursion */191 InitializeCriticalSection( &l->lock ); /* supports recursion */ 214 192 #else 215 193 pthread_mutexattr_t attr; … … 301 279 #else 302 280 struct passwd * pw = getpwuid( getuid() ); 303 endpwent( );304 281 if( pw ) 305 282 home = tr_strdup( pw->pw_dir ); 283 endpwent( ); 306 284 #endif 307 285 } -
trunk/libtransmission/platform.h
r5517 r5645 46 46 47 47 tr_thread* tr_threadNew ( void (*func)(void *), void * arg, const char * name ); 48 void tr_threadJoin ( tr_thread * );49 48 int tr_amInThread ( const tr_thread * ); 50 49 -
trunk/libtransmission/resume.c
r5643 r5645 67 67 tor->info.hash, &pex ); 68 68 if( count > 0 ) 69 tr_benc InitRaw( tr_bencDictAdd( dict, KEY_PEERS ), pex, sizeof(tr_pex)*count );69 tr_bencDictAddRaw( dict, KEY_PEERS, pex, sizeof(tr_pex)*count ); 70 70 tr_free( pex ); 71 71 } … … 250 250 tr_benc * p; 251 251 tr_benc * m; 252 tr_benc * b;253 252 const tr_bitfield * bitfield; 254 253 … … 267 266 /* add the bitfield */ 268 267 bitfield = tr_cpBlockBitfield( tor->completion ); 269 b = tr_bencDictAdd( p, KEY_PROGRESS_BITFIELD );270 tr_bencInitRaw( b,bitfield->bits, bitfield->len );268 tr_bencDictAddRaw( p, KEY_PROGRESS_BITFIELD, 269 bitfield->bits, bitfield->len ); 271 270 272 271 /* cleanup */
Note: See TracChangeset
for help on using the changeset viewer.