mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 06:57:46 +00:00
LibCore: Implement LocalSocket::release_fd
release_fd() releases the fd associated with the LocalSocket it is called on. This is analogous to release_value() on container objects in AK, after which the object does not contain the value.
This commit is contained in:
parent
89d9a1afc0
commit
259ed04087
2 changed files with 17 additions and 0 deletions
|
@ -535,4 +535,15 @@ ErrorOr<size_t> LocalSocket::read_without_waiting(Bytes buffer)
|
||||||
return m_helper.read(buffer, MSG_DONTWAIT);
|
return m_helper.read(buffer, MSG_DONTWAIT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ErrorOr<int> LocalSocket::release_fd()
|
||||||
|
{
|
||||||
|
if (!is_open()) {
|
||||||
|
return Error::from_errno(ENOTCONN);
|
||||||
|
}
|
||||||
|
|
||||||
|
auto fd = m_helper.fd();
|
||||||
|
m_helper.set_fd(-1);
|
||||||
|
return fd;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -416,6 +416,12 @@ public:
|
||||||
ErrorOr<pid_t> peer_pid() const;
|
ErrorOr<pid_t> peer_pid() const;
|
||||||
ErrorOr<size_t> read_without_waiting(Bytes buffer);
|
ErrorOr<size_t> read_without_waiting(Bytes buffer);
|
||||||
|
|
||||||
|
/// Release the fd associated with this LocalSocket. After the fd is
|
||||||
|
/// released, the socket will be considered "closed" and all operations done
|
||||||
|
/// on it will fail with ENOTCONN. Fails with ENOTCONN if the socket is
|
||||||
|
/// already closed.
|
||||||
|
ErrorOr<int> release_fd();
|
||||||
|
|
||||||
virtual ~LocalSocket() { close(); }
|
virtual ~LocalSocket() { close(); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue