mirror of
https://gitlab.com/sortix/sortix.git
synced 2023-02-13 20:55:38 -05:00
Add poll support to log terminal.
This commit is contained in:
parent
b2b55bc34a
commit
51da410dea
2 changed files with 33 additions and 0 deletions
|
@ -29,11 +29,15 @@
|
|||
#include <sortix/kernel/ioctx.h>
|
||||
#include <sortix/kernel/inode.h>
|
||||
#include <sortix/kernel/keyboard.h>
|
||||
#include <sortix/kernel/poll.h>
|
||||
|
||||
#include <sortix/termmode.h>
|
||||
#include <sortix/termios.h>
|
||||
#include <sortix/keycodes.h>
|
||||
#include <sortix/signal.h>
|
||||
#include <sortix/stat.h>
|
||||
#include <sortix/poll.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include "utf8.h"
|
||||
|
@ -155,6 +159,7 @@ void LogTerminal::ProcessKeystroke(int kbkey)
|
|||
numeofs++;
|
||||
if ( numwaiting )
|
||||
kthread_cond_broadcast(&datacond);
|
||||
poll_channel.Signal(POLLIN | POLLRDNORM);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
@ -219,6 +224,7 @@ void LogTerminal::CommitLineBuffer()
|
|||
linebuffer.Commit();
|
||||
if ( numwaiting )
|
||||
kthread_cond_broadcast(&datacond);
|
||||
poll_channel.Signal(POLLIN | POLLRDNORM);
|
||||
}
|
||||
|
||||
ssize_t LogTerminal::read(ioctx_t* ctx, uint8_t* userbuf, size_t count)
|
||||
|
@ -313,4 +319,27 @@ ssize_t LogTerminal::write(ioctx_t* ctx, const uint8_t* buf, size_t count)
|
|||
return count;
|
||||
}
|
||||
|
||||
short LogTerminal::PollEventStatus()
|
||||
{
|
||||
short status = 0;
|
||||
if ( linebuffer.CanPop() || numeofs )
|
||||
status |= POLLIN | POLLRDNORM;
|
||||
if ( true /* can always write */ )
|
||||
status |= POLLOUT | POLLWRNORM;
|
||||
return status;
|
||||
}
|
||||
|
||||
int LogTerminal::poll(ioctx_t* /*ctx*/, PollNode* node)
|
||||
{
|
||||
ScopedLockSignal lock(&termlock);
|
||||
short ret_status = PollEventStatus() & node->events;
|
||||
if ( ret_status )
|
||||
{
|
||||
node->revents |= ret_status;
|
||||
return 0;
|
||||
}
|
||||
poll_channel.Register(node);
|
||||
return errno = EAGAIN, -1;
|
||||
}
|
||||
|
||||
} // namespace Sortix
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
#include <sortix/kernel/kthread.h>
|
||||
#include <sortix/kernel/inode.h>
|
||||
#include <sortix/kernel/keyboard.h>
|
||||
#include <sortix/kernel/poll.h>
|
||||
#include "linebuffer.h"
|
||||
|
||||
namespace Sortix {
|
||||
|
@ -46,6 +47,7 @@ public:
|
|||
virtual int tcgetwinsize(ioctx_t* ctx, struct winsize* ws);
|
||||
virtual int settermmode(ioctx_t* ctx, unsigned termmode);
|
||||
virtual int gettermmode(ioctx_t* ctx, unsigned* termmode);
|
||||
virtual int poll(ioctx_t* ctx, PollNode* node);
|
||||
|
||||
public:
|
||||
virtual void OnKeystroke(Keyboard* keyboard, void* user);
|
||||
|
@ -54,8 +56,10 @@ private:
|
|||
void ProcessKeystroke(int kbkey);
|
||||
void QueueUnicode(uint32_t unicode);
|
||||
void CommitLineBuffer();
|
||||
short PollEventStatus();
|
||||
|
||||
private:
|
||||
PollChannel poll_channel;
|
||||
mutable kthread_mutex_t termlock;
|
||||
kthread_cond_t datacond;
|
||||
size_t numwaiting;
|
||||
|
|
Loading…
Reference in a new issue