Skip to content

Commit

Permalink
Prevent deadlock
Browse files Browse the repository at this point in the history
  • Loading branch information
stephen-webb committed Jul 25, 2024
1 parent f7f8caa commit 8d3a158
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
16 changes: 10 additions & 6 deletions src/main/cpp/aprserversocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ APRServerSocket::APRServerSocket(int port) :
}
}

void APRServerSocket::close(){
void APRServerSocket::close()
{
std::lock_guard<std::mutex> lock(_priv->mutex);

if (_priv->socket != 0)
Expand All @@ -103,9 +104,12 @@ accepts it
*/
SocketPtr APRServerSocket::accept()
{
std::lock_guard<std::mutex> lock(_priv->mutex);

if (_priv->socket == 0)
apr_socket_t* s;
{
std::lock_guard<std::mutex> lock(_priv->mutex);
s = _priv->socket;
}
if (s == 0)
{
throw IOException();
}
Expand All @@ -115,7 +119,7 @@ SocketPtr APRServerSocket::accept()
poll.desc_type = APR_POLL_SOCKET;
poll.reqevents = APR_POLLIN;
poll.rtnevents = 0;
poll.desc.s = _priv->socket;
poll.desc.s = s;
poll.client_data = NULL;

apr_int32_t signaled;
Expand All @@ -140,7 +144,7 @@ SocketPtr APRServerSocket::accept()
}

apr_socket_t* newSocket;
status = apr_socket_accept(&newSocket, _priv->socket, newPool);
status = apr_socket_accept(&newSocket, s, newPool);

if (status != APR_SUCCESS)
{
Expand Down
16 changes: 8 additions & 8 deletions src/main/cpp/telnetappender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,14 @@ struct TelnetAppender::TelnetAppenderPriv : public AppenderSkeletonPrivate
if (!this->serverSocket || this->closed)
return;
this->closed = true;
// Interrupt accept()
try
{
this->serverSocket->close();
}
catch (Exception&)
{
}
}
// Interrupt accept()
try
{
this->serverSocket->close();
}
catch (Exception&)
{
}
if (this->sh.joinable())
this->sh.join();
Expand Down

0 comments on commit 8d3a158

Please sign in to comment.