site_archiver@lists.apple.com Delivered-To: macnetworkprog@lists.apple.com See below. That's correct. No, CFHTTPStream will take care of that level for you. <http://www.lists.apple.com/macnetworkprog/> S+E -- Quinn "The Eskimo!" <http://www.apple.com/developer/> Apple Developer Relations, Developer Technical Support, Core OS/Hardware Date: Tue, 15 Jun 2004 10:47:20 -0500 From: Marc Epard <xxx@yyy> Subject: kCFStreamPropertyHTTPAttemptPersistentConnection To: macnetworkprog <macnetworkprog@lists.apple.com> I'm using CFNetwork for HTTP and I'd like to have persistent connections because I'm doing several transactions in a row. Before calling CFReadStreamOpen, I do this: bool isPersistent = CFReadStreamSetProperty(responseStream, kCFStreamPropertyHTTPAttemptPersistentConnection, kCFBooleanTrue); I've verified that isPersistent is true, but CFNetwork is still closing the TCP stream after each transaction. I'm making sure to read the entire response. I've tried keeping a reference to a stream around and not releasing it each time and I've tried not calling CFReadStreamClose. Still, CFNetwork closes the stream. I've used tcpdump and tcpflow to verify that both ends are including the Connection: Keep-Alive header and determined that it is the CFNetwork end that initiates the TCP close rather than the server. This is on 10.3.4. Any suggestions? Thanks. Date: Thu, 19 Aug 2004 09:44:46 -0500 From: Marc Epard <xxx@yyy> Subject: Re: kCFStreamPropertyHTTPAttemptPersistentConnection To: macnetworkprog <macnetworkprog@lists.apple.com> In case someone searches for this in the future: I talked to some Apple engineers at WWDC and found out the trick to get persistent HTTP connections to work in Panther: You must call CFReadStreamOpen to issue a subsequent request before calling CFReadStreamRead to read *any* of the response for the previous request. Issuing the next request before calling CFReadStreamClose on the previous response is not sufficient. [...] Date: Thu, 19 Aug 2004 10:05:10 -0700 From: Jeremy Wyld <xxx@yyy> Subject: Re: kCFStreamPropertyHTTPAttemptPersistentConnection To: macnetworkprog Programming <macnetworkprog@lists.apple.com> Let me fill in the details. _______________________________________________ Do not post admin requests to the list. They will be ignored. Macnetworkprog mailing list (Macnetworkprog@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/macnetworkprog/site_archiver%40lists.... At 15:38 -0800 20/1/10, John Michael Zorko wrote: 1. How to I keep the connection open once my callback gets called with kCFStreamEventEndEncountered? 2. It is my understanding that every new HTTP request needs a new CFReadStream so how do I tell the CFReadStream to _not_ initiate a new connection, but rather, keep using the current one? Set the kCFStreamPropertyHTTPAttemptPersistentConnection property. However, there's more to it than that. See below. 3. Is setting the HTTP keep-alive header to the correct value all I need to do, or do I need to do something else? The exact requirements to get CFHTTPStream to reuse a connection are not well documented. However, this has been discussed on the list many times before. I've included the most relevant (IMO) snippets below. When reading this, remember that "Panther" is Mac OS X 10.3 and "Tiger" is Mac OS X 10.4 (-: If you're looking for more modern discussions of this, you can search the list archives. At 10:47 -0500 15/6/04, Marc Epard wrote: -Marc At 9:44 -0500 19/8/04, Marc Epard wrote: -Marc At 10:05 -0700 19/8/04, Jeremy Wyld wrote: CFNetwork on Panther is very aggressive about reaping the HTTP sockets. If another request is queued before all the bytes are received on the previous request, the persistent connection will be maintained. The problem is that the act of reading could be the call to close down your persistent connection. This is why the described method will work. The open will cause the queueing, and the persistent connection is still open until the read. CFNetwork on Tiger has been changed to be less aggressive. An underlying, persistent connection is open as long as the last stream on that connection. Calling open before the previous request's close will get the new request enqueued on the persistent connection. "GET Example" in /Developer/Examples/Networking/ has been changed on the Tiger CD to use this model. jeremy This email sent to site_archiver@lists.apple.com
participants (1)
-
Quinn