Re: NSURLConnection timeoutInterval only works in multiples of 30 seconds
Re: NSURLConnection timeoutInterval only works in multiples of 30 seconds
- Subject: Re: NSURLConnection timeoutInterval only works in multiples of 30 seconds
- From: Jerry Krinock <email@hidden>
- Date: Tue, 8 Jul 2008 21:23:21 -0700
I know that you folks have taken a different turn with this
discussion, but I need to post my test results to finish what we
started a couple days ago, for other readers.
RESULTS
In Tiger, it behaves as I recall and exactly as Kanny described: The
timeout gets rounded up 30 or 60 seconds. Bug.
In Leopard, the timeout works correctly, even down to 1 second. Bug
has been fixed.
Jerry
/*********** NSURLRequestTimeoutter.m ************/
#define SLOWPOKE @"http://sheepsystems.com/engineering/Slowpoke.pl"
#import <Foundation/Foundation.h>
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
float timeout ;
float delay ;
printf("Enter timeout for NSURLRequest (seconds):\n") ;
scanf("%f", &timeout) ;
printf("Enter server delay (seconds):\n") ;
scanf("%f", &delay) ;
if (timeout > delay) {
printf("timeout > delay. SHOULD NOT TIME OUT (unless it's
close, with actual delay)\n") ;
}
else {
printf("timeout <= delay. SHOULD TIME OUT\n") ;
}
NSString* urlString = [SLOWPOKE stringByAppendingFormat:@"?Delay=
%f", delay] ;
NSURL* url = [NSURL URLWithString:urlString] ;
NSURLRequest* request=[NSURLRequest requestWithURL:url
cachePolicy:NSURLRequestReloadIgnoringCacheData
timeoutInterval:timeout];
NSMutableURLRequest *mutableRequest = [request mutableCopy] ;
[mutableRequest setHTTPMethod:@"GET"] ;
// [mutableRequest setTimeoutInterval:timeout] ; // This does not
work either.
[mutableRequest
setCachePolicy:NSURLRequestReloadIgnoringCacheData] ;
NSLog(@"Sending request to %@", urlString) ;
NSURLResponse* response ;
NSError* error = nil ;
NSData* rxData = [NSURLConnection sendSynchronousRequest:
[mutableRequest autorelease]
returningResponse:&response
error:&error] ;
NSString* rxString = [[NSString alloc] initWithData:rxData
encoding:NSUTF8StringEncoding] ;
NSLog(@"Received status code: %d %@", [response statusCode],
[NSHTTPURLResponse localizedStringForStatusCode:[response
statusCode]]) ;
NSLog(@"Received data: %@", rxString) ;
NSLog(@"Error: %@", error) ;
[rxString release] ;
[pool drain];
return 0;
}
/*********** Slowpoke.pl ************/
#!/usr/bin/perl
use strict ;
use warnings ;
use CGI ;
my $cgi = new CGI;
my %queryPairs = $cgi->Vars ;
my $nParms = keys(%queryPairs) ;
my $delay = $queryPairs{'Delay'} ;
my $returnData = "Response was delayed for $delay seconds." ;
sleep($delay) ;
my $returnStatus = 200 ;
print $cgi->header(-status=>$returnStatus,-charset=>'utf-8') ;
print $returnData ;
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden