CFNetwork HTTP protocol timeout?

I am looking for a way to add a timeout to a CFHTTP request. It seems like there should be an object function CFHTTPMessageor CFReadStream, but I can't find it. Do I need to minimize my own timer in the start loop or something like that? (if so, any code for this?)

Thanks!

0
source share
2 answers

Update: ASIHTTPRequest has been deprecated and is no longer supported. Now I recommend using Apple's built-in NSURLConnection. NSURLConnection has a very small asynchronous API with most of the functionality contained in NSURLRequest. you can specify the timeout usingNSURLRequest requestWithURL:cachePolicy:timeoutInterval:

If you have no particular reason to use CFHTTPMessage, I would recommend using a higher level class like ASIHTTPRequest , which will add ease of use to you, including timeouts.

-1
source

Try this, readStream is your CFReadStreamRef:

#define _kCFStreamPropertyReadTimeout CFSTR("_kCFStreamPropertyReadTimeout")

double to = 15; // 15s timeout
CFNumberRef num = CFNumberCreate(kCFAllocatorDefault, kCFNumberDoubleType, &to);
CFReadStreamSetProperty(readStream, _kCFStreamPropertyReadTimeout, num);
CFRelease(num);

Constant for recording timeout - _kCFStreamPropertyWriteTimeout

+2
source

Source: https://habr.com/ru/post/1715449/


All Articles