Skip to content

Commit a701963

Browse files
authored
Fix server empty thread name (#478)
1 parent 632ee31 commit a701963

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

ixwebsocket/IXWebSocket.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ namespace ix
4141
, _enablePong(kDefaultEnablePong)
4242
, _pingIntervalSecs(kDefaultPingIntervalSecs)
4343
, _pingType(SendMessageKind::Ping)
44+
, _autoThreadName(true)
4445
{
4546
_ws.setOnCloseCallback(
4647
[this](uint16_t code, const std::string& reason, size_t wireSize, bool remote)
@@ -370,7 +371,10 @@ namespace ix
370371

371372
void WebSocket::run()
372373
{
373-
setThreadName(getUrl());
374+
if (_autoThreadName)
375+
{
376+
setThreadName(getUrl());
377+
}
374378

375379
bool firstConnectionAttempt = true;
376380

@@ -627,4 +631,9 @@ namespace ix
627631
std::lock_guard<std::mutex> lock(_configMutex);
628632
return _subProtocols;
629633
}
634+
635+
void WebSocket::setAutoThreadName(bool enabled)
636+
{
637+
_autoThreadName = enabled;
638+
}
630639
} // namespace ix

ixwebsocket/IXWebSocket.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ namespace ix
119119
uint32_t getMinWaitBetweenReconnectionRetries() const;
120120
const std::vector<std::string>& getSubProtocols();
121121

122+
void setAutoThreadName(bool enabled);
123+
122124
private:
123125
WebSocketSendInfo sendMessage(const IXWebSocketSendData& message,
124126
SendMessageKind sendMessageKind,
@@ -182,6 +184,9 @@ namespace ix
182184
// Subprotocols
183185
std::vector<std::string> _subProtocols;
184186

187+
// enable or disable auto set thread name
188+
bool _autoThreadName;
189+
185190
friend class WebSocketServer;
186191
};
187192
} // namespace ix

ixwebsocket/IXWebSocketServer.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ namespace ix
9191
setThreadName("Srv:ws:" + connectionState->getId());
9292

9393
auto webSocket = std::make_shared<WebSocket>();
94+
95+
webSocket->setAutoThreadName(false);
96+
9497
if (_onConnectionCallback)
9598
{
9699
_onConnectionCallback(webSocket, connectionState);

0 commit comments

Comments
 (0)