Changeset 7524
- Timestamp:
- Dec 29, 2008, 8:54:36 AM (12 years ago)
- Location:
- trunk/libtransmission
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/libtransmission/bandwidth.c
r7495 r7524 99 99 int magicNumber; 100 100 tr_session * session; 101 tr_ptrArray *children; /* struct tr_bandwidth */102 tr_ptrArray *peers; /* tr_peerIo */101 tr_ptrArray children; /* struct tr_bandwidth */ 102 tr_ptrArray peers; /* tr_peerIo */ 103 103 }; 104 104 … … 131 131 tr_bandwidth * b = tr_new0( tr_bandwidth, 1 ); 132 132 b->session = session; 133 b->children = tr_ptrArrayNew( );134 b->peers = tr_ptrArrayNew( );133 b->children = TR_PTR_ARRAY_INIT; 134 b->peers = TR_PTR_ARRAY_INIT; 135 135 b->magicNumber = MAGIC_NUMBER; 136 136 b->band[TR_UP].honorParentLimits = TRUE; … … 146 146 147 147 tr_bandwidthSetParent( b, NULL ); 148 tr_ptrArray Free(b->peers, NULL );149 tr_ptrArray Free(b->children, NULL );148 tr_ptrArrayDestruct( &b->peers, NULL ); 149 tr_ptrArrayDestruct( &b->children, NULL ); 150 150 b->magicNumber = 0xDEAD; 151 151 tr_free( b ); … … 167 167 assert( tr_isBandwidth( b->parent ) ); 168 168 169 tr_ptrArrayRemoveSorted( b->parent->children, b, comparePointers );169 tr_ptrArrayRemoveSorted( &b->parent->children, b, comparePointers ); 170 170 b->parent = NULL; 171 171 } … … 176 176 assert( parent->parent != b ); 177 177 178 tr_ptrArrayInsertSorted( parent->children, b, comparePointers );178 tr_ptrArrayInsertSorted( &parent->children, b, comparePointers ); 179 179 b->parent = parent; 180 180 } … … 270 270 { 271 271 int i; 272 const int n = tr_ptrArraySize(b->peers );272 const int n = TR_PTR_ARRAY_LENGTH( &b->peers ); 273 273 for( i=0; i<n; ++i ) 274 tr_ptrArrayAppend( peer_pool, tr_ptrArrayNth( b->peers, i ) );274 tr_ptrArrayAppend( peer_pool, tr_ptrArrayNth( &b->peers, i ) ); 275 275 } 276 276 … … 282 282 /* all children should reallocate too */ 283 283 if( 1 ) { 284 int i, n=0; 285 struct tr_bandwidth ** children = (struct tr_bandwidth**) tr_ptrArrayPeek( b->children, &n ); 284 int i; 285 struct tr_bandwidth ** children = (struct tr_bandwidth**) TR_PTR_ARRAY_DATA( &b->children ); 286 const int n = TR_PTR_ARRAY_LENGTH( &b->children ); 286 287 for( i=0; i<n; ++i ) 287 288 allocateBandwidth( children[i], dir, period_msec, peer_pool ); … … 295 296 { 296 297 int i, n, peerCount; 297 tr_ptrArray * tmp;298 tr_ptrArray tmp = TR_PTR_ARRAY_INIT; 298 299 struct tr_peerIo ** peers; 299 300 const uint64_t now = tr_date( ); … … 304 305 * 1. allocate bandwidth to b and its subtree 305 306 * 2. accumulate an array of all the peerIos from b and its subtree. */ 306 tmp = tr_ptrArrayNew( ); 307 allocateBandwidth( b, dir, period_msec, tmp ); 308 peers = (struct tr_peerIo**) tr_ptrArrayPeek( tmp, &peerCount ); 307 allocateBandwidth( b, dir, period_msec, &tmp ); 308 peers = (struct tr_peerIo**) tr_ptrArrayPeek( &tmp, &peerCount ); 309 309 310 310 /* Stop all peers from listening for the socket to be ready for IO. … … 348 348 349 349 /* cleanup */ 350 tr_ptrArray Free(tmp, NULL );350 tr_ptrArrayDestruct( &tmp, NULL ); 351 351 } 352 352 … … 362 362 assert( tr_isPeerIo( peerIo ) ); 363 363 364 tr_ptrArrayInsertSorted( b->peers, peerIo, comparePointers );364 tr_ptrArrayInsertSorted( &b->peers, peerIo, comparePointers ); 365 365 } 366 366 … … 372 372 assert( tr_isPeerIo( peerIo ) ); 373 373 374 tr_ptrArrayRemoveSorted( b->peers, peerIo, comparePointers );374 tr_ptrArrayRemoveSorted( &b->peers, peerIo, comparePointers ); 375 375 } 376 376 -
trunk/libtransmission/bencode.c
r7404 r7524 327 327 { 328 328 int err; 329 tr_ptrArray * parentStack = tr_ptrArrayNew( );329 tr_ptrArray parentStack = TR_PTR_ARRAY_INIT; 330 330 331 331 top->type = 0; /* set to `uninitialized' */ 332 err = tr_bencParseImpl( buf, end, top, parentStack, setme_end );332 err = tr_bencParseImpl( buf, end, top, &parentStack, setme_end ); 333 333 if( err ) 334 334 tr_bencFree( top ); 335 335 336 tr_ptrArray Free(parentStack, NULL );336 tr_ptrArrayDestruct( &parentStack, NULL ); 337 337 return err; 338 338 } … … 933 933 void * user_data ) 934 934 { 935 tr_ptrArray * stack = tr_ptrArrayNew( );936 937 tr_ptrArrayAppend( stack, nodeNew( top ) );938 939 while( !tr_ptrArrayEmpty( stack ) )940 { 941 struct SaveNode * node = tr_ptrArrayBack( stack );935 tr_ptrArray stack = TR_PTR_ARRAY_INIT; 936 937 tr_ptrArrayAppend( &stack, nodeNew( top ) ); 938 939 while( !tr_ptrArrayEmpty( &stack ) ) 940 { 941 struct SaveNode * node = tr_ptrArrayBack( &stack ); 942 942 const tr_benc * val; 943 943 … … 956 956 if( isContainer( node->val ) ) 957 957 walkFuncs->containerEndFunc( node->val, user_data ); 958 tr_ptrArrayPop( stack );958 tr_ptrArrayPop( &stack ); 959 959 tr_free( node->children ); 960 960 tr_free( node ); … … 974 974 case TYPE_LIST: 975 975 if( val != node->val ) 976 tr_ptrArrayAppend( stack, nodeNew( val ) );976 tr_ptrArrayAppend( &stack, nodeNew( val ) ); 977 977 else 978 978 walkFuncs->listBeginFunc( val, user_data ); … … 981 981 case TYPE_DICT: 982 982 if( val != node->val ) 983 tr_ptrArrayAppend( stack, nodeNew( val ) );983 tr_ptrArrayAppend( &stack, nodeNew( val ) ); 984 984 else 985 985 walkFuncs->dictBeginFunc( val, user_data ); … … 993 993 } 994 994 995 tr_ptrArray Free(stack, NULL );995 tr_ptrArrayDestruct( &stack, NULL ); 996 996 } 997 997 … … 1088 1088 if( val && val->type ) 1089 1089 { 1090 tr_ptrArray * freeme = tr_ptrArrayNew( );1090 tr_ptrArray a = TR_PTR_ARRAY_INIT; 1091 1091 struct WalkFuncs walkFuncs; 1092 1092 … … 1096 1096 walkFuncs.listBeginFunc = freeContainerBeginFunc; 1097 1097 walkFuncs.containerEndFunc = freeDummyFunc; 1098 bencWalk( val, &walkFuncs, freeme);1099 1100 tr_ptrArray Free( freeme, tr_free );1098 bencWalk( val, &walkFuncs, &a ); 1099 1100 tr_ptrArrayDestruct( &a, tr_free ); 1101 1101 } 1102 1102 } -
trunk/libtransmission/json.c
r7404 r7524 30 30 { 31 31 tr_benc * top; 32 tr_ptrArray *stack;32 tr_ptrArray stack; 33 33 char * key; 34 34 }; … … 40 40 tr_benc * node = NULL; 41 41 42 if( tr_ptrArrayEmpty( data->stack ) )42 if( tr_ptrArrayEmpty( &data->stack ) ) 43 43 parent = NULL; 44 44 else 45 parent = tr_ptrArrayBack( data->stack );45 parent = tr_ptrArrayBack( &data->stack ); 46 46 47 47 if( !parent ) … … 72 72 node = getNode( data ); 73 73 tr_bencInitList( node, 0 ); 74 tr_ptrArrayAppend( data->stack, node );74 tr_ptrArrayAppend( &data->stack, node ); 75 75 break; 76 76 77 77 case JSON_T_ARRAY_END: 78 tr_ptrArrayPop( data->stack );78 tr_ptrArrayPop( &data->stack ); 79 79 break; 80 80 … … 82 82 node = getNode( data ); 83 83 tr_bencInitDict( node, 0 ); 84 tr_ptrArrayAppend( data->stack, node );84 tr_ptrArrayAppend( &data->stack, node ); 85 85 break; 86 86 87 87 case JSON_T_OBJECT_END: 88 tr_ptrArrayPop( data->stack );88 tr_ptrArrayPop( &data->stack ); 89 89 break; 90 90 … … 149 149 data.key = NULL; 150 150 data.top = setme_benc; 151 data.stack = tr_ptrArrayNew( );151 data.stack = TR_PTR_ARRAY_INIT; 152 152 153 153 checker = new_JSON_parser( &config ); … … 162 162 163 163 delete_JSON_parser( checker ); 164 tr_ptrArray Free(data.stack, NULL );164 tr_ptrArrayDestruct( &data.stack, NULL ); 165 165 return err; 166 166 } -
trunk/libtransmission/peer-mgr.c
r7486 r7524 126 126 uint8_t hash[SHA_DIGEST_LENGTH]; 127 127 int * pendingRequestCount; 128 tr_ptrArray *outgoingHandshakes; /* tr_handshake */129 tr_ptrArray *pool; /* struct peer_atom */130 tr_ptrArray *peers; /* tr_peer */131 tr_ptrArray *webseeds; /* tr_webseed */128 tr_ptrArray outgoingHandshakes; /* tr_handshake */ 129 tr_ptrArray pool; /* struct peer_atom */ 130 tr_ptrArray peers; /* tr_peer */ 131 tr_ptrArray webseeds; /* tr_webseed */ 132 132 tr_timer * reconnectTimer; 133 133 tr_timer * rechokeTimer; … … 143 143 { 144 144 tr_session * session; 145 tr_ptrArray *torrents; /* Torrent */146 tr_ptrArray *incomingHandshakes; /* tr_handshake */147 tr_ptrArray *finishedHandshakes; /* tr_handshake */145 tr_ptrArray torrents; /* Torrent */ 146 tr_ptrArray incomingHandshakes; /* tr_handshake */ 147 tr_ptrArray finishedHandshakes; /* tr_handshake */ 148 148 tr_timer * bandwidthTimer; 149 149 }; … … 264 264 const uint8_t * hash ) 265 265 { 266 return (Torrent*) tr_ptrArrayFindSorted( manager->torrents,266 return (Torrent*) tr_ptrArrayFindSorted( &manager->torrents, 267 267 hash, 268 268 torrentCompareToHash ); … … 293 293 assert( addr ); 294 294 295 return tr_ptrArrayFindSorted( torrent->peers, addr, peerCompareToAddr );295 return tr_ptrArrayFindSorted( &torrent->peers, addr, peerCompareToAddr ); 296 296 } 297 297 … … 300 300 const tr_address * addr ) 301 301 { 302 Torrent * tt = (Torrent*)t; 302 303 assert( torrentIsLocked( t ) ); 303 return tr_ptrArrayFindSorted( t->pool, addr, comparePeerAtomToAddress );304 return tr_ptrArrayFindSorted( &tt->pool, addr, comparePeerAtomToAddress ); 304 305 } 305 306 … … 313 314 314 315 return getExistingPeer( t, addr ) 315 || getExistingHandshake( t->outgoingHandshakes, addr )316 || getExistingHandshake( t->manager->incomingHandshakes, addr );316 || getExistingHandshake( &t->outgoingHandshakes, addr ) 317 || getExistingHandshake( &t->manager->incomingHandshakes, addr ); 317 318 } 318 319 … … 340 341 { 341 342 peer = peerConstructor( torrent->tor, addr ); 342 tr_ptrArrayInsertSorted( torrent->peers, peer, peerCompare );343 tr_ptrArrayInsertSorted( &torrent->peers, peer, peerCompare ); 343 344 } 344 345 … … 381 382 atom->time = time( NULL ); 382 383 383 removed = tr_ptrArrayRemoveSorted( t->peers, peer, peerCompare );384 removed = tr_ptrArrayRemoveSorted( &t->peers, peer, peerCompare ); 384 385 assert( removed == peer ); 385 386 peerDestructor( removed ); … … 389 390 removeAllPeers( Torrent * t ) 390 391 { 391 while( !tr_ptrArrayEmpty( t->peers ) )392 removePeer( t, tr_ptrArrayNth( t->peers, 0 ) );392 while( !tr_ptrArrayEmpty( &t->peers ) ) 393 removePeer( t, tr_ptrArrayNth( &t->peers, 0 ) ); 393 394 } 394 395 … … 401 402 assert( t ); 402 403 assert( !t->isRunning ); 403 assert( t->peers );404 404 assert( torrentIsLocked( t ) ); 405 assert( tr_ptrArrayEmpty( t->outgoingHandshakes ) );406 assert( tr_ptrArrayEmpty( t->peers ) );405 assert( tr_ptrArrayEmpty( &t->outgoingHandshakes ) ); 406 assert( tr_ptrArrayEmpty( &t->peers ) ); 407 407 408 408 memcpy( hash, t->hash, SHA_DIGEST_LENGTH ); … … 412 412 tr_timerFree( &t->refillTimer ); 413 413 414 tr_ptrArray Free(t->webseeds, (PtrArrayForeachFunc)tr_webseedFree );415 tr_ptrArray Free(t->pool, (PtrArrayForeachFunc)tr_free );416 tr_ptrArray Free(t->outgoingHandshakes, NULL );417 tr_ptrArray Free(t->peers, NULL );414 tr_ptrArrayDestruct( &t->webseeds, (PtrArrayForeachFunc)tr_webseedFree ); 415 tr_ptrArrayDestruct( &t->pool, (PtrArrayForeachFunc)tr_free ); 416 tr_ptrArrayDestruct( &t->outgoingHandshakes, NULL ); 417 tr_ptrArrayDestruct( &t->peers, NULL ); 418 418 419 419 tr_free( t->pendingRequestCount ); … … 435 435 t->manager = manager; 436 436 t->tor = tor; 437 t->pool = tr_ptrArrayNew( );438 t->peers = tr_ptrArrayNew( );439 t->webseeds = tr_ptrArrayNew( );440 t->outgoingHandshakes = tr_ptrArrayNew( );437 t->pool = TR_PTR_ARRAY_INIT; 438 t->peers = TR_PTR_ARRAY_INIT; 439 t->webseeds = TR_PTR_ARRAY_INIT; 440 t->outgoingHandshakes = TR_PTR_ARRAY_INIT; 441 441 memcpy( t->hash, tor->info.hash, SHA_DIGEST_LENGTH ); 442 442 … … 444 444 { 445 445 tr_webseed * w = 446 tr_webseedNew( tor, tor->info.webseeds[i], peerCallbackFunc, 447 t ); 448 tr_ptrArrayAppend( t->webseeds, w ); 446 tr_webseedNew( tor, tor->info.webseeds[i], peerCallbackFunc, t ); 447 tr_ptrArrayAppend( &t->webseeds, w ); 449 448 } 450 449 … … 462 461 463 462 m->session = session; 464 m->torrents = tr_ptrArrayNew( );465 m->incomingHandshakes = tr_ptrArrayNew( );466 m->finishedHandshakes = tr_ptrArrayNew( );463 m->torrents = TR_PTR_ARRAY_INIT; 464 m->incomingHandshakes = TR_PTR_ARRAY_INIT; 465 m->finishedHandshakes = TR_PTR_ARRAY_INIT; 467 466 m->bandwidthTimer = tr_timerNew( session, bandwidthPulse, m, BANDWIDTH_PERIOD_MSEC ); 468 467 return m; … … 480 479 /* free the handshakes. Abort invokes handshakeDoneCB(), which removes 481 480 * the item from manager->handshakes, so this is a little roundabout... */ 482 while( !tr_ptrArrayEmpty( manager->incomingHandshakes ) )483 tr_handshakeAbort( tr_ptrArrayNth( manager->incomingHandshakes, 0 ) );484 485 tr_ptrArray Free(manager->incomingHandshakes, NULL );486 487 while(( handshake = tr_ptrArrayPop( manager->finishedHandshakes )))481 while( !tr_ptrArrayEmpty( &manager->incomingHandshakes ) ) 482 tr_handshakeAbort( tr_ptrArrayNth( &manager->incomingHandshakes, 0 ) ); 483 484 tr_ptrArrayDestruct( &manager->incomingHandshakes, NULL ); 485 486 while(( handshake = tr_ptrArrayPop( &manager->finishedHandshakes ))) 488 487 tr_handshakeFree( handshake ); 489 488 490 tr_ptrArray Free(manager->finishedHandshakes, NULL );489 tr_ptrArrayDestruct( &manager->finishedHandshakes, NULL ); 491 490 492 491 /* free the torrents. */ 493 tr_ptrArray Free(manager->torrents, torrentDestructor );492 tr_ptrArrayDestruct( &manager->torrents, torrentDestructor ); 494 493 495 494 managerUnlock( manager ); … … 506 505 assert( torrentIsLocked( t ) ); 507 506 508 peers = (tr_peer **) tr_ptrArrayPeek( t->peers, &peerCount );507 peers = (tr_peer **) tr_ptrArrayPeek( &t->peers, &peerCount ); 509 508 ret = tr_new( tr_peer *, peerCount ); 510 509 … … 759 758 int peerCount = 0; 760 759 int retCount = 0; 761 tr_peer ** peers = (tr_peer **) tr_ptrArrayPeek( t->peers, &peerCount );760 tr_peer ** peers = (tr_peer **) tr_ptrArrayPeek( &t->peers, &peerCount ); 762 761 tr_peer ** ret = tr_new( tr_peer *, peerCount ); 763 762 … … 813 812 blockIterator = blockIteratorNew( t ); 814 813 peers = getPeersUploadingToClient( t, &peerCount ); 815 webseedCount = tr_ptrArraySize( t->webseeds );816 webseeds = tr_memdup( tr_ptrArrayBase( t->webseeds ),814 webseedCount = tr_ptrArraySize( &t->webseeds ); 815 webseeds = tr_memdup( tr_ptrArrayBase( &t->webseeds ), 817 816 webseedCount * sizeof( tr_webseed* ) ); 818 817 … … 1183 1182 a->from = from; 1184 1183 tordbg( t, "got a new atom: %s", tr_peerIoAddrStr( &a->addr, a->port ) ); 1185 tr_ptrArrayInsertSorted( t->pool, a, comparePeerAtoms );1184 tr_ptrArrayInsertSorted( &t->pool, a, comparePeerAtoms ); 1186 1185 } 1187 1186 } … … 1196 1195 getPeerCount( const Torrent * t ) 1197 1196 { 1198 return tr_ptrArraySize( t->peers ) + tr_ptrArraySize(t->outgoingHandshakes );1197 return tr_ptrArraySize( &t->peers ) + tr_ptrArraySize( &t->outgoingHandshakes ); 1199 1198 } 1200 1199 … … 1223 1222 1224 1223 if( tr_peerIoIsIncoming ( io ) ) 1225 ours = tr_ptrArrayRemoveSorted( manager->incomingHandshakes,1224 ours = tr_ptrArrayRemoveSorted( &manager->incomingHandshakes, 1226 1225 handshake, handshakeCompare ); 1227 1226 else if( t ) 1228 ours = tr_ptrArrayRemoveSorted( t->outgoingHandshakes,1227 ours = tr_ptrArrayRemoveSorted( &t->outgoingHandshakes, 1229 1228 handshake, handshakeCompare ); 1230 1229 else … … 1297 1296 1298 1297 if( !success ) 1299 tr_ptrArrayAppend( manager->finishedHandshakes, handshake );1298 tr_ptrArrayAppend( &manager->finishedHandshakes, handshake ); 1300 1299 1301 1300 if( t ) … … 1318 1317 tr_netClose( socket ); 1319 1318 } 1320 else if( getExistingHandshake( manager->incomingHandshakes, addr ) )1319 else if( getExistingHandshake( &manager->incomingHandshakes, addr ) ) 1321 1320 { 1322 1321 tr_netClose( socket ); … … 1334 1333 manager ); 1335 1334 1336 tr_ptrArrayInsertSorted( manager->incomingHandshakes, handshake,1335 tr_ptrArrayInsertSorted( &manager->incomingHandshakes, handshake, 1337 1336 handshakeCompare ); 1338 1337 } … … 1457 1456 assert( torrentIsLocked( t ) ); 1458 1457 1459 peers = (tr_peer **) tr_ptrArrayPeek( t->peers, &peerCount );1458 peers = (tr_peer **) tr_ptrArrayPeek( &t->peers, &peerCount ); 1460 1459 for( i = 0; i < peerCount; ++i ) 1461 1460 { … … 1509 1508 uint8_t af) 1510 1509 { 1511 int peerCount = 0;1512 1510 int peersReturning = 0; 1513 1511 const Torrent * t; … … 1523 1521 { 1524 1522 int i; 1525 const tr_peer ** peers = (const tr_peer **) tr_ptrArrayPeek( t->peers, &peerCount ); 1523 const tr_peer ** peers = (const tr_peer**) TR_PTR_ARRAY_DATA( &t->peers ); 1524 const int peerCount = TR_PTR_ARRAY_LENGTH( &t->peers ); 1526 1525 /* for now, this will waste memory on torrents that have both 1527 1526 * ipv6 and ipv4 peers */ … … 1592 1591 rechokePulse( t ); 1593 1592 1594 if( !tr_ptrArrayEmpty( t->webseeds ) )1593 if( !tr_ptrArrayEmpty( &t->webseeds ) ) 1595 1594 refillSoon( t ); 1596 1595 } … … 1609 1608 1610 1609 /* disconnect the peers. */ 1611 tr_ptrArrayForeach( t->peers, (PtrArrayForeachFunc)peerDestructor );1612 tr_ptrArrayClear( t->peers );1610 tr_ptrArrayForeach( &t->peers, (PtrArrayForeachFunc)peerDestructor ); 1611 tr_ptrArrayClear( &t->peers ); 1613 1612 1614 1613 /* disconnect the handshakes. handshakeAbort calls handshakeDoneCB(), 1615 1614 * which removes the handshake from t->outgoingHandshakes... */ 1616 while( !tr_ptrArrayEmpty( t->outgoingHandshakes ) )1617 tr_handshakeAbort( tr_ptrArrayNth( t->outgoingHandshakes, 0 ) );1615 while( !tr_ptrArrayEmpty( &t->outgoingHandshakes ) ) 1616 tr_handshakeAbort( tr_ptrArrayNth( &t->outgoingHandshakes, 0 ) ); 1618 1617 } 1619 1618 … … 1641 1640 1642 1641 t = torrentConstructor( manager, tor ); 1643 tr_ptrArrayInsertSorted( manager->torrents, t, torrentCompare );1642 tr_ptrArrayInsertSorted( &manager->torrents, t, torrentCompare ); 1644 1643 1645 1644 managerUnlock( manager ); … … 1657 1656 assert( t ); 1658 1657 stopTorrent( t ); 1659 tr_ptrArrayRemoveSorted( manager->torrents, t, torrentCompare );1658 tr_ptrArrayRemoveSorted( &manager->torrents, t, torrentCompare ); 1660 1659 torrentDestructor( t ); 1661 1660 … … 1683 1682 interval = tor->info.pieceCount / (float)tabCount; 1684 1683 isSeed = tor && ( tr_cpGetStatus ( tor->completion ) == TR_SEED ); 1685 peers = (const tr_peer **) tr_ptrArrayPeek( t->peers, &peerCount ); 1684 peers = (const tr_peer **) TR_PTR_ARRAY_DATA( &t->peers ); 1685 peerCount = TR_PTR_ARRAY_LENGTH( &t->peers ); 1686 1686 1687 1687 memset( tab, 0, tabCount ); … … 1735 1735 1736 1736 t = getExistingTorrent( (tr_peerMgr*)manager, torrentHash ); 1737 ret = t && ( !tr_ptrArrayEmpty( t->peers ) || !tr_ptrArrayEmpty(t->webseeds ) );1737 ret = t && ( !tr_ptrArrayEmpty( &t->peers ) || !tr_ptrArrayEmpty( &t->webseeds ) ); 1738 1738 1739 1739 managerUnlock( manager ); … … 1760 1760 1761 1761 t = getExistingTorrent( (tr_peerMgr*)manager, torrentHash ); 1762 peers = (const tr_peer **) tr_ptrArrayPeek( t->peers, &size ); 1763 1764 *setmePeersKnown = tr_ptrArraySize( t->pool ); 1762 peers = (const tr_peer **) TR_PTR_ARRAY_DATA( &t->peers ); 1763 size = TR_PTR_ARRAY_LENGTH( &t->peers ); 1764 1765 *setmePeersKnown = tr_ptrArraySize( &t->pool ); 1765 1766 *setmePeersConnected = 0; 1766 1767 *setmeSeedsConnected = 0; … … 1794 1795 } 1795 1796 1796 webseeds = (const tr_webseed **) tr_ptrArrayPeek( t->webseeds, &size ); 1797 webseeds = (const tr_webseed**) TR_PTR_ARRAY_DATA( &t->webseeds ); 1798 size = TR_PTR_ARRAY_LENGTH( &t->webseeds ); 1797 1799 for( i=0; i<size; ++i ) 1798 1800 if( tr_webseedIsActive( webseeds[i] ) ) … … 1816 1818 1817 1819 t = getExistingTorrent( (tr_peerMgr*)manager, torrentHash ); 1818 webseeds = (const tr_webseed**) tr_ptrArrayPeek( t->webseeds,1819 &webseedCount);1820 webseeds = (const tr_webseed**) TR_PTR_ARRAY_DATA( &t->webseeds ); 1821 webseedCount = TR_PTR_ARRAY_LENGTH( &t->webseeds ); 1820 1822 assert( webseedCount == t->tor->info.webseedCount ); 1821 1823 ret = tr_new0( float, webseedCount ); … … 2015 2017 int n; 2016 2018 struct ChokeData * c; 2017 tr_ptrArray * randPool = tr_ptrArrayNew( );2019 tr_ptrArray randPool = TR_PTR_ARRAY_INIT; 2018 2020 2019 2021 for( ; i<size; ++i ) … … 2026 2028 if( isSame( peer ) ) x *= 3; 2027 2029 for( y=0; y<x; ++y ) 2028 tr_ptrArrayAppend( randPool, &choke[i] );2030 tr_ptrArrayAppend( &randPool, &choke[i] ); 2029 2031 } 2030 2032 } 2031 2033 2032 if(( n = tr_ptrArraySize( randPool )))2034 if(( n = tr_ptrArraySize( &randPool ))) 2033 2035 { 2034 c = tr_ptrArrayNth( randPool, tr_cryptoWeakRandInt( n ));2036 c = tr_ptrArrayNth( &randPool, tr_cryptoWeakRandInt( n )); 2035 2037 c->doUnchoke = 1; 2036 2038 t->optimistic = c->peer; 2037 2039 } 2038 2040 2039 tr_ptrArray Free(randPool, NULL );2041 tr_ptrArrayDestruct( &randPool, NULL ); 2040 2042 } 2041 2043 … … 2134 2136 { 2135 2137 int i, peerCount, outsize; 2136 tr_peer ** peers = (tr_peer**) tr_ptrArrayPeek( t->peers, &peerCount );2138 tr_peer ** peers = (tr_peer**) tr_ptrArrayPeek( &t->peers, &peerCount ); 2137 2139 struct tr_peer ** ret = tr_new( tr_peer *, peerCount ); 2138 2140 … … 2220 2222 assert( torrentIsLocked( t ) ); 2221 2223 2222 atoms = (struct peer_atom**) tr_ptrArrayPeek( t->pool, &atomCount );2224 atoms = (struct peer_atom**) tr_ptrArrayPeek( &t->pool, &atomCount ); 2223 2225 ret = tr_new( struct peer_atom*, atomCount ); 2224 2226 for( i = retCount = 0; i < atomCount; ++i ) … … 2299 2301 "%d connection candidates, %d atoms, max per pulse is %d", 2300 2302 t->tor->info.name, nBad, nCandidates, 2301 tr_ptrArraySize( t->pool ),2303 tr_ptrArraySize( &t->pool ), 2302 2304 (int)MAX_RECONNECTIONS_PER_PULSE ); 2303 2305 … … 2346 2348 ++newConnectionsThisSecond; 2347 2349 2348 tr_ptrArrayInsertSorted( t->outgoingHandshakes, handshake,2350 tr_ptrArrayInsertSorted( &t->outgoingHandshakes, handshake, 2349 2351 handshakeCompare ); 2350 2352 } … … 2371 2373 pumpAllPeers( tr_peerMgr * mgr ) 2372 2374 { 2373 const int torrentCount = tr_ptrArraySize( mgr->torrents );2375 const int torrentCount = tr_ptrArraySize( &mgr->torrents ); 2374 2376 int i, j; 2375 2377 2376 2378 for( i=0; i<torrentCount; ++i ) 2377 2379 { 2378 Torrent * t = tr_ptrArrayNth( mgr->torrents, i );2379 for( j=0; j<tr_ptrArraySize( t->peers ); ++j )2380 Torrent * t = tr_ptrArrayNth( &mgr->torrents, i ); 2381 for( j=0; j<tr_ptrArraySize( &t->peers ); ++j ) 2380 2382 { 2381 tr_peer * peer = tr_ptrArrayNth( t->peers, j );2383 tr_peer * peer = tr_ptrArrayNth( &t->peers, j ); 2382 2384 tr_peerMsgsPulse( peer->msgs ); 2383 2385 } … … 2400 2402 2401 2403 /* free all the finished handshakes */ 2402 while(( handshake = tr_ptrArrayPop( mgr->finishedHandshakes )))2404 while(( handshake = tr_ptrArrayPop( &mgr->finishedHandshakes ))) 2403 2405 tr_handshakeFree( handshake ); 2404 2406 -
trunk/libtransmission/ptrarray.c
r7404 r7524 20 20 #define GROW 32 21 21 22 struct tr_ptrArray 23 { 24 void ** items; 25 int n_items; 26 int n_alloc; 27 }; 22 const tr_ptrArray TR_PTR_ARRAY_INIT = { NULL, 0, 0 }; 23 24 void 25 tr_ptrArrayDestruct( tr_ptrArray * p, PtrArrayForeachFunc func ) 26 { 27 assert( p ); 28 assert( p->items || !p->n_items ); 29 30 if( func ) 31 tr_ptrArrayForeach( p, func ); 32 33 tr_free( p->items ); 34 35 memset( p, ~0, sizeof( tr_ptrArray ) ); 36 } 28 37 29 38 tr_ptrArray* 30 39 tr_ptrArrayNew( void ) 31 40 { 32 tr_ptrArray * p; 33 34 p = tr_new( tr_ptrArray, 1 ); 35 p->n_items = 0; 36 p->n_alloc = 0; 37 p->items = NULL; 38 41 tr_ptrArray * p = tr_new( tr_ptrArray, 1 ); 42 *p = TR_PTR_ARRAY_INIT; 39 43 return p; 40 44 } … … 70 74 PtrArrayForeachFunc func ) 71 75 { 72 assert( t ); 73 assert( t->items || !t->n_items ); 74 75 if( func ) 76 tr_ptrArrayForeach( t, func ); 77 78 tr_free( t->items ); 76 tr_ptrArrayDestruct( t, func ); 79 77 tr_free( t ); 80 78 } -
trunk/libtransmission/ptrarray.h
r7404 r7524 33 33 * A simple pointer array that resizes itself dynamically. 34 34 */ 35 typedef struct tr_ptrArray tr_ptrArray; 35 typedef struct tr_ptrArray 36 { 37 void ** items; 38 int n_items; 39 int n_alloc; 40 } 41 tr_ptrArray; 42 43 #define TR_PTR_ARRAY_DATA( A ) ((A)->items) 44 #define TR_PTR_ARRAY_LENGTH( A ) ((A)->n_items) 36 45 37 46 typedef void ( *PtrArrayForeachFunc )( void * ); 47 48 extern const tr_ptrArray TR_PTR_ARRAY_INIT; 49 50 void tr_ptrArrayDestruct( tr_ptrArray*, PtrArrayForeachFunc func ); 38 51 39 52 tr_ptrArray * tr_ptrArrayNew( void ); -
trunk/libtransmission/torrent.c
r7476 r7524 1842 1842 char * tmp; 1843 1843 tr_ptrArrayInsertSorted( dirtyFolders, tr_strdup( dir ), vstrcmp ); 1844 1844 1845 tmp = tr_dirname( dir ); 1845 1846 tr_free( dir ); … … 1896 1897 char ** s; 1897 1898 tr_file_index_t f; 1898 tr_ptrArray * torrentFiles = tr_ptrArrayNew( );1899 tr_ptrArray * folders = tr_ptrArrayNew( );1900 tr_ptrArray * dirtyFolders = tr_ptrArrayNew( ); /* dirty == contains non-torrent files */1899 tr_ptrArray torrentFiles = TR_PTR_ARRAY_INIT; 1900 tr_ptrArray folders = TR_PTR_ARRAY_INIT; 1901 tr_ptrArray dirtyFolders = TR_PTR_ARRAY_INIT; /* dirty == contains non-torrent files */ 1901 1902 1902 1903 const char * firstFile = tor->info.files[0].name; … … 1906 1907 1907 1908 for( f=0; f<tor->info.fileCount; ++f ) 1908 tr_ptrArrayInsertSorted( torrentFiles, tor->info.files[f].name, vstrcmp );1909 tr_ptrArrayInsertSorted( &torrentFiles, tor->info.files[f].name, vstrcmp ); 1909 1910 1910 1911 /* build the set of folders and dirtyFolders */ 1911 walkLocalData( tor, root, root, NULL, torrentFiles, folders,dirtyFolders );1912 walkLocalData( tor, root, root, NULL, &torrentFiles, &folders, &dirtyFolders ); 1912 1913 1913 1914 /* close all the files because we're about to delete them */ … … 1919 1920 1920 1921 /* try to remove entire folders first, so that the recycle bin will be tidy */ 1921 s = (char**) tr_ptrArrayPeek( folders, &n );1922 s = (char**) tr_ptrArrayPeek( &folders, &n ); 1922 1923 for( i=0; i<n; ++i ) 1923 if( tr_ptrArrayFindSorted( dirtyFolders, s[i], vstrcmp ) == NULL )1924 if( tr_ptrArrayFindSorted( &dirtyFolders, s[i], vstrcmp ) == NULL ) 1924 1925 fileFunc( s[i] ); 1925 1926 1926 /* now blow away any remaining torrent files, such torrent files in dirty folders */1927 /* now blow away any remaining torrent files, such as torrent files in dirty folders */ 1927 1928 for( f=0; f<tor->info.fileCount; ++f ) { 1928 1929 char * path = tr_buildPath( tor->downloadDir, tor->info.files[f].name, NULL ); … … 1935 1936 * won't prevent the upper folders from being deleted */ 1936 1937 { 1937 tr_ptrArray * cleanFolders = tr_ptrArrayNew( );1938 s = (char**) tr_ptrArrayPeek( folders, &n );1938 tr_ptrArray cleanFolders = TR_PTR_ARRAY_INIT; 1939 s = (char**) tr_ptrArrayPeek( &folders, &n ); 1939 1940 for( i=0; i<n; ++i ) 1940 if( tr_ptrArrayFindSorted( dirtyFolders, s[i], vstrcmp ) == NULL )1941 tr_ptrArrayInsertSorted( cleanFolders, s[i], compareLongestFirst );1942 s = (char**) tr_ptrArrayPeek( cleanFolders, &n );1941 if( tr_ptrArrayFindSorted( &dirtyFolders, s[i], vstrcmp ) == NULL ) 1942 tr_ptrArrayInsertSorted( &cleanFolders, s[i], compareLongestFirst ); 1943 s = (char**) tr_ptrArrayPeek( &cleanFolders, &n ); 1943 1944 for( i=0; i<n; ++i ) 1944 1945 fileFunc( s[i] ); 1945 tr_ptrArray Free(cleanFolders, NULL );1946 tr_ptrArrayDestruct( &cleanFolders, NULL ); 1946 1947 } 1947 1948 1948 1949 /* cleanup */ 1949 tr_ptrArray Free(dirtyFolders, tr_free );1950 tr_ptrArray Free(folders, tr_free );1951 tr_ptrArray Free(torrentFiles, NULL );1950 tr_ptrArrayDestruct( &dirtyFolders, tr_free ); 1951 tr_ptrArrayDestruct( &folders, tr_free ); 1952 tr_ptrArrayDestruct( &torrentFiles, NULL ); 1952 1953 tr_free( root ); 1953 1954 tr_free( tmp ); … … 1963 1964 deleteLocalData( tor, fileFunc ); 1964 1965 else { 1966 /* torrent only has one file */ 1965 1967 char * path = tr_buildPath( tor->downloadDir, tor->info.files[0].name, NULL ); 1968 tr_fdFileClose( path ); 1966 1969 fileFunc( path ); 1967 1970 tr_free( path );
Note: See TracChangeset
for help on using the changeset viewer.