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:
parent
982b9a732a
commit
9c193777a9
1 changed files with 16 additions and 0 deletions
|
@ -51,6 +51,8 @@ namespace Sortix
|
||||||
size_t bufferused;
|
size_t bufferused;
|
||||||
Event readevent;
|
Event readevent;
|
||||||
Event writeevent;
|
Event writeevent;
|
||||||
|
bool anyreading;
|
||||||
|
bool anywriting;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual ssize_t Read(byte* dest, size_t count);
|
virtual ssize_t Read(byte* dest, size_t count);
|
||||||
|
@ -58,6 +60,10 @@ namespace Sortix
|
||||||
virtual bool IsReadable();
|
virtual bool IsReadable();
|
||||||
virtual bool IsWritable();
|
virtual bool IsWritable();
|
||||||
|
|
||||||
|
public:
|
||||||
|
void NotReading();
|
||||||
|
void NotWriting();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
DevPipeStorage::DevPipeStorage(byte* buffer, size_t buffersize)
|
DevPipeStorage::DevPipeStorage(byte* buffer, size_t buffersize)
|
||||||
|
@ -66,6 +72,8 @@ namespace Sortix
|
||||||
this->buffersize = buffersize;
|
this->buffersize = buffersize;
|
||||||
this->bufferoffset = 0;
|
this->bufferoffset = 0;
|
||||||
this->bufferused = 0;
|
this->bufferused = 0;
|
||||||
|
this->anyreading = true;
|
||||||
|
this->anywriting = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
DevPipeStorage::~DevPipeStorage()
|
DevPipeStorage::~DevPipeStorage()
|
||||||
|
@ -93,6 +101,8 @@ namespace Sortix
|
||||||
return amount + Read(dest + amount, count - amount);
|
return amount + Read(dest + amount, count - amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( !anywriting ) { return 0; }
|
||||||
|
|
||||||
Error::Set(EBLOCKING);
|
Error::Set(EBLOCKING);
|
||||||
readevent.Register();
|
readevent.Register();
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -100,6 +110,7 @@ namespace Sortix
|
||||||
|
|
||||||
ssize_t DevPipeStorage::Write(const byte* src, size_t count)
|
ssize_t DevPipeStorage::Write(const byte* src, size_t count)
|
||||||
{
|
{
|
||||||
|
if ( !anyreading ) { /* TODO: SIGPIPE */ }
|
||||||
if ( count == 0 ) { return 0; }
|
if ( count == 0 ) { return 0; }
|
||||||
if ( bufferused < buffersize )
|
if ( bufferused < buffersize )
|
||||||
{
|
{
|
||||||
|
@ -120,6 +131,9 @@ namespace Sortix
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DevPipeStorage::NotReading() { anyreading = false; }
|
||||||
|
void DevPipeStorage::NotWriting() { anywriting = false; }
|
||||||
|
|
||||||
class DevPipeReading : public DevStream
|
class DevPipeReading : public DevStream
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -148,6 +162,7 @@ namespace Sortix
|
||||||
|
|
||||||
DevPipeReading::~DevPipeReading()
|
DevPipeReading::~DevPipeReading()
|
||||||
{
|
{
|
||||||
|
((DevPipeStorage*) stream)->NotReading();
|
||||||
stream->Unref();
|
stream->Unref();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -200,6 +215,7 @@ namespace Sortix
|
||||||
|
|
||||||
DevPipeWriting::~DevPipeWriting()
|
DevPipeWriting::~DevPipeWriting()
|
||||||
{
|
{
|
||||||
|
((DevPipeStorage*) stream)->NotWriting();
|
||||||
stream->Unref();
|
stream->Unref();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue