From 9bac10d4a3b9db0043e07765b26f6d5a7e5251a3 Mon Sep 17 00:00:00 2001 From: Mitchell Livingston Date: Tue, 18 Dec 2007 20:10:23 +0000 Subject: [PATCH] ensure that a single portchecker can be used for only a single check --- macosx/PortChecker.h | 4 ++-- macosx/PortChecker.m | 35 +++++++++++++++-------------------- macosx/PrefsController.m | 3 +-- 3 files changed, 18 insertions(+), 24 deletions(-) diff --git a/macosx/PortChecker.h b/macosx/PortChecker.h index 8a67b9611..2f9dd22df 100644 --- a/macosx/PortChecker.h +++ b/macosx/PortChecker.h @@ -26,6 +26,7 @@ typedef enum { + PORT_STATUS_CHECKING, PORT_STATUS_OPEN, PORT_STATUS_CLOSED, PORT_STATUS_ERROR @@ -40,8 +41,7 @@ typedef enum NSMutableData * fPortProbeData; } -- (id) initWithDelegate: (id) delegate; -- (void) probePort: (int) portNumber; +- (id) initForPort: (int) portNumber withDelegate: (id) delegate; - (void) endProbe; - (void) callBackWithStatus: (port_status_t) status; diff --git a/macosx/PortChecker.m b/macosx/PortChecker.m index 03ecd5362..767f92b89 100644 --- a/macosx/PortChecker.m +++ b/macosx/PortChecker.m @@ -27,11 +27,24 @@ @implementation PortChecker -- (id) initWithDelegate: (id) delegate +- (id) initForPort: (int) portNumber withDelegate: (id) delegate { if ((self = [super init])) { - fDelegate = delegate; + NSURLRequest * portProbeRequest = [NSURLRequest requestWithURL: [NSURL URLWithString: + [NSString stringWithFormat: @"http://transmission.m0k.org/PortCheck.php?port=%d", portNumber]] cachePolicy: + [NSApp isOnLeopardOrBetter] ? NSURLRequestReloadIgnoringLocalAndRemoteCacheData : NSURLRequestReloadIgnoringCacheData + timeoutInterval: 15.0]; + + fStatus = PORT_STATUS_CHECKING; + + if ((fConnection = [[NSURLConnection alloc] initWithRequest: portProbeRequest delegate: self])) + fPortProbeData = [[NSMutableData data] retain]; + else + { + NSLog(@"Unable to get port status: failed to initiate connection"); + [self callBackWithStatus: PORT_STATUS_ERROR]; + } } return self; @@ -49,23 +62,6 @@ return fStatus; } -- (void) probePort: (int) portNumber -{ - NSURLRequest * portProbeRequest = [NSURLRequest requestWithURL: [NSURL URLWithString: - [NSString stringWithFormat: @"http://transmission.m0k.org/PortCheck.php?port=%d", portNumber]] cachePolicy: - [NSApp isOnLeopardOrBetter] ? NSURLRequestReloadIgnoringLocalAndRemoteCacheData : NSURLRequestReloadIgnoringCacheData - timeoutInterval: 15.0]; - - - if ((fConnection = [[NSURLConnection alloc] initWithRequest: portProbeRequest delegate: self])) - fPortProbeData = [[NSMutableData data] retain]; - else - { - NSLog(@"Unable to get port status: failed to initiate connection"); - [self callBackWithStatus: PORT_STATUS_ERROR]; - } -} - - (void) endProbe { [fConnection cancel]; @@ -110,7 +106,6 @@ status = PORT_STATUS_ERROR; [self callBackWithStatus: status]; - [probeString release]; } diff --git a/macosx/PrefsController.m b/macosx/PrefsController.m index 27dc12a38..d022f706f 100644 --- a/macosx/PrefsController.m +++ b/macosx/PrefsController.m @@ -245,8 +245,7 @@ [fPortChecker endProbe]; [fPortChecker release]; } - fPortChecker = [[PortChecker alloc] initWithDelegate: self]; - [fPortChecker probePort: fPublicPort]; + fPortChecker = [[PortChecker alloc] initForPort: fPublicPort withDelegate: self]; } }