From 93a6528df8c17875b293ef14a2b0ccabed45aee2 Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Tue, 21 Nov 2023 23:34:59 -0500 Subject: [PATCH] protocols/tcp: Correct implementation of MSG_DONTWAIT. Waiting for state changes correctly checked MSG_DONTWAIT, but the overall data timeout only did in ReadData, not SendData. This corrects that and makes the implementation more consistent overall. --- .../network/protocols/tcp/TCPEndpoint.cpp | 28 +++++++++++-------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/src/add-ons/kernel/network/protocols/tcp/TCPEndpoint.cpp b/src/add-ons/kernel/network/protocols/tcp/TCPEndpoint.cpp index ae76349b7b..ad0e06753e 100644 --- a/src/add-ons/kernel/network/protocols/tcp/TCPEndpoint.cpp +++ b/src/add-ons/kernel/network/protocols/tcp/TCPEndpoint.cpp @@ -828,11 +828,14 @@ TCPEndpoint::SendData(net_buffer *buffer) size_t left = buffer->size; - bigtime_t timeout = absolute_timeout(socket->send.timeout); - if (gStackModule->is_restarted_syscall()) - timeout = gStackModule->restore_syscall_restart_timeout(); - else - gStackModule->store_syscall_restart_timeout(timeout); + bigtime_t timeout = 0; + if ((flags & MSG_DONTWAIT) == 0) { + timeout = absolute_timeout(socket->send.timeout); + if (gStackModule->is_restarted_syscall()) + timeout = gStackModule->restore_syscall_restart_timeout(); + else + gStackModule->store_syscall_restart_timeout(timeout); + } while (left > 0) { while (fSendQueue.Free() < socket->send.low_water_mark) { @@ -946,11 +949,14 @@ TCPEndpoint::ReadData(size_t numBytes, uint32 flags, net_buffer** _buffer) return ENOTCONN; } - bigtime_t timeout = absolute_timeout(socket->receive.timeout); - if (gStackModule->is_restarted_syscall()) - timeout = gStackModule->restore_syscall_restart_timeout(); - else - gStackModule->store_syscall_restart_timeout(timeout); + bigtime_t timeout = 0; + if ((flags & MSG_DONTWAIT) == 0) { + timeout = absolute_timeout(socket->receive.timeout); + if (gStackModule->is_restarted_syscall()) + timeout = gStackModule->restore_syscall_restart_timeout(); + else + gStackModule->store_syscall_restart_timeout(timeout); + } if (fState == SYNCHRONIZE_SENT || fState == SYNCHRONIZE_RECEIVED) { if (flags & MSG_DONTWAIT) @@ -990,7 +996,7 @@ TCPEndpoint::ReadData(size_t numBytes, uint32 flags, net_buffer** _buffer) return B_OK; } - if ((flags & MSG_DONTWAIT) != 0 || socket->receive.timeout == 0) + if (timeout == 0) return B_WOULD_BLOCK; if ((fFlags & FLAG_NO_RECEIVE) != 0)