Changeset 4205


Ignore:
Timestamp:
Dec 18, 2007, 8:10:23 PM (15 years ago)
Author:
livings124
Message:

ensure that a single portchecker can be used for only a single check

Location:
trunk/macosx
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/macosx/PortChecker.h

    r4203 r4205  
    2727typedef enum
    2828{
     29    PORT_STATUS_CHECKING,
    2930    PORT_STATUS_OPEN,
    3031    PORT_STATUS_CLOSED,
     
    4142}
    4243
    43 - (id) initWithDelegate: (id) delegate;
    44 - (void) probePort: (int) portNumber;
     44- (id) initForPort: (int) portNumber withDelegate: (id) delegate;
    4545- (void) endProbe;
    4646
  • trunk/macosx/PortChecker.m

    r4204 r4205  
    2828@implementation PortChecker
    2929
    30 - (id) initWithDelegate: (id) delegate
     30- (id) initForPort: (int) portNumber withDelegate: (id) delegate
    3131{
    3232    if ((self = [super init]))
    3333    {
    34         fDelegate = delegate;
     34        NSURLRequest * portProbeRequest = [NSURLRequest requestWithURL: [NSURL URLWithString:
     35                [NSString stringWithFormat: @"http://transmission.m0k.org/PortCheck.php?port=%d", portNumber]] cachePolicy:
     36                [NSApp isOnLeopardOrBetter] ? NSURLRequestReloadIgnoringLocalAndRemoteCacheData : NSURLRequestReloadIgnoringCacheData
     37                timeoutInterval: 15.0];
     38       
     39        fStatus = PORT_STATUS_CHECKING;
     40       
     41        if ((fConnection = [[NSURLConnection alloc] initWithRequest: portProbeRequest delegate: self]))
     42            fPortProbeData = [[NSMutableData data] retain];
     43        else
     44        {
     45            NSLog(@"Unable to get port status: failed to initiate connection");
     46            [self callBackWithStatus: PORT_STATUS_ERROR];
     47        }
    3548    }
    3649   
     
    4861{
    4962    return fStatus;
    50 }
    51 
    52 - (void) probePort: (int) portNumber
    53 {
    54     NSURLRequest * portProbeRequest = [NSURLRequest requestWithURL: [NSURL URLWithString:
    55                 [NSString stringWithFormat: @"http://transmission.m0k.org/PortCheck.php?port=%d", portNumber]] cachePolicy:
    56                 [NSApp isOnLeopardOrBetter] ? NSURLRequestReloadIgnoringLocalAndRemoteCacheData : NSURLRequestReloadIgnoringCacheData
    57                 timeoutInterval: 15.0];
    58    
    59    
    60     if ((fConnection = [[NSURLConnection alloc] initWithRequest: portProbeRequest delegate: self]))
    61         fPortProbeData = [[NSMutableData data] retain];
    62     else
    63     {
    64         NSLog(@"Unable to get port status: failed to initiate connection");
    65         [self callBackWithStatus: PORT_STATUS_ERROR];
    66     }
    6763}
    6864
     
    111107   
    112108    [self callBackWithStatus: status];
    113    
    114109    [probeString release];
    115110}
  • trunk/macosx/PrefsController.m

    r4203 r4205  
    246246            [fPortChecker release];
    247247        }
    248         fPortChecker = [[PortChecker alloc] initWithDelegate: self];
    249         [fPortChecker probePort: fPublicPort];
     248        fPortChecker = [[PortChecker alloc] initForPort: fPublicPort withDelegate: self];
    250249    }
    251250}
Note: See TracChangeset for help on using the changeset viewer.