From 27ecc3517dc003f250e7392dfca9774b1b196d4b Mon Sep 17 00:00:00 2001 From: Mitchell Livingston Date: Sat, 6 Sep 2008 21:57:13 +0000 Subject: [PATCH] if delay is off, perform the port check probe without any timer; on 10.5, set the port checker to ignore remote cache data on top of local cache data --- macosx/PortChecker.m | 56 ++++++++++++++++++++++++---------------- macosx/PrefsController.m | 3 +-- 2 files changed, 35 insertions(+), 24 deletions(-) diff --git a/macosx/PortChecker.m b/macosx/PortChecker.m index bd5af77a0..b26a0a72c 100644 --- a/macosx/PortChecker.m +++ b/macosx/PortChecker.m @@ -28,6 +28,12 @@ #define CHECKER_URL @"http://portcheck.transmissionbt.com/%d" #define CHECK_FIRE 3.0 +@interface PortChecker (Private) + +- (void) startProbe; + +@end + @implementation PortChecker - (id) initForPort: (int) portNumber delay: (BOOL) delay withDelegate: (id) delegate @@ -39,8 +45,11 @@ fPortNumber = portNumber; fStatus = PORT_STATUS_CHECKING; - fTimer = [NSTimer scheduledTimerWithTimeInterval: (delay ? CHECK_FIRE : 0.1) target: self - selector: @selector(startProbe) userInfo: nil repeats: NO]; + if (delay) + fTimer = [NSTimer scheduledTimerWithTimeInterval: CHECK_FIRE target: self + selector: @selector(startProbe) userInfo: nil repeats: NO]; + else + [self startProbe]; } return self; @@ -60,24 +69,6 @@ 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) cancelProbe { [fTimer invalidate]; @@ -94,8 +85,6 @@ [fDelegate performSelectorOnMainThread: @selector(portCheckerDidFinishProbing:) withObject: self waitUntilDone: NO]; } -#pragma mark NSURLConnection delegate methods - - (void) connection: (NSURLConnection *) connection didReceiveResponse: (NSURLResponse *) response { [fPortProbeData setLength: 0]; @@ -139,3 +128,26 @@ } @end + +@implementation PortChecker (Private) + +- (void) startProbe +{ + fTimer = nil; + + NSURLRequest * portProbeRequest = [NSURLRequest requestWithURL: [NSURL URLWithString: + [NSString stringWithFormat: CHECKER_URL, fPortNumber]] cachePolicy: + [NSApp isOnLeopardOrBetter] ? NSURLRequestReloadIgnoringLocalAndRemoteCacheData : 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]; + } +} + +@end + diff --git a/macosx/PrefsController.m b/macosx/PrefsController.m index e7dd23d47..52a697458 100644 --- a/macosx/PrefsController.m +++ b/macosx/PrefsController.m @@ -365,8 +365,7 @@ tr_handle * fHandle; [fPortChecker cancelProbe]; [fPortChecker release]; } - fPortChecker = [[PortChecker alloc] initForPort: fPeerPort - delay: tr_sessionIsPortForwardingEnabled(fHandle) withDelegate: self]; + fPortChecker = [[PortChecker alloc] initForPort: fPeerPort delay: tr_sessionIsPortForwardingEnabled(fHandle) withDelegate: self]; } }