1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2025-03-11 06:32:59 +00:00

put in a delay before checking port status

This commit is contained in:
Mitchell Livingston 2007-12-25 19:08:06 +00:00
parent e870440025
commit 2f44e0925d
6 changed files with 38 additions and 19 deletions

View file

@ -539,10 +539,13 @@ typedef enum
int maxPeers = [torrent maxPeerConnect];
while ((torrent = [enumerator nextObject]) && maxPeers != INVALID)
while ((torrent = [enumerator nextObject]))
{
if (/*maxPeers != INVALID &&*/ maxPeers != [torrent maxPeerConnect])
if (maxPeers != [torrent maxPeerConnect])
{
maxPeers = INVALID;
break;
}
}
//set peer view

View file

@ -57,7 +57,6 @@
[super dealloc];
}
#warning don't update when the window is closed
- (void) awakeFromNib
{
NSWindow * window = [self window];

View file

@ -34,11 +34,14 @@ typedef enum
@interface PortChecker : NSObject
{
id fDelegate;
port_status_t fStatus;
id fDelegate;
port_status_t fStatus;
int fPortNumber;
NSURLConnection * fConnection;
NSMutableData * fPortProbeData;
NSMutableData * fPortProbeData;
NSTimer * fTimer;
}
- (id) initForPort: (int) portNumber withDelegate: (id) delegate;

View file

@ -26,6 +26,7 @@
#import "NSApplicationAdditions.h"
#define CHECKER_URL @"http://transmission.m0k.org/PortCheck.php?port=%d"
#define CHECK_FIRE 3.0
@implementation PortChecker
@ -35,20 +36,11 @@
{
fDelegate = delegate;
NSURLRequest * portProbeRequest = [NSURLRequest requestWithURL: [NSURL URLWithString:
[NSString stringWithFormat: CHECKER_URL, portNumber]] cachePolicy:
[NSApp isOnLeopardOrBetter] ? NSURLRequestReloadIgnoringLocalCacheData : NSURLRequestReloadIgnoringCacheData
timeoutInterval: 15.0];
fPortNumber = portNumber;
fStatus = PORT_STATUS_CHECKING;
if ((fConnection = [[NSURLConnection alloc] initWithRequest: portProbeRequest delegate: self]))
fPortProbeData = [[NSMutableData alloc] init];
else
{
NSLog(@"Unable to get port status: failed to initiate connection");
[self callBackWithStatus: PORT_STATUS_ERROR];
}
fTimer = [NSTimer scheduledTimerWithTimeInterval: CHECK_FIRE target: self selector: @selector(startProbe)
userInfo: nil repeats: NO];
}
return self;
@ -56,6 +48,8 @@
- (void) dealloc
{
[fTimer invalidate];
[fConnection release];
[fPortProbeData release];
[super dealloc];
@ -66,8 +60,27 @@
return fStatus;
}
- (void) startProbe
{
fTimer = nil;
NSURLRequest * portProbeRequest = [NSURLRequest requestWithURL: [NSURL URLWithString:
[NSString stringWithFormat: CHECKER_URL, fPortNumber]] cachePolicy:
[NSApp isOnLeopardOrBetter] ? NSURLRequestReloadIgnoringLocalCacheData : NSURLRequestReloadIgnoringCacheData
timeoutInterval: 15.0];
if ((fConnection = [[NSURLConnection alloc] initWithRequest: portProbeRequest delegate: self]))
fPortProbeData = [[NSMutableData alloc] init];
else
{
NSLog(@"Unable to get port status: failed to initiate connection");
[self callBackWithStatus: PORT_STATUS_ERROR];
}
}
- (void) endProbe
{
[fTimer invalidate];
[fConnection cancel];
}

View file

@ -64,7 +64,7 @@ tr_handle * fLib;
{
[fTimer invalidate];
[fStatsWindowInstance release];
[fStatsWindowInstance release];
fStatsWindowInstance = nil;
}

View file

@ -700,6 +700,7 @@ void completenessChangeCallback(tr_torrent * torrent, cp_status_t status, void *
return fInfo->isPrivate;
}
#warning not working
- (NSString *) torrentLocation
{
return [NSString stringWithUTF8String: fInfo->torrent];