From ebf7b6eac1cf3c518f8adaf7748b84c0a0c43fd9 Mon Sep 17 00:00:00 2001 From: Mitchell Livingston Date: Mon, 14 Aug 2006 22:27:34 +0000 Subject: [PATCH] Lock and unlock while accessing peers in libtransmission. Handle lack of client id in clients.h rather than the gui. --- libtransmission/clients.c | 5 ++++- libtransmission/transmission.c | 4 ++++ macosx/Torrent.m | 9 ++------- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/libtransmission/clients.c b/libtransmission/clients.c index 225aac017..e76f495d5 100644 --- a/libtransmission/clients.c +++ b/libtransmission/clients.c @@ -87,8 +87,11 @@ char * tr_clientForId( uint8_t * id ) if( !ret ) { - asprintf( &ret, "unknown client (%c%c%c%c%c%c%c%c)", + if (id[0] != 0) + asprintf( &ret, "unknown client (%c%c%c%c%c%c%c%c)", id[0], id[1], id[2], id[3], id[4], id[5], id[6], id[7] ); + else + asprintf( &ret, "unknown client" ); } return ret; diff --git a/libtransmission/transmission.c b/libtransmission/transmission.c index 5da274dbe..d714c6945 100644 --- a/libtransmission/transmission.c +++ b/libtransmission/transmission.c @@ -486,6 +486,8 @@ tr_stat_t * tr_torrentStat( tr_torrent_t * tor ) tr_peer_stat_t * tr_torrentPeers( tr_torrent_t * tor, int * peerCount ) { + tr_lockLock( &tor->lock ); + *peerCount = tor->peerCount; tr_peer_stat_t * peers = (tr_peer_stat_t *) calloc( tor->peerCount, sizeof( tr_peer_stat_t ) ); @@ -503,6 +505,8 @@ tr_peer_stat_t * tr_torrentPeers( tr_torrent_t * tor, int * peerCount ) } } + tr_lockUnlock( &tor->lock ); + return peers; } diff --git a/macosx/Torrent.m b/macosx/Torrent.m index 4aa2193c9..f37361a69 100644 --- a/macosx/Torrent.m +++ b/macosx/Torrent.m @@ -526,14 +526,9 @@ for (i = 0; i < totalPeers; i++) { peer = peers[i]; - - client = [NSString stringWithCString: (char *) peer.client encoding: NSUTF8StringEncoding]; - //get rid of strange returned client strings - if ([client hasPrefix: @"unknown client ("] && ![client hasSuffix: @")"]) - client = @"unknown client"; - + [peerDics addObject: [NSDictionary dictionaryWithObjectsAndKeys: - client, @"Client", + [NSString stringWithCString: (char *) peer.client encoding: NSUTF8StringEncoding], @"Client", [NSNumber numberWithBool: peer.isDownloading], @"UL To", [NSNumber numberWithBool: peer.isUploading], @"DL From", nil]]; }