• 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: Multithreading program regarding write()
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Multithreading program regarding write()


  • Subject: Re: Multithreading program regarding write()
  • From: Quinn <email@hidden>
  • Date: Fri, 5 May 2006 10:37:38 +0100

At 21:23 +0200 4/5/06, Fredrik H. Larsen wrote:
I'm writing a program that at the moment uses two threads. I have one main thread for everything except for select() which is handled in the detached thread. My question is. How should my writeToHost: method be constructed so it doesn't block?

If you're already knee deep in "select" code, you might as well wade in all the way. For this sort of thing, you usually keeps a queue of data, one per connection, that holds the data waiting to be sent on that connection. You then write the data to the socket. If that fails with a flow control error, you put the data in the queue and retry the send when the "select" indicates that the socket has space.


Is there a reason you're doing this with your own thread and "select" rather than one of the higher-levels of abstraction? My CFLocalServer sample shows how to create a simple server than handles connections for multiple requests simultaneously. I do all of the work using CFSocket, which takes care of all the "select" ugliness for me.

<http://developer.apple.com/samplecode/CFLocalServer/CFLocalServer.html>

<broken_record> Oh, yes, and use kqueues rather than "select" </broken_record>

S+E
--
Quinn "The Eskimo!"                    <http://www.apple.com/developer/>
Apple Developer Relations, Developer Technical Support, Core OS/Hardware
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Macnetworkprog mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >Multithreading program regarding write() (From: "Fredrik H. Larsen" <email@hidden>)

  • Prev by Date: Re: Loopback problem?
  • Next by Date: Re: Multithreading program regarding write()
  • Previous by thread: Multithreading program regarding write()
  • Next by thread: Re: Multithreading program regarding write()
  • Index(es):
    • Date
    • Thread