From 9c193777a9acfc6177d4114ff41bfd0df281b14e Mon Sep 17 00:00:00 2001 From: Jonas 'Sortie' Termansen Date: Thu, 1 Mar 2012 14:31:12 +0100 Subject: [PATCH] Pipes now return 0 (EOF) if no data and no fds can write. --- sortix/pipe.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/sortix/pipe.cpp b/sortix/pipe.cpp index 47de660a..5e56c2a5 100644 --- a/sortix/pipe.cpp +++ b/sortix/pipe.cpp @@ -51,6 +51,8 @@ namespace Sortix size_t bufferused; Event readevent; Event writeevent; + bool anyreading; + bool anywriting; public: virtual ssize_t Read(byte* dest, size_t count); @@ -58,6 +60,10 @@ namespace Sortix virtual bool IsReadable(); virtual bool IsWritable(); + public: + void NotReading(); + void NotWriting(); + }; DevPipeStorage::DevPipeStorage(byte* buffer, size_t buffersize) @@ -66,6 +72,8 @@ namespace Sortix this->buffersize = buffersize; this->bufferoffset = 0; this->bufferused = 0; + this->anyreading = true; + this->anywriting = true; } DevPipeStorage::~DevPipeStorage() @@ -93,6 +101,8 @@ namespace Sortix return amount + Read(dest + amount, count - amount); } + if ( !anywriting ) { return 0; } + Error::Set(EBLOCKING); readevent.Register(); return -1; @@ -100,6 +110,7 @@ namespace Sortix ssize_t DevPipeStorage::Write(const byte* src, size_t count) { + if ( !anyreading ) { /* TODO: SIGPIPE */ } if ( count == 0 ) { return 0; } if ( bufferused < buffersize ) { @@ -120,6 +131,9 @@ namespace Sortix return -1; } + void DevPipeStorage::NotReading() { anyreading = false; } + void DevPipeStorage::NotWriting() { anywriting = false; } + class DevPipeReading : public DevStream { public: @@ -148,6 +162,7 @@ namespace Sortix DevPipeReading::~DevPipeReading() { + ((DevPipeStorage*) stream)->NotReading(); stream->Unref(); } @@ -200,6 +215,7 @@ namespace Sortix DevPipeWriting::~DevPipeWriting() { + ((DevPipeStorage*) stream)->NotWriting(); stream->Unref(); }