tcp: report disconnected events for tcp

* FIONREAD shouldn't report errors, only EINVAL when listening
* read available data in closing and closing-wait states
* fix #18327

Change-Id: Idd53a043a72ef6c7b282ea669895ff2e947adbb4
Reviewed-on: https://review.haiku-os.org/c/haiku/+/6420
Reviewed-by: waddlesplash <waddlesplash@gmail.com>
This commit is contained in:
Jérôme Duval 2023-05-06 15:17:01 +02:00 committed by waddlesplash
parent 30d2a5e189
commit 9c1af36c30
2 changed files with 6 additions and 3 deletions

View File

@ -964,6 +964,8 @@ TCPEndpoint::ReadData(size_t numBytes, uint32 flags, net_buffer** _buffer)
if (fState == CLOSING || fState == WAIT_FOR_FINISH_ACKNOWLEDGE
|| fState == TIME_WAIT) {
// ``Connection closing''.
if (fReceiveQueue.Available() > 0)
break;
return B_OK;
}
@ -1345,7 +1347,8 @@ TCPEndpoint::_AvailableData() const
if (availableData == 0 && !_ShouldReceive())
return ENOTCONN;
if (availableData == 0 && (fState == FINISH_RECEIVED || fState == WAIT_FOR_FINISH_ACKNOWLEDGE))
return ESHUTDOWN;
return availableData;
}

View File

@ -540,12 +540,12 @@ socket_control(net_socket* socket, uint32 op, void* data, size_t length)
case FIONREAD:
{
if (data == NULL)
if (data == NULL || (socket->options & SO_ACCEPTCONN) != 0)
return B_BAD_VALUE;
int available = (int)socket_read_avail(socket);
if (available < 0)
return available;
available = 0;
if (is_syscall()) {
if (!IS_USER_ADDRESS(data)