C stdio unbuffered multiplexing

I'm working on a little program that needs to pipe binary streams very closely (unbuffered). It has to rely on select() multiplexing and is never allowed to "hold existing input unless more input has arrived, because it's not worth it yet".

It's possible using System calls, but then again, I would like to use stdio for convenience (string formatting is involved, too).

  • Can I safely use select() on a stream's underlying file descriptor as long as I'm using unbuffered stdio? If not, how can I determine a FILE stream that will not block from a set?
  • Is there any call that transfers all input from libc to the the application, besides the char-by-char functions ( getchar() and friends)?

  • While I'm not entirely clear on whether it's sanctioned by the standards, using select on fileno(f) should in practice work when f is unbuffered. Keep in mind however that unbuffered stdio can perform pathologically bad, and that you are not allowed to change the buffering except as the very first operation before you use the stream at all.

    If your only concern is being able to do formatted output, the newly-standardized-in-POSIX-2008 dprintf (and vdprintf ) function might be a better solution to your problem.

    链接地址: http://www.djcxy.com/p/68802.html

    上一篇: 当标准输入缓冲区中已有数据时,在标准输入上选择()

    下一篇: C stdio无缓冲复用