Re: Getting a HTTP response with read streams
Re: Getting a HTTP response with read streams
- Subject: Re: Getting a HTTP response with read streams
- From: Frederick Cheung <email@hidden>
- Date: Tue, 19 Dec 2006 15:29:43 +0000
On 19 Dec 2006, at 14:00, Maarten Kools wrote:
Hi,
I'm retrieving an XML file from a HTTP server using a
CFReadStreamRef. However, I'm having some troubles determining
whether there's a valid connection or not.
Call CFReadStreamGetStatus to determine whether the stream has
encountered an error condition (and then CFReadStreamGetError to find
out what the error is).
Alternatively schedule the stream with a runloop and say that you
want your callback called when errors occur (CFReadStreamSetClient);
this is also nicer in terms of not sitting in a tight loop.
Fred
I've got the following bit of code (all in a separate thread):
ReadStream = CFReadStreamCreateForHTTPRequest( kCFAllocatorDefault,
Request);
if( !ReadStream) ThrowRuntimeError
( "CFReadStreamCreateForHTTPRequest failed");
if( !CFReadStreamOpen( ReadStream)) ThrowRuntimeError
( "CFReadStreamOpen failed");
UInt32 StatusCode = 0;
CFHTTPMessageRef ResponseHeader = NULL;
while( !ResponseHeader)
{
ResponseHeader = (CFHTTPMessageRef)CFReadStreamCopyProperty
( ReadStream, kCFStreamPropertyHTTPResponseHeader);
if( !ResponseHeader) continue;
StatusCode = CFHTTPMessageGetResponseStatusCode( ResponseHeader);
}
if( ResponseHeader) CFRelease( ResponseHeader);
Works perfectly when there's a valid network connection. However,
once you unplug the network the problem arises. Instead of failing
to open the read stream (like I expected) it just opens without any
error, but it obviously never gets the response headers so it just
hangs there.
Is there any way to either detect a network connection, or to
determine that the request failed?
Thanks,
Maarten Kools
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Macnetworkprog mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
email@hidden
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Macnetworkprog mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden