CFNetwork HTTP timeout?

做~自己de王妃 提交于 2019-12-11 17:43:47

问题


I am looking for a way to add a timeout to a CFHTTP request. It seems like there should be a feature of the CFHTTPMessage or the CFReadStream object, but I can't find it. Do I have to roll my own timer on the run loop or something? (if so, any code for this?)

Thanks!


回答1:


My answer is outdated but I can't delete the accepted answer.




回答2:


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 write timeout is _kCFStreamPropertyWriteTimeout



来源:https://stackoverflow.com/questions/962076/cfnetwork-http-timeout

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!