mirror of
https://github.com/transmission/transmission
synced 2025-01-31 03:12:44 +00:00
if delay is off, perform the port check probe without any timer; on 10.5, set the port checker to ignore remote cache data on top of local cache data
This commit is contained in:
parent
ede407ee0e
commit
27ecc3517d
2 changed files with 35 additions and 24 deletions
|
@ -28,6 +28,12 @@
|
|||
#define CHECKER_URL @"http://portcheck.transmissionbt.com/%d"
|
||||
#define CHECK_FIRE 3.0
|
||||
|
||||
@interface PortChecker (Private)
|
||||
|
||||
- (void) startProbe;
|
||||
|
||||
@end
|
||||
|
||||
@implementation PortChecker
|
||||
|
||||
- (id) initForPort: (int) portNumber delay: (BOOL) delay withDelegate: (id) delegate
|
||||
|
@ -39,8 +45,11 @@
|
|||
fPortNumber = portNumber;
|
||||
fStatus = PORT_STATUS_CHECKING;
|
||||
|
||||
fTimer = [NSTimer scheduledTimerWithTimeInterval: (delay ? CHECK_FIRE : 0.1) target: self
|
||||
selector: @selector(startProbe) userInfo: nil repeats: NO];
|
||||
if (delay)
|
||||
fTimer = [NSTimer scheduledTimerWithTimeInterval: CHECK_FIRE target: self
|
||||
selector: @selector(startProbe) userInfo: nil repeats: NO];
|
||||
else
|
||||
[self startProbe];
|
||||
}
|
||||
|
||||
return self;
|
||||
|
@ -60,24 +69,6 @@
|
|||
return fStatus;
|
||||
}
|
||||
|
||||
- (void) startProbe
|
||||
{
|
||||
fTimer = nil;
|
||||
|
||||
NSURLRequest * portProbeRequest = [NSURLRequest requestWithURL: [NSURL URLWithString:
|
||||
[NSString stringWithFormat: CHECKER_URL, fPortNumber]] cachePolicy:
|
||||
[NSApp isOnLeopardOrBetter] ? NSURLRequestReloadIgnoringLocalCacheData : NSURLRequestReloadIgnoringCacheData
|
||||
timeoutInterval: 15.0];
|
||||
|
||||
if ((fConnection = [[NSURLConnection alloc] initWithRequest: portProbeRequest delegate: self]))
|
||||
fPortProbeData = [[NSMutableData alloc] init];
|
||||
else
|
||||
{
|
||||
NSLog(@"Unable to get port status: failed to initiate connection");
|
||||
[self callBackWithStatus: PORT_STATUS_ERROR];
|
||||
}
|
||||
}
|
||||
|
||||
- (void) cancelProbe
|
||||
{
|
||||
[fTimer invalidate];
|
||||
|
@ -94,8 +85,6 @@
|
|||
[fDelegate performSelectorOnMainThread: @selector(portCheckerDidFinishProbing:) withObject: self waitUntilDone: NO];
|
||||
}
|
||||
|
||||
#pragma mark NSURLConnection delegate methods
|
||||
|
||||
- (void) connection: (NSURLConnection *) connection didReceiveResponse: (NSURLResponse *) response
|
||||
{
|
||||
[fPortProbeData setLength: 0];
|
||||
|
@ -139,3 +128,26 @@
|
|||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation PortChecker (Private)
|
||||
|
||||
- (void) startProbe
|
||||
{
|
||||
fTimer = nil;
|
||||
|
||||
NSURLRequest * portProbeRequest = [NSURLRequest requestWithURL: [NSURL URLWithString:
|
||||
[NSString stringWithFormat: CHECKER_URL, fPortNumber]] cachePolicy:
|
||||
[NSApp isOnLeopardOrBetter] ? NSURLRequestReloadIgnoringLocalAndRemoteCacheData : NSURLRequestReloadIgnoringCacheData
|
||||
timeoutInterval: 15.0];
|
||||
|
||||
if ((fConnection = [[NSURLConnection alloc] initWithRequest: portProbeRequest delegate: self]))
|
||||
fPortProbeData = [[NSMutableData alloc] init];
|
||||
else
|
||||
{
|
||||
NSLog(@"Unable to get port status: failed to initiate connection");
|
||||
[self callBackWithStatus: PORT_STATUS_ERROR];
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
|
|
@ -365,8 +365,7 @@ tr_handle * fHandle;
|
|||
[fPortChecker cancelProbe];
|
||||
[fPortChecker release];
|
||||
}
|
||||
fPortChecker = [[PortChecker alloc] initForPort: fPeerPort
|
||||
delay: tr_sessionIsPortForwardingEnabled(fHandle) withDelegate: self];
|
||||
fPortChecker = [[PortChecker alloc] initForPort: fPeerPort delay: tr_sessionIsPortForwardingEnabled(fHandle) withDelegate: self];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue