• 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: Write stream proxy
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Write stream proxy


  • Subject: Re: Write stream proxy
  • From: Quinn <email@hidden>
  • Date: Wed, 10 Sep 2008 13:18:38 +0100

At 10:26 -0700 9/9/08, Jack Brindle wrote:
For file transfers we do the same thing except create the dual socket setup and call CFReadStreamCreateForStreamedHTTPRequest on the read stream. However the read stream looks to be handled as a raw stream of bits, without http-specific handling. It uses CFWriteStreamWrite to send the data. No calls are made to anything with the characters HTTP in the name for this stream. Am I right in the feeling that this really isn't what I need to have?

It depends (-: When you create a streamed CFHTTP request (by calling CFReadStreamCreateForStreamedHTTPRequest) CFHTTP will call the supplied read stream to get the bytes for the body of the request. This isn't HTTP at all, it's just a raw stream of bytes. A typical usage is, if you want to upload a file, you create a file read stream (CFReadStreamCreateWithFile) and pass that to CFReadStreamCreateForStreamedHTTPRequest.


The only reason you need to do the whole socket pair thing is if the data that you want to upload isn't present in one single file (or one single block of memory). In that case, you have a number of options:

A. If the data is relatively small, you can flatten it to a temporary file and then create a file read stream and use that. Similarly, you can flatten it to a temporary block of memory.

OTOH, if the data is large, this approach is too inefficient.

B. If you're OK with using Objective-C and the data is all present (that is, you don't need to be scheduled on a runloop in order to produce the data), you can create the data from a custom subclass of NSInputStream. Subclassing NSInputStream for asynchronous streams isn't something we support, but it should be OK for synchronous streams.

I haven't actually tried this though (-:

C. If all else fails, you can produce the data using the technique that you're already using, that is, create a socket pair, create a read stream for one member of the pair and a write stream for the other, and feed the data to the CFHTTP request by writing it to the write stream.

If you do this you won't need to mess with proxies on the streams you create for the socket pair. Those streams are just used for internal communication within your program. The only stream that needs to deal with proxies is the main CFHTTP stream.

S+E
--
Quinn "The Eskimo!"                    <http://www.apple.com/developer/>
Apple Developer Relations, Developer Technical Support, Core OS/Hardware
_______________________________________________
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


  • Follow-Ups:
    • Re: Write stream proxy
      • From: Jack Brindle <email@hidden>
    • Re: Write stream proxy
      • From: Mark Pauley <email@hidden>
References: 
 >Re: Write stream proxy (From: Jack Brindle <email@hidden>)

  • Prev by Date: Re: Write stream proxy
  • Next by Date: Re: Write stream proxy
  • Previous by thread: Re: Write stream proxy
  • Next by thread: Re: Write stream proxy
  • Index(es):
    • Date
    • Thread