Victor Ng's Radio Weblog : armed with cocoa, an ibook and too much spare time
Updated: 4/4/03; 12:28:13 AM.

 

Click to see the XML version of this web page.

Click here to send an email to the editor of this weblog.


dotMac


Categories

Cocoa


Friends


Site Meter
 
 

Sunday, February 9, 2003

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    


© Copyright 2003 Victor Ng.



Click here to visit the Radio UserLand website.

 


February 2003
Sun Mon Tue Wed Thu Fri Sat
            1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28  
Jan   Apr


AIM: vng1@mac.com
MSN: v2ng@hotmail.com
ICQ: 30390174

NetNewsWire: More news, less junk. Faster