Skip to content

Commit

Permalink
enh: check if WebSocket is still active when stopping
Browse files Browse the repository at this point in the history
  • Loading branch information
obiltschnig committed Nov 20, 2024
1 parent f932e46 commit 6721b55
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions WebTunnel/src/RemotePortForwarder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,20 +91,23 @@ void RemotePortForwarder::stop()
{
const Poco::Timestamp::TimeDiff STOP_TIMEOUT = 500000;

_dispatcher.queueTask(
[pSelf=this](SocketDispatcher& dispatcher)
if (_dispatcher.hasSocket(*_pWebSocket))
{
_dispatcher.queueTask(
[pSelf=this](SocketDispatcher& dispatcher)
{
pSelf->closeWebSocket(RPF_CLOSE_GRACEFUL, true);
}
);

_logger.debug("Waiting for WebSocket closing handshake to complete..."s);
Poco::Timestamp closeTime;
while (_dispatcher.hasSocket(*_pWebSocket) && !closeTime.isElapsed(STOP_TIMEOUT))
{
pSelf->closeWebSocket(RPF_CLOSE_GRACEFUL, true);
Poco::Thread::sleep(20);
}
);

_logger.debug("Waiting for WebSocket closing handshake to complete..."s);
Poco::Timestamp closeTime;
while (_dispatcher.hasSocket(*_pWebSocket) && !closeTime.isElapsed(STOP_TIMEOUT))
{
Poco::Thread::sleep(20);
_dispatcher.removeSocket(*_pWebSocket);
}
_dispatcher.removeSocket(*_pWebSocket);
}


Expand Down

0 comments on commit 6721b55

Please sign in to comment.