Menu

O_NONBLOCK on pipes

2002-01-29
2002-02-04
  • Dave Fisher

    Dave Fisher - 2002-01-29

    I need to be able to read from a pipe, but not have it block while doing so.  Would it be possible to add this functionality into the Pipe class?  Right now I have simply rewritten the class, but it would be nice to be able to either derive a new class from Pipe in order to set the read to non-blocking, or add a new method in Pipe itself.

    In order to derive a new class, I would need access to fd[0], which would mean either making it protected instead of private, or create an accessor function for it.

    Or, add another method while might look something like this:

    void Pipe::setNonBlockingRead()
    {
      int status = fcntl( fd[0], F_SETFL, O_NONBLOCK );

      if ( status == -1 )
      {
          throw this;
      }
    }

    I do not know how to set the read to non-blocking in WIN32, however, so portability may be an issue. :-(

     
    • David Sugar

      David Sugar - 2002-02-04

      One reason I tend not to use that is because it only works well if the objects moved thru the pipe are fixed size and a multiple of the pipe buffer size.  This way no partial writes on "un-aligned" objects can occur into a full buffer.

       
    • David Sugar

      David Sugar - 2002-02-04

      One reason I tend not to use that is because it only works well if the objects moved thru the pipe are fixed size and a multiple of the pipe buffer size.  This way no partial writes on "un-aligned" objects can occur into a full buffer.

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.