kernel+libluna: Add Buffer::dequeue_data()
This commit is contained in:
parent
48f5f6ea33
commit
1b596027c1
@ -49,13 +49,7 @@ Result<usize> ConsoleDevice::read(u8* buf, usize, usize length) const
|
|||||||
{
|
{
|
||||||
TRY(handle_background_process_group(false, SIGTTIN));
|
TRY(handle_background_process_group(false, SIGTTIN));
|
||||||
|
|
||||||
if (length > m_input_buffer.size()) length = m_input_buffer.size();
|
length = m_input_buffer.dequeue_data(buf, length);
|
||||||
|
|
||||||
memcpy(buf, m_input_buffer.data(), length);
|
|
||||||
|
|
||||||
memmove(m_input_buffer.data(), m_input_buffer.data() + length, m_input_buffer.size() - length);
|
|
||||||
|
|
||||||
m_input_buffer.try_resize(m_input_buffer.size() - length).release_value();
|
|
||||||
|
|
||||||
if (!length && m_may_read_without_blocking) m_may_read_without_blocking = false;
|
if (!length && m_may_read_without_blocking) m_may_read_without_blocking = false;
|
||||||
|
|
||||||
|
@ -21,6 +21,8 @@ class Buffer
|
|||||||
|
|
||||||
Result<void> append_data(const u8* data, usize size);
|
Result<void> append_data(const u8* data, usize size);
|
||||||
|
|
||||||
|
usize dequeue_data(u8* data, usize size);
|
||||||
|
|
||||||
u8* data()
|
u8* data()
|
||||||
{
|
{
|
||||||
return m_data;
|
return m_data;
|
||||||
|
@ -53,6 +53,20 @@ Result<void> Buffer::append_data(const u8* data, usize size)
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
usize Buffer::dequeue_data(u8* data, usize size)
|
||||||
|
{
|
||||||
|
if (size > m_size) size = m_size;
|
||||||
|
if (!size) return 0;
|
||||||
|
|
||||||
|
memcpy(data, m_data, size);
|
||||||
|
|
||||||
|
memmove(m_data, m_data + size, m_size - size);
|
||||||
|
|
||||||
|
m_size -= size;
|
||||||
|
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
u8* Buffer::release_data()
|
u8* Buffer::release_data()
|
||||||
{
|
{
|
||||||
u8* data = m_data;
|
u8* data = m_data;
|
||||||
|
Loading…
Reference in New Issue
Block a user