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: Maarten Kools <email@hidden>
- Date: Thu, 21 Dec 2006 11:09:28 +0100
- Organization: Van Gennep - Media Automation Consulting bv
I've tried testing for an error with CFReadStreamGetError, except it
tells me it's all good, so I can't use that (how it can tell me it's all
good when it's a HTTP read stream without network is beyond me).
I'll try with the run loop, or otherwise just start reading data.
Thanks,
Maarten
Frederick Cheung wrote:
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:
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