diff options
author | Andreas Kling <kling@serenityos.org> | 2020-02-08 00:52:33 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-02-08 00:54:43 +0100 |
commit | 2b0b7cc5a478e0081c418118264f9fb9f34dbc8b (patch) | |
tree | 48d7201bc7dcbfdb17d2318f120c4960e065ebb6 /Kernel/Net/Socket.cpp | |
parent | a3f39fe789380ff0a577083993bbd0cda0e9e55e (diff) | |
download | serenity-2b0b7cc5a478e0081c418118264f9fb9f34dbc8b.zip |
Net: Add a basic sys$shutdown() implementation
Calling shutdown prevents further reads and/or writes on a socket.
We should do a few more things based on the type of socket, but this
initial implementation just puts the basic mechanism in place.
Work towards #428.
Diffstat (limited to 'Kernel/Net/Socket.cpp')
-rw-r--r-- | Kernel/Net/Socket.cpp | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/Kernel/Net/Socket.cpp b/Kernel/Net/Socket.cpp index 48acfe334a..6e66db59c7 100644 --- a/Kernel/Net/Socket.cpp +++ b/Kernel/Net/Socket.cpp @@ -149,10 +149,23 @@ KResult Socket::getsockopt(FileDescription&, int level, int option, void* value, ssize_t Socket::read(FileDescription& description, u8* buffer, ssize_t size) { + if (is_shut_down_for_reading()) + return 0; return recvfrom(description, buffer, size, 0, nullptr, 0); } ssize_t Socket::write(FileDescription& description, const u8* data, ssize_t size) { + if (is_shut_down_for_writing()) + return -EPIPE; return sendto(description, data, size, 0, nullptr, 0); } + +KResult Socket::shutdown(int how) +{ + if (type() == SOCK_STREAM && !is_connected()) + return KResult(-ENOTCONN); + m_shut_down_for_reading |= how & SHUT_RD; + m_shut_down_for_writing |= how & SHUT_WR; + return KSuccess; +} |