Re: BSD events on NSRunLoop?
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.