summaryrefslogtreecommitdiff
path: root/Kernel/Net/LocalSocket.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Kernel/Net/LocalSocket.cpp')
-rw-r--r--Kernel/Net/LocalSocket.cpp46
1 files changed, 24 insertions, 22 deletions
diff --git a/Kernel/Net/LocalSocket.cpp b/Kernel/Net/LocalSocket.cpp
index 1d0309eb13..135306a272 100644
--- a/Kernel/Net/LocalSocket.cpp
+++ b/Kernel/Net/LocalSocket.cpp
@@ -229,32 +229,34 @@ ssize_t LocalSocket::sendto(FileDescription& description, const void* data, size
ASSERT_NOT_REACHED();
}
-ssize_t LocalSocket::recvfrom(FileDescription& description, void* buffer, size_t buffer_size, int, sockaddr*, socklen_t*)
+DoubleBuffer& LocalSocket::buffer_for(FileDescription& description)
{
auto role = this->role(description);
- if (role == Role::Accepted) {
- if (!description.is_blocking()) {
- if (m_for_server.is_empty()) {
- if (!has_attached_peer(description))
- return 0;
- return -EAGAIN;
- }
- }
- ASSERT(!m_for_server.is_empty());
- return m_for_server.read((u8*)buffer, buffer_size);
- }
- if (role == Role::Connected) {
- if (!description.is_blocking()) {
- if (m_for_client.is_empty()) {
- if (!has_attached_peer(description))
- return 0;
- return -EAGAIN;
- }
+ if (role == Role::Accepted)
+ return m_for_server;
+ if (role == Role::Connected)
+ return m_for_client;
+ ASSERT_NOT_REACHED();
+}
+
+ssize_t LocalSocket::recvfrom(FileDescription& description, void* buffer, size_t buffer_size, int, sockaddr*, socklen_t*)
+{
+ auto& buffer_for_me = buffer_for(description);
+ if (!description.is_blocking()) {
+ if (buffer_for_me.is_empty()) {
+ if (!has_attached_peer(description))
+ return 0;
+ return -EAGAIN;
}
- ASSERT(!m_for_client.is_empty());
- return m_for_client.read((u8*)buffer, buffer_size);
+ } else if (!can_read(description)) {
+ auto result = current->block<Thread::ReceiveBlocker>(description);
+ if (result == Thread::BlockResult::InterruptedBySignal)
+ return -EINTR;
}
- ASSERT_NOT_REACHED();
+ if (!has_attached_peer(description) && buffer_for_me.is_empty())
+ return 0;
+ ASSERT(!buffer_for_me.is_empty());
+ return buffer_for_me.read((u8*)buffer, buffer_size);
}
StringView LocalSocket::socket_path() const