mirror of
https://github.com/transmission/transmission
synced 2024-12-26 01:27:28 +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
|
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;
|
||||||
|
|
|
@ -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];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue