1
0
Fork 0
mirror of https://gitlab.com/sortix/sortix.git synced 2023-02-13 20:55:38 -05:00

Pipes now return 0 (EOF) if no data and no fds can write.

This commit is contained in:
Jonas 'Sortie' Termansen 2012-03-01 14:31:12 +01:00
parent 982b9a732a
commit 9c193777a9

View file

@ -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();
}