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. :-(
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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. :-(
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.
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.