Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!usenet.ins.cwru.edu!tut.cis.ohio-state.edu!rutgers!cmcl2!stealth.acf.nyu.edu!brnstnd From: brnstnd@stealth.acf.nyu.edu Newsgroups: comp.unix.questions Subject: Re: How to do a non-blocking write of more than one char? Message-ID: <20081@stealth.acf.nyu.edu> Date: 16 Jan 90 23:08:35 GMT References: <2759@stealth.acf.nyu.edu> <2799@auspex.auspex.com> <5564@stealth.acf.nyu.edu> <2816@auspex.auspex.com> Reply-To: brnstnd@stealth.acf.nyu.edu (Dan Bernstein) Distribution: usa Organization: IR Lines: 29 I'm trying to write a ``multitee'' program so that, e.g., multitee 0:6,7 6:1 would send all input from fd 0 to fd 6 and fd 7, while sending all input from fd 6 to fd 1. It's a trivial problem, except that multitee should do its best to never block on writes. (Otherwise it could enter a deadlock with another process.) Buffering is easy, but how to avoid blocking? One correct answer is to always write just one character per write() call. Unfortunately, this usually forces a hellish overhead. Another answer is to use fcntl() and set FNDELAY on the descriptor. Unfortunately, this doesn't just affect the descriptor; it affects the entire open file, including possibly other processes. (This is the real problem.) Another answer is that multitee should fork into separate processes, one for each input descriptor. This works and solves the flow control problems, but it's not very polite to other processes unless the system supports threads. In article <2816@auspex.auspex.com> guy@auspex.auspex.com (Guy Harris) writes: > >C'mon, guys, this is a simple question! > And it may have a simple answer like "sorry, you can't do it". I guess it's a good question, then... ---Dan