1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2025-03-12 07:03:44 +00:00

put in a delay before checking port status

This commit is contained in:
Mitchell Livingston 2007-12-25 19:08:06 +00:00
parent e870440025
commit 2f44e0925d
6 changed files with 38 additions and 19 deletions

View file

@ -539,10 +539,13 @@ typedef enum
int maxPeers = [torrent maxPeerConnect]; int maxPeers = [torrent maxPeerConnect];
while ((torrent = [enumerator nextObject]) && maxPeers != INVALID) while ((torrent = [enumerator nextObject]))
{
if (maxPeers != [torrent maxPeerConnect])
{ {
if (/*maxPeers != INVALID &&*/ maxPeers != [torrent maxPeerConnect])
maxPeers = INVALID; maxPeers = INVALID;
break;
}
} }
//set peer view //set peer view

View file

@ -57,7 +57,6 @@
[super dealloc]; [super dealloc];
} }
#warning don't update when the window is closed
- (void) awakeFromNib - (void) awakeFromNib
{ {
NSWindow * window = [self window]; NSWindow * window = [self window];

View file

@ -36,9 +36,12 @@ typedef enum
{ {
id fDelegate; id fDelegate;
port_status_t fStatus; port_status_t fStatus;
int fPortNumber;
NSURLConnection * fConnection; NSURLConnection * fConnection;
NSMutableData * fPortProbeData; NSMutableData * fPortProbeData;
NSTimer * fTimer;
} }
- (id) initForPort: (int) portNumber withDelegate: (id) delegate; - (id) initForPort: (int) portNumber withDelegate: (id) delegate;

View file

@ -26,6 +26,7 @@
#import "NSApplicationAdditions.h" #import "NSApplicationAdditions.h"
#define CHECKER_URL @"http://transmission.m0k.org/PortCheck.php?port=%d" #define CHECKER_URL @"http://transmission.m0k.org/PortCheck.php?port=%d"
#define CHECK_FIRE 3.0
@implementation PortChecker @implementation PortChecker
@ -35,20 +36,11 @@
{ {
fDelegate = delegate; fDelegate = delegate;
NSURLRequest * portProbeRequest = [NSURLRequest requestWithURL: [NSURL URLWithString: fPortNumber = portNumber;
[NSString stringWithFormat: CHECKER_URL, portNumber]] cachePolicy:
[NSApp isOnLeopardOrBetter] ? NSURLRequestReloadIgnoringLocalCacheData : NSURLRequestReloadIgnoringCacheData
timeoutInterval: 15.0];
fStatus = PORT_STATUS_CHECKING; fStatus = PORT_STATUS_CHECKING;
if ((fConnection = [[NSURLConnection alloc] initWithRequest: portProbeRequest delegate: self])) fTimer = [NSTimer scheduledTimerWithTimeInterval: CHECK_FIRE target: self selector: @selector(startProbe)
fPortProbeData = [[NSMutableData alloc] init]; userInfo: nil repeats: NO];
else
{
NSLog(@"Unable to get port status: failed to initiate connection");
[self callBackWithStatus: PORT_STATUS_ERROR];
}
} }
return self; return self;
@ -56,6 +48,8 @@
- (void) dealloc - (void) dealloc
{ {
[fTimer invalidate];
[fConnection release]; [fConnection release];
[fPortProbeData release]; [fPortProbeData release];
[super dealloc]; [super dealloc];
@ -66,8 +60,27 @@
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) endProbe - (void) endProbe
{ {
[fTimer invalidate];
[fConnection cancel]; [fConnection cancel];
} }

View file

@ -700,6 +700,7 @@ void completenessChangeCallback(tr_torrent * torrent, cp_status_t status, void *
return fInfo->isPrivate; return fInfo->isPrivate;
} }
#warning not working
- (NSString *) torrentLocation - (NSString *) torrentLocation
{ {
return [NSString stringWithUTF8String: fInfo->torrent]; return [NSString stringWithUTF8String: fInfo->torrent];