// iterate over I/O registry to find desired node and keep your
// registry entry node (See DTS docs for a write up on how to do
this)
io_registry_entry_t portre = <do the search>
int fd;
int preempt;
tryAgain:
for (;;) {
do {
fd = open(<tty.dialindevice>, O_NONBLOCK);
if (-1 == fd)
if (EBUSY == errno)
continue;
else
exit(1); // Fatal error
// clear O_NONBLOCK flag
if (-1 == fcntl(fd, F_SETFL, 0))
exit(1); // fatal error
// We must have had an EBUSY error to be here so wait for idle
if (kIOReturnSuccess != IORegistryEntrySetProperty(portre,
CFSTR(kIOTTYWaitForIdleKey), kCFBooleanTrue)
exit(1); // Fatal error
};
// At this point you have the port exclusively and non-preemtibly
// so now is a good time to program up the modem or do any other
// equipment initialisation you desire.
// Now the port is in the preemptible - blocking state
// time to issue a blocking read or a select as needed
// waiting for whatever event you are want.
if (-1 == read(fd, buf, sizeof(buf)) // Pseudo code
if (EIO == errno) {
close(fd); // We have been preempted.
goto tryAgain;
}
else
exit(1); // probably fatal
// We have a connection and it is time to say we are no longer
// preemptible
preempt = 0;
if (-1 == ioctl(fd, IOSSPREEMPT, &preempt)) // Disable preemption
exit(1); // Fatal error
// That's it while we are running non-preemtibly/exclusive further
// attempts to open the port on either cu.* or tty.* will fail with
EBUSY
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/darwin-dev/email@hidden