mirror of
https://github.com/RGBCube/serenity
synced 2025-05-14 07:54:58 +00:00
Kernel/Net: Add a special SOCKET_TRY() and use it in socket code
Sockets remember their last error code in the SO_ERROR field, so we need to take special care to remember this when returning an error. This patch adds a SOCKET_TRY() that works like TRY() but also calls set_so_error() on the failure path. There's probably a lot more code that should be using this, but that's outside the scope of this patch.
This commit is contained in:
parent
3c44e381d4
commit
308773ffda
5 changed files with 29 additions and 46 deletions
|
@ -164,8 +164,7 @@ 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 (auto result = buffer.write(tcp_packet.payload(), payload_size); result.is_error())
|
||||
return set_so_error(result);
|
||||
SOCKET_TRY(buffer.write(tcp_packet.payload(), payload_size));
|
||||
return payload_size;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue