Has it really been 8 days since I posted last time?
I've been trying to decipher how to use the CFNetwork framework and wrap it in a nice library so that I can do nice and friendly conditional HTTP/1.1 fetches from web servers.
The short version of this story is that Java has made me into a moron as far as programming is concerned. Well, that and Apple needs to fix some of their documentation.
To get CFNetwork to handle event driven reads from a CFStream, you create a class that opens all of the necessary CFStreams, then you set a context which contains an 'info' pointer (of type void*) which points back at your object.
The documentation that Apple provides is a little misleading - it seems to indicate that your entire context datastructure is passed back in the callback:
- clientCallBackInfo
- A pointer to context information that was provided when the application previously called CFReadStreamSetClient.
That is wrong.
What you really wanted to look at is this:
- clientCallBackInfo
- The info member of the CFStreamClientContext structure that was used when setting the client for stream.
I got screwed for a day because I kept casting the void* pointer to CFStreamClientContext. Grabbing 'info' from that pointer happened to give me the first attribute of my Objective-C object.
Points for Java on this one - I'd get a ClassCastException, whereas here all I got was some weird data that I couldn't figure out.
Blech...
Kudos to Matt Jarjoura for setting up a CFNetwork wiki with some simple example code for using CFNetwork in Cocoa.
4:10:52 AM
|