• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: CFReadStreamCreateForHTTPRequest
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: CFReadStreamCreateForHTTPRequest


  • Subject: Re: CFReadStreamCreateForHTTPRequest
  • From: "Duane Murphy" <email@hidden>
  • Date: Thu, 30 Mar 2006 09:00:15 -0800

--- At Thu, 30 Mar 2006 11:23:18 -0500, Chris Branch wrote:

>I'm trying to create a simple C++ class that is able to send an HTTP
>request and retrieve the response on OS X (10.2 and later).  For
>example, suppose the interface for my class looks like this:
>
>class cInternetRequest {
>public:
>	cInternetRequest();
>	virtual ~cInternetRequest();
>
>	bool Open(const char *url);
>	bool Read(char *buffer, int bytesToRead, int *bytesRead) const;
>	void Close();
>
>	bool GetHttpStatusCode(int *statusCode) const;
>
>	... more stuff omitted ...
>};
>
>Sample usage of this class might look like:
>
>	if (request.Open("www.somedomain.com/example.php")) {
>		if (request.GetHttpStatusCode(&httpStatus) && httpStatus == 200) {
>			do {
>				success = request.Read(buffer, sizeof(buffer), &numBytes);
>				// ...process response...
>			} while (success && numBytes > 0);
>		}
>
>		request.Close();
>	}
>
>
>It looks like the implementation of this should be pretty
>straightforward using CFHTTPMessageCreateRequest() and
>CFReadStreamCreateForHTTPRequest(), but there are a few aspects that
>Apple's documentation does not seem to cover.
>
>In my Open() method, I would call CFHTTPMessageCreateRequest() to create
>the request, then call CFReadStreamCreateForHTTPRequest() and
>CFStreamOpen() to actually send the request.  Questions:
>
>1) Does CFReadStreamCreateForHTTPRequest() take a "snapshot" of the
>CFHTTPMessageRef parameter?  In other words, is it safe to CFRelease the
>CFHTTPMessageRef immediately after calling
>CFReadStreamCreateForHTTPRequest, or does the CFHTTPMessageRef have to
>persist until the stream is closed/released?
>
>2) Does CFReadStreamOpen() block until HTTP response headers are
>available?  If no, how do I know when it's "safe" to call
>CFReadStreamCopyProperty() to get the response headers?  If
>CFReadStreamOpen() DOES block, what happens if there's a network error?
>Will it timeout?  How long?

I have implemented something similar (many of us have, I'm sure).

Looking through the sample code should help to understand the answers to
your questions:

<http://developer.apple.com/samplecode/CFNetworkHTTPDownload/
CFNetworkHTTPDownload.html>

 ...Duane

 _______________________________________________
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

References: 
 >CFReadStreamCreateForHTTPRequest (From: Chris Branch <email@hidden>)

  • Prev by Date: CFReadStreamCreateForHTTPRequest
  • Next by Date: Regarding CFRunLoop and multible outgoing connections
  • Previous by thread: CFReadStreamCreateForHTTPRequest
  • Next by thread: Regarding CFRunLoop and multible outgoing connections
  • Index(es):
    • Date
    • Thread