I've recently posted a question about reducing the timeout of an FTP connection (click here to see it if you want).
Now, I've been asked to post a more specific question, focusing on the component we're using for the FTP download.
We're using Nico Kreipke's FTPManager (click here to go to its GitHub).
What we're trying to implement is to download data from an FTP address, and if it fails we'll fallback to use an HTTPS web server.
When the FTP address we give isn't available, it takes about one minute to timeout.
The question is, how can I reduce that timeout?
Best regards,
Tiago
Some More Info
I forgot to say, the FTP connection is done with an IP (local network).
Johan's Tip
I added a property to FTPManager, a double
named timeout
.
Then I've overridden the accessor of serverReadStream
, a property used throughout FTPManager to hold the read stream, so that it would configure the timeout interval for all requests.
- (NSInputStream *)serverReadStream
{
return _serverReadStream;
}
- (void)setServerReadStream:(NSInputStream *)serverReadStream
{
if ((_serverReadStream = serverReadStream)) {
CFNumberRef number = CFNumberCreate(kCFAllocatorDefault, kCFNumberDoubleType, &_timeout);
CFReadStreamSetProperty((__bridge CFReadStreamRef)(_serverReadStream), _kCFStreamPropertyReadTimeout, number);
CFRelease(number);
}
}
_kCFStreamPropertyReadTimeout
is defined by:
#define _kCFStreamPropertyReadTimeout CFSTR("_kCFStreamPropertyReadTimeout")
However, it still takes about one minute to timeout. I set the timeout before connecting to the FTP address, right after creating ftpManager
. The code I use to set the timeout follows:
FTPManager *ftpManager = [[FTPManager alloc] init];
[ftpManager setTimeout:10];