Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!samsung!uunet!murphy!dwrsun2!perl From: perl@dwrsun2.UUCP (Robert Perlberg) Newsgroups: comp.unix.questions Subject: Re: writing an lpr filter (SunOS 4.1.1) Summary: buffer flushing Message-ID: <2337@prodigal.dwrsun2.UUCP> Date: 20 Jun 91 21:05:15 GMT References: <28820@uflorida.cis.ufl.EDU> <28839@uflorida.cis.ufl.EDU> Organization: Dean Witter Reynolds Inc., New York Lines: 32 In writing an lpd filter for an HP LaserJet, I discovered something important. It may not be necessary on all systems, but it sure was on mine (SunOS 3.5 at the time). I had a problem with handshaking not working and sometimes small jobs just wouldn't print at all. I discovered that the problem was that since my filter exits as soon as it finishes writing to the serial port, the port had not been flushed. Apparently, when you close a serial port before all of the data in the output queue has been physically transmitted it can cause the driver to stop doing handshaking, or to throw away the rest of the output queue. I solved the problem by making sure in the filter that the serial port output queue was empty before exiting. Here is the code I used for this: #include ... int outchars; ... fflush(stdout); while(ioctl(fileno(stdout), TIOCOUTQ, &outchars) == 0 && outchars > 0) { sleep(1); } Robert Perlberg Dean Witter Reynolds Inc., New York murphy!dwrsun2!perl -- "I am not a language ... I am a free man!"