Skip to content

Commit

Permalink
poll: simplify poll socket handling.
Browse files Browse the repository at this point in the history
Restores exception guards
reduces duplication
simplifies code - to use existing disposition logic.
fixes unusual branch on function whitespace
removes logged warning on timeout
removes timeout handling from 'checkRemoval'
	- timeout does not imply removal; return value needs
	  re-evaluating there.
restores checkTimeout in its original location.i
	- unclear what extra 'setClosed' is good for.
also removes 'checkRemoval' from ServerSocket sub-class etc.

Signed-off-by: Michael Meeks <[email protected]>
Change-Id: Ibb582ec5b2600c7ac7cf3b6aecbee39c43b214f8
  • Loading branch information
mmeeks committed Oct 26, 2024
1 parent 1594989 commit 749f035
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 26 deletions.
26 changes: 0 additions & 26 deletions net/Socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -678,25 +678,6 @@ int SocketPoll::poll(int64_t timeoutMaxMicroS)
// removed in a callback
++itemsErased;
}
else if (!_pollSockets[i]->isOpen())
{
// closed socket ..
++itemsErased;
LOGA_TRC(Socket, '#' << _pollFds[i].fd << ": Removing socket (at " << i
<< " of " << _pollSockets.size() << ") from " << _name);
_pollSockets[i] = nullptr;
}
else if( _pollSockets[i]->checkRemoval(newNow) )
{
// timed out socket .. also checks
// ProtocolHandlerInterface
// - http::Session::checkTimeout() OK
// - WebSocketHandler::checkTimeout() OK
++itemsErased;
LOGA_TRC(Socket, '#' << _pollFds[i].fd << ": Removing socket (at " << i
<< " of " << _pollSockets.size() << ") from " << _name);
_pollSockets[i] = nullptr;
}
else if (_pollFds[i].fd == _pollSockets[i]->getFD())
{
SocketDisposition disposition(_pollSockets[i]);
Expand Down Expand Up @@ -1534,13 +1515,6 @@ bool StreamSocket::checkRemoval(std::chrono::steady_clock::time_point now)
return true;
}
}
if (_socketHandler && _socketHandler->checkTimeout(now))
{
assert(isOpen() == false); // should have issued shutdown
setClosed();
LOG_WRN("CheckRemoval: Timeout: " << getStatsString(now) << ", " << *this);
return true;
}
return false;
}

Expand Down
15 changes: 15 additions & 0 deletions net/Socket.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1449,6 +1449,21 @@ class StreamSocket : public Socket,
{
ASSERT_CORRECT_SOCKET_THREAD(this);

if (_socketHandler->checkTimeout(now))
{
assert(isOpen() == false); // should have issued shutdown
setClosed();
LOGA_DBG(Socket, "socket timeout: " << getStatsString(now) << ", " << *this);
disposition.setClosed();
return;
}

if (!isOpen() || checkRemoval(now))
{
disposition.setClosed();
return;
}

if (!events && _inBuffer.empty())
return;

Expand Down

0 comments on commit 749f035

Please sign in to comment.