Network Programming Models (was OTCountFreeBytes?)
Network Programming Models (was OTCountFreeBytes?)
- Subject: Network Programming Models (was OTCountFreeBytes?)
- From: Quinn <email@hidden>
- Date: Mon, 4 Feb 2002 10:36:52 +0000
At 23:06 +1300 4/2/02, Bryan Christianson wrote:
Alternatively, you can use pthreads, with the thread hanging on a
read (or some other blocking condition) until an event occurs (such
as a packet arrival).
As an alternative alternative, if your application is Mac OS X-only
and CFRunLoop based (Carbon or Cocoa are), you can use CFNetwork. It
delivers data to your application from a runloop event source, which
means it runs cooperatively with respect to all the other events in
your application.
You can even combine these techniques. Each pthread has its own
runloop, so you can start a pthread and then add all your CFNetwork
runloop sources to it. This thread runs preemptively with respect to
the rest of your application, but it only ever dispatches one
callback at a time.
The possibilities are endless. Deciding the approach to use depends
a lot on your application's structure. If you need to do a lot of
GUI stuff from your network callbacks, CFNetwork on the main runloop
is an excellent solution. If you want absolute best performance on
hundreds of connections simultaneously, lots of non-blocking socket
with select (bletch) is fastest. If you want a high-speed solution
for a limited number of connections with a nice programming model,
one pthread per connection works well.
S+E
--
Quinn "The Eskimo!" <
http://www.apple.com/developer/>
Apple Developer Technical Support * Networking, Communications, Hardware