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.
This commit is contained in:
Augustin Cavalier
2023-11-21 23:34:59 -05:00
parent f860cfc76c
commit 93a6528df8
@@ -828,11 +828,14 @@ TCPEndpoint::SendData(net_buffer *buffer)
size_t left = buffer->size; size_t left = buffer->size;
bigtime_t timeout = absolute_timeout(socket->send.timeout); bigtime_t timeout = 0;
if (gStackModule->is_restarted_syscall()) if ((flags & MSG_DONTWAIT) == 0) {
timeout = gStackModule->restore_syscall_restart_timeout(); timeout = absolute_timeout(socket->send.timeout);
else if (gStackModule->is_restarted_syscall())
gStackModule->store_syscall_restart_timeout(timeout); timeout = gStackModule->restore_syscall_restart_timeout();
else
gStackModule->store_syscall_restart_timeout(timeout);
}
while (left > 0) { while (left > 0) {
while (fSendQueue.Free() < socket->send.low_water_mark) { while (fSendQueue.Free() < socket->send.low_water_mark) {
@@ -946,11 +949,14 @@ TCPEndpoint::ReadData(size_t numBytes, uint32 flags, net_buffer** _buffer)
return ENOTCONN; return ENOTCONN;
} }
bigtime_t timeout = absolute_timeout(socket->receive.timeout); bigtime_t timeout = 0;
if (gStackModule->is_restarted_syscall()) if ((flags & MSG_DONTWAIT) == 0) {
timeout = gStackModule->restore_syscall_restart_timeout(); timeout = absolute_timeout(socket->receive.timeout);
else if (gStackModule->is_restarted_syscall())
gStackModule->store_syscall_restart_timeout(timeout); timeout = gStackModule->restore_syscall_restart_timeout();
else
gStackModule->store_syscall_restart_timeout(timeout);
}
if (fState == SYNCHRONIZE_SENT || fState == SYNCHRONIZE_RECEIVED) { if (fState == SYNCHRONIZE_SENT || fState == SYNCHRONIZE_RECEIVED) {
if (flags & MSG_DONTWAIT) if (flags & MSG_DONTWAIT)
@@ -990,7 +996,7 @@ TCPEndpoint::ReadData(size_t numBytes, uint32 flags, net_buffer** _buffer)
return B_OK; return B_OK;
} }
if ((flags & MSG_DONTWAIT) != 0 || socket->receive.timeout == 0) if (timeout == 0)
return B_WOULD_BLOCK; return B_WOULD_BLOCK;
if ((fFlags & FLAG_NO_RECEIVE) != 0) if ((fFlags & FLAG_NO_RECEIVE) != 0)