CFNetwork to access member variables of my objective-c classes?
CFNetwork to access member variables of my objective-c classes?
- Subject: CFNetwork to access member variables of my objective-c classes?
- From: Victor Ng <email@hidden>
- Date: Fri, 7 Feb 2003 22:04:24 -0500
Hi, I'm having problems using the CFStreams framework in a Cocoa
application I'm trying to build.
My goal here is to have CFStreams invoke callbacks when data comes down
the socket and I want to buffer that data inside of a NSMutableData
object. This NSMutableData instance is a member of my class - I want
to pass it into the CFStreamClientContext as the info pointer.
I've tried basing my code off of the CFNetworkHTTPDownload example from
the Apple sample source, but that code seems to just append the
incoming data onto a Carbon widget.
When I run this code, the read calllbacks work properly, and I can read
the data from the stream just fine, but when I look at the info object
in the ReadStreamClientCallback, I only get null back.
So - my question is how do I get CFNetwork to access member variables
of my objective-c classes?
What am I not understanding here?
void ReadStreamClientCallBack( CFReadStreamRef stream,
CFStreamEventType type, void *clientCallBackInfo )
{
NSLog(@"info object: %@",
((CFStreamClientContext*)clientCallBackInfo)->info);
// bunch of code snipped out
}
-(void)downloadURL:(id)sender
{
CFHTTPMessageRef messageRef = NULL;
CFStringRef requestMethod = (CFStringRef) @"GET";
CFURLRef url = (CFURLRef) [NSURL URLWithString:
@"
http://www.apple.com"];
// this is where is stuff the NSMutableData member variable into
the clientcontext
CFStreamClientContext ctxt = { 0, (void*)readBuffer, NULL, NULL,
NULL };
// stuff some data into the readBuffer
[(NSMutableData *)(ctxt.info) append
Data:[NSArchiver
archivedDataWithRootObject:@"test data"]];
messageRef = CFHTTPMessageCreateRequest(kCFAllocatorDefault,
requestMethod, url, kCFHTTPVersion1_1);
// Create the stream for the request.
readStreamRef = CFReadStreamCreateForHTTPRequest(
kCFAllocatorDefault, messageRef );
if (readStreamRef == NULL) {
NSLog(@"error while getting read stream");
}
CFHTTPReadStreamSetRedirectsAutomatically( readStreamRef, true );
// Set the client notifier
if ( CFReadStreamSetClient( readStreamRef, kNetworkEvents,
ReadStreamClientCallBack, &ctxt ) == false ) {
goto Bail;
} else {
NSLog(@"client is set");
}
// Schedule the stream
CFReadStreamScheduleWithRunLoop( readStreamRef,
CFRunLoopGetCurrent(), kCFRunLoopCommonModes );
// Start the HTTP connection
if ( CFReadStreamOpen( readStreamRef ) == false ) {
NSLog(@"readStream can't be opened");
goto Bail;
} else {
NSLog(@"readStream is open");
}
// setup a timeout timer if nothing comes back in 5 seconds
timeoutTimer = [[NSTimer scheduledTimerWithTimeInterval:5
target:self
selector:@selector(timeout:)
userInfo:nil
repeats:NO] retain];
Bail:
// todo: add some release code here later
}
_______________________________________________
macnetworkprog mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/macnetworkprog
Do not post admin requests to the list. They will be ignored.