summaryrefslogtreecommitdiff
path: root/Kernel
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2021-08-29 01:22:34 +0200
committerAndreas Kling <kling@serenityos.org>2021-08-29 01:25:03 +0200
commit242063866f855bf01259f8cae5d1a877fe1fc031 (patch)
tree03a5d27b702d53e5e17ea0f0a6414c062367c6a7 /Kernel
parent244ede561b3d9e0a5b3f63c9714e7bee7008c74d (diff)
downloadserenity-242063866f855bf01259f8cae5d1a877fe1fc031.zip
Kernel: Rename LocalSocket factory to try_create() & tighten return type
Also tighten the return type to KResultOr<NonnullRefPtr<LocalSocket>> since it cannot return any other socket type.
Diffstat (limited to 'Kernel')
-rw-r--r--Kernel/Net/LocalSocket.cpp6
-rw-r--r--Kernel/Net/LocalSocket.h2
-rw-r--r--Kernel/Net/Socket.cpp8
3 files changed, 10 insertions, 6 deletions
diff --git a/Kernel/Net/LocalSocket.cpp b/Kernel/Net/LocalSocket.cpp
index d62c14ad86..b783102a37 100644
--- a/Kernel/Net/LocalSocket.cpp
+++ b/Kernel/Net/LocalSocket.cpp
@@ -34,7 +34,7 @@ void LocalSocket::for_each(Function<void(const LocalSocket&)> callback)
});
}
-KResultOr<NonnullRefPtr<Socket>> LocalSocket::create(int type)
+KResultOr<NonnullRefPtr<LocalSocket>> LocalSocket::try_create(int type)
{
auto client_buffer = DoubleBuffer::try_create();
if (!client_buffer)
@@ -50,11 +50,11 @@ KResultOr<NonnullRefPtr<Socket>> LocalSocket::create(int type)
KResultOr<SocketPair> LocalSocket::create_connected_pair(int type)
{
- auto socket_or_error = LocalSocket::create(type);
+ auto socket_or_error = LocalSocket::try_create(type);
if (socket_or_error.is_error())
return socket_or_error.error();
- auto socket = static_ptr_cast<LocalSocket>(socket_or_error.release_value());
+ auto socket = socket_or_error.release_value();
auto description1_result = FileDescription::try_create(*socket);
if (description1_result.is_error())
return description1_result.error();
diff --git a/Kernel/Net/LocalSocket.h b/Kernel/Net/LocalSocket.h
index af4728c53f..7a69814897 100644
--- a/Kernel/Net/LocalSocket.h
+++ b/Kernel/Net/LocalSocket.h
@@ -22,7 +22,7 @@ struct SocketPair {
class LocalSocket final : public Socket {
public:
- static KResultOr<NonnullRefPtr<Socket>> create(int type);
+ static KResultOr<NonnullRefPtr<LocalSocket>> try_create(int type);
static KResultOr<SocketPair> create_connected_pair(int type);
virtual ~LocalSocket() override;
diff --git a/Kernel/Net/Socket.cpp b/Kernel/Net/Socket.cpp
index 3ab4f846b7..7ef57da95d 100644
--- a/Kernel/Net/Socket.cpp
+++ b/Kernel/Net/Socket.cpp
@@ -20,8 +20,12 @@ namespace Kernel {
KResultOr<NonnullRefPtr<Socket>> Socket::create(int domain, int type, int protocol)
{
switch (domain) {
- case AF_LOCAL:
- return LocalSocket::create(type & SOCK_TYPE_MASK);
+ case AF_LOCAL: {
+ auto socket_or_error = LocalSocket::try_create(type & SOCK_TYPE_MASK);
+ if (socket_or_error.is_error())
+ return socket_or_error.error();
+ return socket_or_error.release_value();
+ }
case AF_INET:
return IPv4Socket::create(type & SOCK_TYPE_MASK, protocol);
default: