1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-25 09:13:06 +00:00

ensure that a single portchecker can be used for only a single check

This commit is contained in:
Mitchell Livingston 2007-12-18 20:10:23 +00:00
parent 8b6a64f8e8
commit 9bac10d4a3
3 changed files with 18 additions and 24 deletions

View file

@ -26,6 +26,7 @@
typedef enum typedef enum
{ {
PORT_STATUS_CHECKING,
PORT_STATUS_OPEN, PORT_STATUS_OPEN,
PORT_STATUS_CLOSED, PORT_STATUS_CLOSED,
PORT_STATUS_ERROR PORT_STATUS_ERROR
@ -40,8 +41,7 @@ typedef enum
NSMutableData * fPortProbeData; NSMutableData * fPortProbeData;
} }
- (id) initWithDelegate: (id) delegate; - (id) initForPort: (int) portNumber withDelegate: (id) delegate;
- (void) probePort: (int) portNumber;
- (void) endProbe; - (void) endProbe;
- (void) callBackWithStatus: (port_status_t) status; - (void) callBackWithStatus: (port_status_t) status;

View file

@ -27,11 +27,24 @@
@implementation PortChecker @implementation PortChecker
- (id) initWithDelegate: (id) delegate - (id) initForPort: (int) portNumber withDelegate: (id) delegate
{ {
if ((self = [super init])) 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; return self;
@ -49,23 +62,6 @@
return fStatus; 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 - (void) endProbe
{ {
[fConnection cancel]; [fConnection cancel];
@ -110,7 +106,6 @@
status = PORT_STATUS_ERROR; status = PORT_STATUS_ERROR;
[self callBackWithStatus: status]; [self callBackWithStatus: status];
[probeString release]; [probeString release];
} }

View file

@ -245,8 +245,7 @@
[fPortChecker endProbe]; [fPortChecker endProbe];
[fPortChecker release]; [fPortChecker release];
} }
fPortChecker = [[PortChecker alloc] initWithDelegate: self]; fPortChecker = [[PortChecker alloc] initForPort: fPublicPort withDelegate: self];
[fPortChecker probePort: fPublicPort];
} }
} }