diff options
author | Andreas Kling <kling@serenityos.org> | 2021-09-07 12:09:52 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-09-07 13:53:14 +0200 |
commit | b4811324183cc64bd671f93c889fa5e6590e0182 (patch) | |
tree | 083ec95329a20fbcf74f78ce8ea2bf3c9a4055b8 /Kernel/Net/TCPSocket.cpp | |
parent | 7bf88444993a72f588ce3bd849042c3420e222a7 (diff) | |
download | serenity-b4811324183cc64bd671f93c889fa5e6590e0182.zip |
Kernel: Make UserOrKernelBuffer return KResult from read/write/memset
This allows us to simplify a whole bunch of call sites with TRY(). :^)
Diffstat (limited to 'Kernel/Net/TCPSocket.cpp')
-rw-r--r-- | Kernel/Net/TCPSocket.cpp | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/Kernel/Net/TCPSocket.cpp b/Kernel/Net/TCPSocket.cpp index 740696ef6a..06b01cbda9 100644 --- a/Kernel/Net/TCPSocket.cpp +++ b/Kernel/Net/TCPSocket.cpp @@ -169,8 +169,8 @@ KResultOr<size_t> TCPSocket::protocol_receive(ReadonlyBytes raw_ipv4_packet, Use size_t payload_size = raw_ipv4_packet.size() - sizeof(IPv4Packet) - tcp_packet.header_size(); dbgln_if(TCP_SOCKET_DEBUG, "payload_size {}, will it fit in {}?", payload_size, buffer_size); VERIFY(buffer_size >= payload_size); - if (!buffer.write(tcp_packet.payload(), payload_size)) - return set_so_error(EFAULT); + if (auto result = buffer.write(tcp_packet.payload(), payload_size); result.is_error()) + return set_so_error(result); return payload_size; } @@ -226,9 +226,11 @@ KResult TCPSocket::send_tcp_packet(u16 flags, const UserOrKernelBuffer* payload, tcp_packet.set_ack_number(m_ack_number); } - if (payload && !payload->read(tcp_packet.payload(), payload_size)) { - routing_decision.adapter->release_packet_buffer(*packet); - return set_so_error(EFAULT); + if (payload) { + if (auto result = payload->read(tcp_packet.payload(), payload_size); result.is_error()) { + routing_decision.adapter->release_packet_buffer(*packet); + return set_so_error(result); + } } if (flags & TCPFlags::SYN) { |