Re: Write stream proxy
Re: Write stream proxy
- Subject: Re: Write stream proxy
- From: Jack Brindle <email@hidden>
- Date: Mon, 08 Sep 2008 15:19:11 -0700
- Thread-topic: Write stream proxy
Title: Re: Write stream proxy
This is specifically for writing files to a server. There is a control server and a separate transfer server. It is very important that we be able to set header properties, which I believe is the reason that the CFNetworking calls were used and not the higher level HTTP or NSURL calls. As I noted, I just recently inherited this code.
Adding info to what I previously said, and hopefully answering your questions, since this is a file send, a write stream is used. The file can be very long, and definitely may not be able to fit in memory. This is the reason for the write stream instead of the read stream. Successive CFWriteStreamWrite calls are made in response to the kCFStreamCanAcceptBytes event. Two properties are attached to the stream, kCFStreamPropertyShouldCloseNativeSocket and kCFStreamPropertyHTTPProxy.
The original author may indeed have chosen the least desirable interface for this code, but the argument I face is that it works. I am open to suggestions for alternatives if needed. I am puzzled at the moment, however, as to why the challenge is not coming back where I expect it (the write stream) or if it is being sent to a non-existant (or so I thought) read stream associated with the write stream.
I am led to believe that the read stream cannot handle files transfers that do not fit in memory. Is this no longer the case, or are the docs incorrect? Would a readstream be a better solution here?
Thanks!
Jack Brindle
YouSendIt, Inc.
On 9/8/08 2:31 PM, "Mark Pauley" <email@hidden> wrote:
I'm not sure what you're trying to do here. There is no such thing as a write stream for the CFNetwork HTTP or FTP API. If you would like to use the CFSocketStream API then you get a SOCKS proxy and that's it.
If you would like to send data via HTTP, you need to use one of the calls on CFHTTPMessage that sets a CFDataRef or a CFReadStream (in the case that you'd like to not have the entire contents of your upload in memory). You can easily create a CFReadStream with CFStreamCreateBoundPair. It sounds like this is what you'd like to do, correct?
On Sep 8, 2008, at 1:35 PM, Jack Brindle wrote:
I’m trying to add proxy support to an existing application. The read stream support runs great, but write stream does not.
The app creates a socket pair, then creates a read stream from one socket using CFStreamCreatePairWithSocket. In this call the writestream parameter is NULL. A write stream is then created using the same function, with the read stream parameter null this time. In both cases a run loop is used to allow the responses to be handled through callbacks. The streams communicate with a pair of servers, one which coordinates transfers, and the second to handle them. Things work great without a proxy in the system.
I added proxy support code to the read stream, basing the code on that in the ImageClient8 example. This works great for read streams and downloads, but things break when it is added (with appropriate changes) to the write stream. The proxy issues its challenge, but it is not conveyed through the callback mechanism as it is in the read stream case. The callback handles the cases of kCFStreamEventOpenCompleted, kCF StreamEventCanAcceptBytes and kCFStreamEventErrorOccurred quite well. In fact I am seeing an error reported through the latter, specifically for the domain kCFStreamErrorDomainPOSIX, error id of 32 (broken pipe). At no time do I get any response for the kCFStreamEventHasBytesAvailable case.
This brings up several questions. Should I see anything on the Bytes Available case for write streams? If not, do I need to instantiate a read stream on the socket just to receive challenges? Is it possible the challenges are coming in on the other socket’s read stream? I am definitely not seeing this in that stream’s data.
And, are there any examples for handling proxy through write streams? There are times (like sending files) when a read stream won’t do. I’m sure others have solved this problem.
Any help or suggestions?
Thanks!
Jack Brindle
YouSendIt, Inc.
_______________________________________________
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
_Mark
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