Changeset 766


Ignore:
Timestamp:
Aug 13, 2006, 9:16:18 PM (15 years ago)
Author:
livings124
Message:

Get peers separately from the rest of the stats. This should also get rid of a memory leak.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/transmission.c

    r765 r766  
    435435   
    436436    tr_peer_t * peer;
    437     s->peers = (tr_peer_stat_t *) calloc( tor->peerCount, sizeof( tr_peer_stat_t ) );
    438 
    439437    for( i = 0; i < tor->peerCount; i++ )
    440438    {
    441439        peer = tor->peers[i];
    442        
    443         s->peers[i].client = tr_clientForId(tr_peerId(peer));
    444         s->peers[i].isDownloading = tr_peerIsDownloading(peer);
    445         s->peers[i].isUploading = tr_peerIsUploading(peer);
    446440   
    447441        if( tr_peerIsConnected( peer ) )
     
    489483
    490484    return s;
     485}
     486
     487tr_peer_stat_t * tr_torrentPeers( tr_torrent_t * tor, int * peerCount )
     488{
     489    *peerCount = tor->peerCount;
     490   
     491    tr_peer_stat_t * peers = (tr_peer_stat_t *) calloc( tor->peerCount, sizeof( tr_peer_stat_t ) );
     492    if (peers != NULL)
     493    {
     494        tr_peer_t * peer;
     495        int i = 0;
     496        for( i = 0; i < tor->peerCount; i++ )
     497        {
     498            peer = tor->peers[i];
     499           
     500            peers[i].client = tr_clientForId(tr_peerId(peer));
     501            peers[i].isDownloading = tr_peerIsDownloading(peer);
     502            peers[i].isUploading = tr_peerIsUploading(peer);
     503        }
     504    }
     505   
     506    return peers;
     507}
     508
     509void tr_torrentPeersFree( tr_peer_stat_t * peers )
     510{
     511    free( peers );
    491512}
    492513
  • trunk/libtransmission/transmission.h

    r765 r766  
    212212
    213213/***********************************************************************
     214 * tr_torrentPeers
     215 ***********************************************************************/
     216typedef struct tr_peer_stat_s tr_peer_stat_t;
     217tr_peer_stat_t * tr_torrentPeers( tr_torrent_t *, int * peerCount );
     218void tr_torrentPeersFree( tr_peer_stat_t * );
     219
     220/***********************************************************************
    214221 * tr_torrentAvailability
    215222 ***********************************************************************
     
    280287 * tr_stat_s
    281288 **********************************************************************/
    282 typedef struct tr_peer_stat_s
    283 {
    284     char *  client;
    285    
    286     int     isDownloading;
    287     int     isUploading;
    288 }
    289 tr_peer_stat_t;
    290289struct tr_stat_s
    291290{
     
    312311    int                 eta;
    313312    int                 peersTotal;
    314     tr_peer_stat_t *    peers;
    315313    int                 peersUploading;
    316314    int                 peersDownloading;
     
    322320};
    323321
     322struct tr_peer_stat_s
     323{
     324    char *  client;
     325   
     326    int     isDownloading;
     327    int     isUploading;
     328};
     329
    324330#ifdef __TRANSMISSION__
    325331#  include "internal.h"
  • trunk/macosx/Torrent.m

    r765 r766  
    518518- (NSArray *) peers
    519519{
    520     int totalPeers = [self totalPeers], i;
     520    int totalPeers, i;
     521   
     522    tr_peer_stat_t * peers = tr_torrentPeers(fHandle, & totalPeers);
    521523    tr_peer_stat_t peer;
    522524   
    523     NSMutableArray * peers = [NSMutableArray arrayWithCapacity: totalPeers];
     525    NSMutableArray * peerDics = [NSMutableArray arrayWithCapacity: totalPeers];
    524526    for (i = 0; i < totalPeers; i++)
    525527    {
    526         peer = fStat->peers[i];
    527    
    528         [peers addObject: [NSDictionary dictionaryWithObjectsAndKeys:
     528        peer = peers[i];
     529   
     530        [peerDics addObject: [NSDictionary dictionaryWithObjectsAndKeys:
    529531            [NSString stringWithCString: (char *) peer.client encoding: NSUTF8StringEncoding], @"Client",
    530532            [NSNumber numberWithBool: peer.isDownloading], @"UL To",
     
    533535    //NSLog(@"%d", tr_peerId(peer));
    534536   
    535     return peers;
     537    return peerDics;
    536538}
    537539
Note: See TracChangeset for help on using the changeset viewer.