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 if (fState == CLOSING || fState == WAIT_FOR_FINISH_ACKNOWLEDGE
|| fState == TIME_WAIT) { || fState == TIME_WAIT) {
// ``Connection closing''. // ``Connection closing''.
if (fReceiveQueue.Available() > 0)
break;
return B_OK; return B_OK;
} }
@ -1345,7 +1347,8 @@ TCPEndpoint::_AvailableData() const
if (availableData == 0 && !_ShouldReceive()) if (availableData == 0 && !_ShouldReceive())
return ENOTCONN; return ENOTCONN;
if (availableData == 0 && (fState == FINISH_RECEIVED || fState == WAIT_FOR_FINISH_ACKNOWLEDGE))
return ESHUTDOWN;
return availableData; return availableData;
} }

View File

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