On Sep 21, 2009, at 10:14 AM, Sixten Otto wrote:

I don't think that that gets me out of the problem I was really trying
to ask about, though, which is how to manage getting the work from the
(single) queue of requests from the user to the exactly N persistent
connections available to the application. Somehow I need to track
which/how many connections are idle, and dequeue requests to those
connections.

Just keep a mutable array of free connections.
When a request arrives, and a connection is free, give it to the first free connection and remove the connection from the array. Or if there aren't any free connections, add the request to a queue (another mutable array). When a connection finishes its work, re-add it to the array, and if there are requests waiting in the queue, remove the oldest one and give it to the connection.

Do you have control over the protocol used by the server? There are more efficient ways to do this, like multiplexing multiple requests over a socket. (The BLIP protocol in MYNetwork does that; you can run any number of parallel messages over one socket at once.)

—Jens_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to