Right now i'm writing an iPhone app that will interact with a network, and i plan to use a non-blocking berkley sockets so i can a full control about connect(), accept() and recv() timings. The one queston i'm not sure yet is how to correctly shut down lenghly connect() and recv() opertions (that can be minutes long). In UNIX, this is done by creating a pipe and using it, alongside with sockets, in select() request. Writing something in a pipe will immediately abort select() so i can check for shutdown etc. But is it possible to use pipes on iPhone and is it possible to use them with select()? Any insight or comment is welcomed.
Asked
Active
Viewed 328 times
1 Answers
2
Yes this is totally possible. The iPhone basically runs the same OS as OS X and has most if not all the standard facilities like sockets and pipes.
If you are familiar with those, then use them.
An alternative would be the CFNetwork API, specifically CFSocket
. These integrate a little better in an iOS app and also provide nice asynchronous socket operations. You can use CFTimer
next to your sockets to keep an eye on timeouts and then cancel socket operations that take too long.

Stefan Arentz
- 34,311
- 8
- 67
- 88
-
Thank you. And what is an iPhone API to create a pipe for that? – grigoryvp Sep 08 '10 at 14:09
-
You can give `CFSocket` a pair of file descriptors. But the point is that you don't need that pipe anymore. Since the 'runloop' will take care of all the scheduling. It basically does the whole select() for you. (internals might not acually use select though) – Stefan Arentz Sep 08 '10 at 14:32
-
1Also, Apple recommends against using BSD sockets because they may not integrate well with some of the underlying networking functions on the device. See my answer here for more: http://stackoverflow.com/questions/2488634/bsd-sockets-dont-behave-in-a-iphone-3g-environment/2488657#2488657 – Brad Larson Sep 08 '10 at 20:05