summaryrefslogtreecommitdiff
path: root/Kernel/Process.cpp
diff options
context:
space:
mode:
authorSergey Bugaev <bugaevc@gmail.com>2019-08-11 16:38:20 +0300
committerAndreas Kling <awesomekling@gmail.com>2019-08-11 16:30:43 +0200
commit43ce6c547486e915be117385356a8cf7746e64df (patch)
treea0ad723466276fd9ff8e46c975c84853f892d74b /Kernel/Process.cpp
parentd46c3b0b5bc196bb987d3c77855be678849e2e09 (diff)
downloadserenity-43ce6c547486e915be117385356a8cf7746e64df.zip
Kernel: Move socket role tracking to the Socket class itself
This is more logical and allows us to solve the problem of non-blocking TCP sockets getting stuck in SocketRole::None. The only complication is that a single LocalSocket may be shared between two file descriptions (on the connect and accept sides), and should have two different roles depending from which side you look at it. To deal with it, Socket::role() is made a virtual method that accepts a file description, and LocalSocket internally tracks which FileDescription is the which one and returns a correct role.
Diffstat (limited to 'Kernel/Process.cpp')
-rw-r--r--Kernel/Process.cpp20
1 files changed, 4 insertions, 16 deletions
diff --git a/Kernel/Process.cpp b/Kernel/Process.cpp
index fc9e764773..4029b235ac 100644
--- a/Kernel/Process.cpp
+++ b/Kernel/Process.cpp
@@ -2134,11 +2134,7 @@ int Process::sys$listen(int sockfd, int backlog)
if (!description->is_socket())
return -ENOTSOCK;
auto& socket = *description->socket();
- auto result = socket.listen(backlog);
- if (result.is_error())
- return result;
- description->set_socket_role(SocketRole::Listener);
- return 0;
+ return socket.listen(backlog);
}
int Process::sys$accept(int accepting_socket_fd, sockaddr* address, socklen_t* address_size)
@@ -2168,7 +2164,7 @@ int Process::sys$accept(int accepting_socket_fd, sockaddr* address, socklen_t* a
ASSERT(accepted_socket);
bool success = accepted_socket->get_peer_address(address, address_size);
ASSERT(success);
- auto accepted_socket_description = FileDescription::create(*accepted_socket, SocketRole::Accepted);
+ auto accepted_socket_description = FileDescription::create(*accepted_socket);
// NOTE: The accepted socket inherits fd flags from the accepting socket.
// I'm not sure if this matches other systems but it makes sense to me.
accepted_socket_description->set_blocking(accepting_socket_description->is_blocking());
@@ -2188,17 +2184,9 @@ int Process::sys$connect(int sockfd, const sockaddr* address, socklen_t address_
return -EBADF;
if (!description->is_socket())
return -ENOTSOCK;
- if (description->socket_role() == SocketRole::Connected)
- return -EISCONN;
+
auto& socket = *description->socket();
- description->set_socket_role(SocketRole::Connecting);
- auto result = socket.connect(*description, address, address_size, description->is_blocking() ? ShouldBlock::Yes : ShouldBlock::No);
- if (result.is_error()) {
- description->set_socket_role(SocketRole::None);
- return result;
- }
- description->set_socket_role(SocketRole::Connected);
- return 0;
+ return socket.connect(*description, address, address_size, description->is_blocking() ? ShouldBlock::Yes : ShouldBlock::No);
}
ssize_t Process::sys$sendto(const Syscall::SC_sendto_params* params)