Kernel/LibC: Implement basic epoll
This implementation is on top of inodes instead of fds as linux does it. If I start finding ports/software that relies on epoll allowing duplicate inodes, I will do what linux does. I'm probably missing multiple epoll_notify's which may cause hangs but the system seems to work fine :dd:
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
|
||||
#include <BAN/ScopeGuard.h>
|
||||
|
||||
#include <sys/epoll.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/sysmacros.h>
|
||||
|
||||
@@ -95,6 +96,8 @@ namespace Kernel
|
||||
reinterpret_cast<uint8_t*>(m_buffer->vaddr())[(m_buffer_tail + m_buffer_size) % m_buffer->size()] = ch;
|
||||
m_buffer_size++;
|
||||
|
||||
epoll_notify(EPOLLIN);
|
||||
|
||||
m_buffer_blocker.unblock();
|
||||
|
||||
return true;
|
||||
@@ -127,6 +130,8 @@ namespace Kernel
|
||||
m_buffer_size -= to_copy;
|
||||
m_buffer_tail = (m_buffer_tail + to_copy) % m_buffer->size();
|
||||
|
||||
epoll_notify(EPOLLOUT);
|
||||
|
||||
m_buffer_lock.unlock(state);
|
||||
|
||||
return to_copy;
|
||||
@@ -137,7 +142,6 @@ namespace Kernel
|
||||
auto slave = m_slave.lock();
|
||||
if (!slave)
|
||||
return BAN::Error::from_errno(ENODEV);
|
||||
|
||||
for (size_t i = 0; i < buffer.size(); i++)
|
||||
slave->handle_input_byte(buffer[i]);
|
||||
return buffer.size();
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include <string.h>
|
||||
#include <stropts.h>
|
||||
#include <sys/banan-os.h>
|
||||
#include <sys/epoll.h>
|
||||
#include <sys/sysmacros.h>
|
||||
|
||||
namespace Kernel
|
||||
@@ -40,6 +41,7 @@ namespace Kernel
|
||||
bool can_read_impl() const override { return false; }
|
||||
bool can_write_impl() const override { return false; }
|
||||
bool has_error_impl() const override { return false; }
|
||||
bool has_hangup_impl() const override { return false; }
|
||||
|
||||
private:
|
||||
DevTTY(mode_t mode, uid_t uid, gid_t gid)
|
||||
@@ -238,6 +240,7 @@ namespace Kernel
|
||||
if (ch == '\x04' && (m_termios.c_lflag & ICANON))
|
||||
{
|
||||
m_output.flush = true;
|
||||
epoll_notify(EPOLLIN);
|
||||
m_output.thread_blocker.unblock();
|
||||
return;
|
||||
}
|
||||
@@ -280,6 +283,7 @@ namespace Kernel
|
||||
if (ch == '\n' || !(m_termios.c_lflag & ICANON))
|
||||
{
|
||||
m_output.flush = true;
|
||||
epoll_notify(EPOLLIN);
|
||||
m_output.thread_blocker.unblock();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user