site_archiver@lists.apple.com Delivered-To: darwin-kernel@lists.apple.com T _______________________________________________ Do not post admin requests to the list. They will be ignored. Darwin-kernel mailing list (Darwin-kernel@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/darwin-kernel/site_archiver%40lists.a... On Sep 11, 2007, at 4:35 PM, Terry Lambert wrote: If they should both think they are talking to serial ports, then you can write a little program that opens the master side of two ptys, calls grantpt() on both and unlockpt() on both, uses fcntl() to put them in non-blocking mode, then calls select() on both, and when they become active, writes the data from one end to the other and vice versa. I've written a little app that does this, mostly... openpty(3) handles most of the getpt/grantpt/unlockpt/etc stuff... at least I think. :) I've scanned through implementations of openpty on Google Code Search and it looks like it, at least. My app calls openpty twice, and has a loop with select that reads from one master and writes the data read to the other master. My understanding was that if you write to a ptm, it actually goes to the input of the pts... and writing to the pts is input for the ptm. The good news is that the clients who just open up the slave ptys correctly get their input read, and they receive data from my app. There's one small problem... what is also happening *inside* my app is that if I write to my master file descriptor it also becomes input for the other... which means that every time I read from masterA and write to masterB, masterB is then flagged as having input to be read... which means I get an infinite loop of data being copied back and forth. This happens every loop, no matter the delay between iterations (I'm running it inside Xcode). I am hoping this can be prevented, as there is no way to tell the difference between the master being ready to read because of input from the a client writing to the slave pty, or from app writing to that master file descriptor. I have to assume that I'm missing some small detail. Pouring through Stevens' Advanced Programming in the UNIX Environment has not yet revealed any answers. Any ideas out there? -- Some people, when confronted with a problem, think "I know, I'll use regular expressions." Now they have two problems. --Jamie Zawinski, in comp.lang.emacs This email sent to site_archiver@lists.apple.com