• 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: Asynchronous sockets?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Asynchronous sockets?


  • Subject: Re: Asynchronous sockets?
  • From: Douglas Davidson <email@hidden>
  • Date: Wed, 6 Feb 2002 16:04:27 -0800

On Wednesday, February 6, 2002, at 03:40 PM, Duane Murphy wrote:

I have been scanning Steven's looking for a solution. The only solution I
have seen uses threads. The fundamental problem with this is how to clean
up the thread nicely. Aborting a thread is the equivalent of kill -9; No
hope to clean anything up, just recover the memory and move on.

There are plenty of ways to solve that. For example, you can make your threads select not only on their own sockets, but also on one or more local "wakeup" sockets. When you want a thread to halt or do something else, write to an appropriate wakeup socket; the thread returns from select, notices it's been woken up, and checks some flag to determine what it should do.

There are many other patterns; for example, one thread can select on many different sockets, and notify one or more worker threads when data arrives.

Someone also suggested the use of CFSocket and CFRunLoop for this. The "run loop" is the basic abstraction behind both Carbon and Cocoa event loops, but it can also be explicitly used via CFRunLoop in other contexts. CFSocket permits a socket to act as a run loop source, so that you can receive a callback when e.g. data arrives.

Douglas Davidson
_______________________________________________
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: Asynchronous sockets? (From: Duane Murphy <email@hidden>)

  • Prev by Date: Re: Asynchronous sockets?
  • Next by Date: Re: Asynchronous sockets?
  • Previous by thread: Re: Asynchronous sockets?
  • Next by thread: Re: Asynchronous sockets?
  • Index(es):
    • Date
    • Thread