• 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: BSD events on NSRunLoop?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: BSD events on NSRunLoop?


  • Subject: Re: BSD events on NSRunLoop?
  • From: Nathan Day <email@hidden>
  • Date: Mon, 21 Oct 2002 20:08:52 +0930

You can look at my NDRunLoopMessenger code it does stuff similar to what it sounds like you are trying to do. Specifically look at the sendData function. It's on my web site
http://homepage.mac.com/nathan_day/

On Monday, October 21, 2002, at 08:01 AM, Fritz Anderson wrote:

I have an application in which I read line-oriented input from a serial port. The termios system has a nice set of options whereby read(2) will block waiting for full lines of input, making my job much simpler at that level.

I have an architecture wherein various clients register for the particular line content they want, and the read-serial-line loop dispatches among them as lines come in. It works, but if you do dispatching on the same thread as the port service, you risk losing lines, and if you separate the port-service and line-dispatch threads, the result is insanely inefficient and bug-prone.

Well, the arrival of a line is just an event like any other; why can't I put it into the main run loop? This would seem to require that an NSPort of some kind be attached to the main NSRunLoop; pass it to the port-service thread; have the port-service wrap the incoming lines in NSPortMessages for that port; and pass sendBeforeDate: to the message. The line-dispatch code then goes into a handlePortMessage: handler, right?

PROBLEM
Well, it seems that I cannot call sendBeforeDate: without getting a bad-access exception. I've made every variant on the relevant calls I can think of (I think) but one: I do not have an NSRunLoop running on the port-service thread. Obviously I don't have an NSRunLoop running on the port-service thread: Getting an NSRunLoop to trigger when a read() unblocks is exactly the problem I'm trying to solve.

QUESTIONS
My questions are:

1. Am I right that having no run mode is the problem? Or should I go back to debugging?

2. Is there a way to add a BSD-unblock event to an NSRunLoop? Is there a best way? Am I reduced to sleep-and-poll or NSTimer-poll?


Nathan Day
http://homepage.mac.com/nathan_day/
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

References: 
 >BSD events on NSRunLoop? (From: Fritz Anderson <email@hidden>)

  • Prev by Date: openDocument
  • Next by Date: Deallocation in Cocoa [greenhorn]
  • Previous by thread: BSD events on NSRunLoop?
  • Next by thread: Re: cocoa-dev digest, Vol 2 #1410 - 12 msgs
  • Index(es):
    • Date
    • Thread