views:

969

answers:

1

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!

A: 

Unless you have a special reason for using CFHTTPMessage I'd recommend using a higher level class such as ASIHTTPRequest which gives you added ease of use including timeouts.

Roger Nolan
Roger, I did look @ ASIHTTPRequest and it looks great, except there's one thing I need it to do that it doesn't -- which is stream data from a CFReadStream object. (I could add a patch I s'pose...)
sehugg
You should drop Ben at All seeing eye a line. He answers his mail and is a nice guy. If you have a patch, I'm sure he'd take it.
Roger Nolan
ASIHTTPRequest does use an NSInputStream for the request body when posting files from an ASIFormDataRequest, and also whenever shouldStreamPostDataFromDisk is true.If your CFReadStream is reading from a file on disk, just use setPostBodyFilePath: and it'll do the rest. If not, it shouldn't be too tough to patch it to use your CFReadStream instead, but drop me a msg (my email is on the website) if you need a hand.
pokeb
Thanks for the offer -- I ended up using NSURLConnection for everything except the POST, which I augmented with a NSTimer. Kind of a cop-out but I already had the code and some unit tests :P Next time I will start with ASIHTTPRequest in the first place!
sehugg
Just FYI, I finally got around to extending ASIHTTPRequest and it was quite simply to make it take a stream instead of file or buffer. I used `socketpair()` to make a write stream that could be written from a different thread. Let me know if you are interested in code. Thanks :)
sehugg