diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-04-29 04:55:54 +0200 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-04-29 04:55:54 +0200 |
commit | 0a0d739e98327e5244106931d1fbe1e7a796e35b (patch) | |
tree | 5aec880dfe3a95886bb93a8f68fdb14f525ac0fa /Kernel/FileSystem/FIFO.cpp | |
parent | f254a84d17f04d0410689e7a8eece7498c33144d (diff) | |
download | serenity-0a0d739e98327e5244106931d1fbe1e7a796e35b.zip |
Kernel: Make FIFO inherit from File.
Diffstat (limited to 'Kernel/FileSystem/FIFO.cpp')
-rw-r--r-- | Kernel/FileSystem/FIFO.cpp | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/Kernel/FileSystem/FIFO.cpp b/Kernel/FileSystem/FIFO.cpp index b229c75b76..1bc4a550ac 100644 --- a/Kernel/FileSystem/FIFO.cpp +++ b/Kernel/FileSystem/FIFO.cpp @@ -1,4 +1,5 @@ #include <Kernel/FileSystem/FIFO.h> +#include <Kernel/FileSystem/FileDescriptor.h> #include <Kernel/Lock.h> #include <AK/StdLibExtras.h> #include <AK/HashTable.h> @@ -27,6 +28,14 @@ Retained<FIFO> FIFO::create(uid_t uid) return adopt(*new FIFO(uid)); } +Retained<FileDescriptor> FIFO::open_direction(FIFO::Direction direction) +{ + auto descriptor = FileDescriptor::create(this); + attach(direction); + descriptor->set_fifo_direction({ }, direction); + return descriptor; +} + FIFO::FIFO(uid_t uid) : m_uid(uid) { @@ -40,7 +49,7 @@ FIFO::~FIFO() all_fifos().resource().remove(this); } -void FIFO::open(Direction direction) +void FIFO::attach(Direction direction) { if (direction == Reader) { ++m_readers; @@ -55,7 +64,7 @@ void FIFO::open(Direction direction) } } -void FIFO::close(Direction direction) +void FIFO::detach(Direction direction) { if (direction == Reader) { #ifdef FIFO_DEBUG @@ -72,17 +81,17 @@ void FIFO::close(Direction direction) } } -bool FIFO::can_read() const +bool FIFO::can_read(Process&) const { return !m_buffer.is_empty() || !m_writers; } -bool FIFO::can_write() const +bool FIFO::can_write(Process&) const { return m_buffer.bytes_in_write_buffer() < 4096; } -ssize_t FIFO::read(byte* buffer, ssize_t size) +ssize_t FIFO::read(Process&, byte* buffer, ssize_t size) { if (!m_writers && m_buffer.is_empty()) return 0; @@ -96,7 +105,7 @@ ssize_t FIFO::read(byte* buffer, ssize_t size) return nread; } -ssize_t FIFO::write(const byte* buffer, ssize_t size) +ssize_t FIFO::write(Process&, const byte* buffer, ssize_t size) { if (!m_readers) return 0; @@ -105,3 +114,8 @@ ssize_t FIFO::write(const byte* buffer, ssize_t size) #endif return m_buffer.write(buffer, size); } + +String FIFO::absolute_path() const +{ + return String::format("fifo:%u", this); +} |