mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 22:48:11 +00:00
LibCore: Implement LocalSocket::read_without_waiting
This uses recv with MSG_DONTWAIT to disable blocking operation for a single call. LibIPC uses this to read in a non-blocking manner from an otherwise blocking socket.
This commit is contained in:
parent
f9847372f3
commit
27b49a60d0
2 changed files with 10 additions and 4 deletions
|
@ -341,15 +341,15 @@ ErrorOr<void> Socket::connect_inet(int fd, SocketAddress const& address)
|
|||
return {};
|
||||
}
|
||||
|
||||
ErrorOr<size_t> PosixSocketHelper::read(Bytes buffer)
|
||||
ErrorOr<size_t> PosixSocketHelper::read(Bytes buffer, int flags)
|
||||
{
|
||||
if (!is_open()) {
|
||||
return Error::from_errno(ENOTCONN);
|
||||
}
|
||||
|
||||
ssize_t rc = ::recv(m_fd, buffer.data(), buffer.size(), 0);
|
||||
ssize_t rc = ::recv(m_fd, buffer.data(), buffer.size(), flags);
|
||||
if (rc < 0) {
|
||||
return Error::from_errno(errno);
|
||||
return Error::from_syscall("recv", -errno);
|
||||
}
|
||||
|
||||
m_last_read_was_eof = rc == 0;
|
||||
|
@ -556,4 +556,9 @@ ErrorOr<void> LocalSocket::send_fd(int fd)
|
|||
#endif
|
||||
}
|
||||
|
||||
ErrorOr<size_t> LocalSocket::read_without_waiting(Bytes buffer)
|
||||
{
|
||||
return m_helper.read(buffer, MSG_DONTWAIT);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue