• 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: Managing Multiple Connections
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Managing Multiple Connections


  • Subject: Re: Managing Multiple Connections
  • From: Dietrich Epp <email@hidden>
  • Date: Wed, 21 May 2003 11:35:14 -0700

Wow, thanks! I thought CFSockets et al. were just a thin layer on top of BSD sockets. After reading the CF*Stream and CFSocket docks, I think I'll use that.

I wish traditional UNIX IPC were a little more coherent, though. Nobody should ever have to consider using file descriptors for sending messages to a thread. The CFRunLoop method looks very much like the Right Way (TM) to do things.

--Dietrich

On Wednesday, May 21, 2003, at 09:03 US/Pacific, Becky Willrich wrote:

I believe the select thread is the traditional way to do this in UNIX, using a file descriptor for communication between other threads and the select thread. As Quinn says, a thread per connection is dangerous if you will have many open connections. If you can affectively limit the number of connections to a handful, though, this approach is sound, and is what several web servers do. On MacOS X, the easiest way to do what you want, though, is to create a run loop source for each open connection, then run the run loop. CFSocket will give you a run loop source per socket; CFRead/WriteStream will give you a stream abstraction (as well as run loop integration) per socket, and can be used to build the socket for you if you wish. Your code will look roughly like this:

for each socket
build a CFSocket or CFRead/WriteStream
if CFSocket
get CFSocket's run loop source
schedule the run loop source on the current run loop, current mode
else if CFRead/WriteStream
schedule the stream on the current run loop, current mode
CFRunLoopRun(CFRunLoopGetCurrent())

CFRunLoopRun() will never exit until the run loop is explicitly halted. The usual way to arrange for cross-thread communication in this model is to build a custom run loop source (see CFRunLoop.h; this isn't as hard as it sounds) and install it on the run loop as well. When you want to communicate something to the connection thread, you signal the custom run loop source; that will cause its signal callback to be called on the connection thread.

Hope that helps,
REW
_______________________________________________
macnetworkprog mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/macnetworkprog
Do not post admin requests to the list. They will be ignored.

References: 
 >Re: Managing Multiple Connections (From: Becky Willrich <email@hidden>)

  • Prev by Date: Re: Managing Multiple Connections
  • Next by Date: writeData: Question
  • Previous by thread: Re: Managing Multiple Connections
  • Next by thread: writeData: Question
  • Index(es):
    • Date
    • Thread