Re: Asynchronous sockets?
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.