From 514fab535959a7a35644bbc5a885bb17ded7630f Mon Sep 17 00:00:00 2001 From: Jonas 'Sortie' Termansen Date: Sun, 31 Mar 2013 17:26:03 +0200 Subject: [PATCH] Add O_NONBLOCK support to pipes. --- sortix/pipe.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/sortix/pipe.cpp b/sortix/pipe.cpp index 1bd3a891..715d79e4 100644 --- a/sortix/pipe.cpp +++ b/sortix/pipe.cpp @@ -149,6 +149,8 @@ ssize_t PipeChannel::read(ioctx_t* ctx, uint8_t* buf, size_t count) if ( !lock.IsAcquired() ) { errno = EINTR; return -1; } while ( anywriting && !bufferused ) { + if ( ctx->dflags & O_NONBLOCK ) + return errno = EWOULDBLOCK, -1; if ( !kthread_cond_wait_signal(&readcond, &pipelock) ) { errno = EINTR; @@ -175,6 +177,8 @@ ssize_t PipeChannel::write(ioctx_t* ctx, const uint8_t* buf, size_t count) if ( !lock.IsAcquired() ) { errno = EINTR; return -1; } while ( anyreading && bufferused == buffersize ) { + if ( ctx->dflags & O_NONBLOCK ) + return errno = EWOULDBLOCK, -1; if ( !kthread_cond_wait_signal(&writecond, &pipelock) ) { errno = EINTR;