Add Unix domain sockets for local IPC #37
@ -49,13 +49,7 @@ Result<usize> ConsoleDevice::read(u8* buf, usize, usize length) const
|
||||
{
|
||||
TRY(handle_background_process_group(false, SIGTTIN));
|
||||
|
||||
if (length > m_input_buffer.size()) length = m_input_buffer.size();
|
||||
|
||||
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();
|
||||
length = m_input_buffer.dequeue_data(buf, length);
|
||||
|
||||
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);
|
||||
|
||||
usize dequeue_data(u8* data, usize size);
|
||||
|
||||
u8* data()
|
||||
{
|
||||
return m_data;
|
||||
|
@ -53,6 +53,20 @@ Result<void> Buffer::append_data(const u8* data, usize size)
|
||||
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* data = m_data;
|
||||
|
Loading…
Reference in New Issue
Block a user