Re: Overlapping requests on multiple persistent connections?
Re: Overlapping requests on multiple persistent connections?
- Subject: Re: Overlapping requests on multiple persistent connections?
- From: Mark Pauley <email@hidden>
- Date: Mon, 1 Dec 2008 15:03:11 -0800
A word of warning:
This is relying on an implementation detail that is unlikely to
change, but it might. Our CFHTTPReadStream API suggests nothing about
the underlying connection, the HTTPStream won't tell you when the
server has closed the connection and your next request has been
enqueued on another socket.
That being said, for now Jim's hack will work. You can essentially
manage k connections to the remote host by specifying streams with a
"Queue" property name whose value is a CFNumber 0->k-1 or any such set
of k unique identifiers. These queues will be FIFO, though you should
be able to reschedule them by cancel / re-create.
To keep a connection open, you must have at least one open stream on
any given connection. It may not matter to you, but if you happen to
close all streams in one of these logical queues and then open a new
stream in that queue later, a brand new socket will be created for you.
On Nov 29, 2008, at 8:30 AM, Jim Luther wrote:
Mike,
I had the same problem with multiple persistent connections when I
brought the WebDAV file system up on CFNetwork. The trick is to make
each CFReadStream unique so that CFNetwork's connection cache won't
try to queue up your new request on a persistent connection it
already has open. This is pretty easy -- just create a unique
CFString (or number) value for each persistent connection you want
and then set that value as a property on the CFReadStream after you
create it but before you open it. For example:
newReadStreamRef =
CFReadStreamCreateForHTTPRequest(kCFAllocatorDefault, request);
/* add persistent property */
CFReadStreamSetProperty(newReadStreamRef,
kCFStreamPropertyHTTPAttemptPersistentConnection, kCFBooleanTrue);
/* make the read stream unique */
CFReadStreamSetProperty(newReadStreamRef, CFSTR("UniqueProperty"),
uniqueValue);
- Jim
On Nov 28, 2008, at 7:58 AM, Michael Bernardo wrote:
I'm trying to use the CFNetwork APIs to make multiple simultaneous
HTTP POST requests to a web service using persistent connections.
I've followed the model used by sample code at "/Developer/Examples/
Networking/Get Example" to get a single persistent connection
working. I can verify that with single, serial requests, the
connection is re-used.
The trouble starts when I try to send simultaneous overlapping
requests. It seems that CFNetwork only creates a single underlying
network connection, no matter how many simultaneous requests are
outstanding.
Is this expected behavior? Is there any way to get multiple
persistent connections created?
TIA,
Mike Bernardo
_______________________________________________
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
_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