1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2025-01-31 11:23:40 +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:
Mitchell Livingston 2008-09-06 21:57:13 +00:00
parent ede407ee0e
commit 27ecc3517d
2 changed files with 35 additions and 24 deletions

View file

@ -28,6 +28,12 @@
#define CHECKER_URL @"http://portcheck.transmissionbt.com/%d" #define CHECKER_URL @"http://portcheck.transmissionbt.com/%d"
#define CHECK_FIRE 3.0 #define CHECK_FIRE 3.0
@interface PortChecker (Private)
- (void) startProbe;
@end
@implementation PortChecker @implementation PortChecker
- (id) initForPort: (int) portNumber delay: (BOOL) delay withDelegate: (id) delegate - (id) initForPort: (int) portNumber delay: (BOOL) delay withDelegate: (id) delegate
@ -39,8 +45,11 @@
fPortNumber = portNumber; fPortNumber = portNumber;
fStatus = PORT_STATUS_CHECKING; fStatus = PORT_STATUS_CHECKING;
fTimer = [NSTimer scheduledTimerWithTimeInterval: (delay ? CHECK_FIRE : 0.1) target: self if (delay)
fTimer = [NSTimer scheduledTimerWithTimeInterval: CHECK_FIRE target: self
selector: @selector(startProbe) userInfo: nil repeats: NO]; selector: @selector(startProbe) userInfo: nil repeats: NO];
else
[self startProbe];
} }
return self; return self;
@ -60,24 +69,6 @@
return fStatus; 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 - (void) cancelProbe
{ {
[fTimer invalidate]; [fTimer invalidate];
@ -94,8 +85,6 @@
[fDelegate performSelectorOnMainThread: @selector(portCheckerDidFinishProbing:) withObject: self waitUntilDone: NO]; [fDelegate performSelectorOnMainThread: @selector(portCheckerDidFinishProbing:) withObject: self waitUntilDone: NO];
} }
#pragma mark NSURLConnection delegate methods
- (void) connection: (NSURLConnection *) connection didReceiveResponse: (NSURLResponse *) response - (void) connection: (NSURLConnection *) connection didReceiveResponse: (NSURLResponse *) response
{ {
[fPortProbeData setLength: 0]; [fPortProbeData setLength: 0];
@ -139,3 +128,26 @@
} }
@end @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

View file

@ -365,8 +365,7 @@ tr_handle * fHandle;
[fPortChecker cancelProbe]; [fPortChecker cancelProbe];
[fPortChecker release]; [fPortChecker release];
} }
fPortChecker = [[PortChecker alloc] initForPort: fPeerPort fPortChecker = [[PortChecker alloc] initForPort: fPeerPort delay: tr_sessionIsPortForwardingEnabled(fHandle) withDelegate: self];
delay: tr_sessionIsPortForwardingEnabled(fHandle) withDelegate: self];
} }
} }