summaryrefslogtreecommitdiff
path: root/Kernel/Net/TCPSocket.cpp
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2021-01-20 23:11:17 +0100
committerAndreas Kling <kling@serenityos.org>2021-01-20 23:20:02 +0100
commit19d3f8cab77a95b284e30f142521c6b483221324 (patch)
tree8df3f585e91113215b52d10a9a0032c9998dc1b5 /Kernel/Net/TCPSocket.cpp
parente279b45aed5509efc537fc8c831f40733d7b1028 (diff)
downloadserenity-19d3f8cab77a95b284e30f142521c6b483221324.zip
Kernel+LibC: Turn errno codes into a strongly typed enum
..and allow implicit creation of KResult and KResultOr from ErrnoCode. This means that kernel functions that return those types can finally do "return EINVAL;" and it will just work. There's a handful of functions that still deal with signed integers that should be converted to return KResults.
Diffstat (limited to 'Kernel/Net/TCPSocket.cpp')
-rw-r--r--Kernel/Net/TCPSocket.cpp18
1 files changed, 9 insertions, 9 deletions
diff --git a/Kernel/Net/TCPSocket.cpp b/Kernel/Net/TCPSocket.cpp
index 638602b8e6..08bda1251f 100644
--- a/Kernel/Net/TCPSocket.cpp
+++ b/Kernel/Net/TCPSocket.cpp
@@ -177,7 +177,7 @@ KResultOr<size_t> TCPSocket::protocol_receive(ReadonlyBytes raw_ipv4_packet, Use
#endif
ASSERT(buffer_size >= payload_size);
if (!buffer.write(tcp_packet.payload(), payload_size))
- return KResult(-EFAULT);
+ return EFAULT;
return payload_size;
}
@@ -185,7 +185,7 @@ KResultOr<size_t> TCPSocket::protocol_send(const UserOrKernelBuffer& data, size_
{
int err = send_tcp_packet(TCPFlags::PUSH | TCPFlags::ACK, &data, data_length);
if (err < 0)
- return KResult(err);
+ return KResult((ErrnoCode)-err);
return data_length;
}
@@ -354,7 +354,7 @@ KResult TCPSocket::protocol_bind()
if (has_specific_local_address() && !m_adapter) {
m_adapter = NetworkAdapter::from_ipv4_address(local_address());
if (!m_adapter)
- return KResult(-EADDRNOTAVAIL);
+ return EADDRNOTAVAIL;
}
return KSuccess;
@@ -364,7 +364,7 @@ KResult TCPSocket::protocol_listen()
{
LOCKER(sockets_by_tuple().lock());
if (sockets_by_tuple().resource().contains(tuple()))
- return KResult(-EADDRINUSE);
+ return EADDRINUSE;
sockets_by_tuple().resource().set(tuple(), this);
set_direction(Direction::Passive);
set_state(State::Listen);
@@ -378,7 +378,7 @@ KResult TCPSocket::protocol_connect(FileDescription& description, ShouldBlock sh
auto routing_decision = route_to(peer_address(), local_address());
if (routing_decision.is_zero())
- return KResult(-EHOSTUNREACH);
+ return EHOSTUNREACH;
if (!has_specific_local_address())
set_local_address(routing_decision.adapter->ipv4_address());
@@ -390,7 +390,7 @@ KResult TCPSocket::protocol_connect(FileDescription& description, ShouldBlock sh
set_setup_state(SetupState::InProgress);
int err = send_tcp_packet(TCPFlags::SYN);
if (err < 0)
- return KResult(err);
+ return KResult((ErrnoCode)-err);
m_state = State::SynSent;
m_role = Role::Connecting;
m_direction = Direction::Outgoing;
@@ -401,17 +401,17 @@ KResult TCPSocket::protocol_connect(FileDescription& description, ShouldBlock sh
locker.unlock();
auto unblock_flags = Thread::FileBlocker::BlockFlags::None;
if (Thread::current()->block<Thread::ConnectBlocker>({}, description, unblock_flags).was_interrupted())
- return KResult(-EINTR);
+ return EINTR;
locker.lock();
ASSERT(setup_state() == SetupState::Completed);
if (has_error()) { // TODO: check unblock_flags
m_role = Role::None;
- return KResult(-ECONNREFUSED);
+ return ECONNREFUSED;
}
return KSuccess;
}
- return KResult(-EINPROGRESS);
+ return EINPROGRESS;
}
int TCPSocket::protocol_allocate_local_port()