Skip to content

Commit

Permalink
Fix server empty thread name
Browse files Browse the repository at this point in the history
  • Loading branch information
lanthora committed Aug 2, 2023
1 parent 632ee31 commit 8f0b329
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
11 changes: 10 additions & 1 deletion ixwebsocket/IXWebSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ namespace ix
, _enablePong(kDefaultEnablePong)
, _pingIntervalSecs(kDefaultPingIntervalSecs)
, _pingType(SendMessageKind::Ping)
, _autoThreadName(true)
{
_ws.setOnCloseCallback(
[this](uint16_t code, const std::string& reason, size_t wireSize, bool remote)
Expand Down Expand Up @@ -370,7 +371,10 @@ namespace ix

void WebSocket::run()
{
setThreadName(getUrl());
if (_autoThreadName)
{
setThreadName(getUrl());
}

bool firstConnectionAttempt = true;

Expand Down Expand Up @@ -627,4 +631,9 @@ namespace ix
std::lock_guard<std::mutex> lock(_configMutex);
return _subProtocols;
}

void WebSocket::setAutoThreadName(bool enabled)
{
_autoThreadName = enabled;
}
} // namespace ix
5 changes: 5 additions & 0 deletions ixwebsocket/IXWebSocket.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ namespace ix
uint32_t getMinWaitBetweenReconnectionRetries() const;
const std::vector<std::string>& getSubProtocols();

void setAutoThreadName(bool enabled);

private:
WebSocketSendInfo sendMessage(const IXWebSocketSendData& message,
SendMessageKind sendMessageKind,
Expand Down Expand Up @@ -182,6 +184,9 @@ namespace ix
// Subprotocols
std::vector<std::string> _subProtocols;

// enable or disable auto set thread name
bool _autoThreadName;

friend class WebSocketServer;
};
} // namespace ix
3 changes: 3 additions & 0 deletions ixwebsocket/IXWebSocketServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ namespace ix
setThreadName("Srv:ws:" + connectionState->getId());

auto webSocket = std::make_shared<WebSocket>();

webSocket->setAutoThreadName(false);

if (_onConnectionCallback)
{
_onConnectionCallback(webSocket, connectionState);
Expand Down

0 comments on commit 8f0b329

Please sign in to comment.