mirror of
https://github.com/transmission/transmission.git
synced 2025-12-25 04:45:56 +00:00
ensure that a single portchecker can be used for only a single check
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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];
|
||||
}
|
||||
|
||||
|
||||
@@ -245,8 +245,7 @@
|
||||
[fPortChecker endProbe];
|
||||
[fPortChecker release];
|
||||
}
|
||||
fPortChecker = [[PortChecker alloc] initWithDelegate: self];
|
||||
[fPortChecker probePort: fPublicPort];
|
||||
fPortChecker = [[PortChecker alloc] initForPort: fPublicPort withDelegate: self];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user