mirror of
https://github.com/transmission/transmission
synced 2024-12-25 01:03:01 +00:00
ensure that a single portchecker can be used for only a single check
This commit is contained in:
parent
8b6a64f8e8
commit
9bac10d4a3
3 changed files with 18 additions and 24 deletions
|
@ -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];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue