forked from Bananymous/banan-os
Kernel: Add basic support for O_NONBLOCK (only for tty)
This commit is contained in:
parent
19d0fb6fcd
commit
f1d4d5f995
|
@ -87,6 +87,7 @@ namespace Kernel
|
||||||
|
|
||||||
virtual BAN::ErrorOr<size_t> read(size_t, void*, size_t) { if (mode().ifdir()) return BAN::Error::from_errno(EISDIR); ASSERT_NOT_REACHED(); }
|
virtual BAN::ErrorOr<size_t> read(size_t, void*, size_t) { if (mode().ifdir()) return BAN::Error::from_errno(EISDIR); ASSERT_NOT_REACHED(); }
|
||||||
virtual BAN::ErrorOr<size_t> write(size_t, const void*, size_t) { if (mode().ifdir()) return BAN::Error::from_errno(EISDIR); ASSERT_NOT_REACHED(); }
|
virtual BAN::ErrorOr<size_t> write(size_t, const void*, size_t) { if (mode().ifdir()) return BAN::Error::from_errno(EISDIR); ASSERT_NOT_REACHED(); }
|
||||||
|
virtual bool has_data() const { dwarnln("nonblock not supported"); return true; }
|
||||||
|
|
||||||
virtual BAN::ErrorOr<void> truncate(size_t) { if (mode().ifdir()) return BAN::Error::from_errno(EISDIR); return BAN::Error::from_errno(ENOTSUP); }
|
virtual BAN::ErrorOr<void> truncate(size_t) { if (mode().ifdir()) return BAN::Error::from_errno(EISDIR); return BAN::Error::from_errno(ENOTSUP); }
|
||||||
|
|
||||||
|
|
|
@ -35,6 +35,7 @@ namespace Kernel
|
||||||
|
|
||||||
virtual BAN::ErrorOr<size_t> read(size_t, void*, size_t) override;
|
virtual BAN::ErrorOr<size_t> read(size_t, void*, size_t) override;
|
||||||
virtual BAN::ErrorOr<size_t> write(size_t, const void*, size_t) override;
|
virtual BAN::ErrorOr<size_t> write(size_t, const void*, size_t) override;
|
||||||
|
virtual bool has_data() const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void clear();
|
void clear();
|
||||||
|
@ -78,7 +79,7 @@ namespace Kernel
|
||||||
};
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Kernel::SpinLock m_lock;
|
mutable Kernel::SpinLock m_lock;
|
||||||
|
|
||||||
State m_state { State::Normal };
|
State m_state { State::Normal };
|
||||||
AnsiState m_ansi_state { };
|
AnsiState m_ansi_state { };
|
||||||
|
|
|
@ -234,6 +234,8 @@ namespace Kernel
|
||||||
{
|
{
|
||||||
TRY(validate_fd(fd));
|
TRY(validate_fd(fd));
|
||||||
auto& open_file = m_open_files[fd];
|
auto& open_file = m_open_files[fd];
|
||||||
|
if ((open_file->flags & O_NONBLOCK) && !open_file->inode->has_data())
|
||||||
|
return 0;
|
||||||
size_t nread = TRY(open_file->inode->read(open_file->offset, buffer, count));
|
size_t nread = TRY(open_file->inode->read(open_file->offset, buffer, count));
|
||||||
open_file->offset += nread;
|
open_file->offset += nread;
|
||||||
return nread;
|
return nread;
|
||||||
|
|
|
@ -679,6 +679,12 @@ flush:
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool TTY::has_data() const
|
||||||
|
{
|
||||||
|
LockGuard _(m_lock);
|
||||||
|
return m_output.flush;
|
||||||
|
}
|
||||||
|
|
||||||
void TTY::putchar_current(uint8_t ch)
|
void TTY::putchar_current(uint8_t ch)
|
||||||
{
|
{
|
||||||
ASSERT(s_tty);
|
ASSERT(s_tty);
|
||||||
|
|
Loading…
Reference in New Issue