Skip to content

Commit ea05d34

Browse files
committed
Address PR feedback: lock ordering, translate_ec comment, type-erasure assert
1. SetOptions: move HasBinaryMessageFragmentHandlers() before m_stateMutex acquisition to eliminate latent m_stateMutex -> m_eventCallbacksMutex nesting hazard. 2. wintls_socket translate_ec: add comment explaining that wintls::error_code resolves to the lib::error_code identity overload (same type via WINTLS_USE_STANDALONE_ASIO), so TLS errors propagate correctly. 3. websocketpp_client_base::impl<T>(): add debug-only type tag (typeid hash) set at construction and asserted on access, catching config-type dispatch mismatches at zero release cost.
1 parent 7dad3d9 commit ea05d34

3 files changed

Lines changed: 22 additions & 1 deletion

File tree

Source/WebSocket/Websocketpp/websocketpp_websocket.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1790,17 +1790,27 @@ struct wspp_websocket_impl : public hc_websocket_impl, public std::enable_shared
17901790
template <typename WebsocketConfig>
17911791
websocketpp::client<WebsocketConfig>& impl()
17921792
{
1793+
ASSERT(m_typeTag == typeid(websocketpp::client<WebsocketConfig>).hash_code()
1794+
&& "Config type mismatch in wspp client type erasure");
17931795
return *reinterpret_cast<websocketpp::client<WebsocketConfig>*>(client_storage());
17941796
}
17951797

17961798
virtual void* client_storage() noexcept = 0;
17971799
virtual bool is_tls_client() const = 0;
17981800
virtual bool uses_compression() const = 0;
1801+
1802+
protected:
1803+
size_t m_typeTag{ 0 };
17991804
};
18001805

18011806
template<typename WebsocketConfig, bool IsTlsClient, bool UsesCompression>
18021807
struct websocketpp_client_impl : websocketpp_client_base
18031808
{
1809+
websocketpp_client_impl()
1810+
{
1811+
m_typeTag = typeid(websocketpp::client<WebsocketConfig>).hash_code();
1812+
}
1813+
18041814
void* client_storage() noexcept override
18051815
{
18061816
return &m_client;

Source/WebSocket/Websocketpp/wintls_socket.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,12 @@ class connection : public lib::enable_shared_from_this<connection> {
215215
}
216216

217217
public:
218+
// Overload resolution note: wintls::error_code is a typedef for std::error_code
219+
// (via WINTLS_USE_STANDALONE_ASIO), which is the same type as lib::error_code.
220+
// TLS handshake failures therefore resolve to the identity overload below, preserving
221+
// the original SECURITY_STATUS value in system_category through to HResultFromConnectError.
222+
// The generic template only fires for non-std::error_code types (e.g. boost error codes
223+
// in non-standalone configurations).
218224
template <typename ErrorCodeType>
219225
static lib::error_code translate_ec(ErrorCodeType)
220226
{

Source/WebSocket/hcwebsocket.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,11 @@ HRESULT WebSocket::SetOptions(HCWebSocketOptions options) noexcept
550550
E_INVALIDARG,
551551
HasNoContextTakeoverWebSocketOptions(options) && !RequestsWebSocketCompression(options));
552552

553+
// Check fragment handlers before acquiring m_stateMutex to avoid nesting
554+
// m_stateMutex -> m_eventCallbacksMutex (which HasBinaryMessageFragmentHandlers acquires).
555+
// Safe because SetOptions is only valid in State::Initial, before callbacks can fire.
556+
bool const hasBinaryFragmentHandlers = HasBinaryMessageFragmentHandlers();
557+
553558
std::lock_guard<DefaultUnnamedMutex> lock{ m_stateMutex };
554559
RETURN_HR_IF(E_HC_CONNECT_ALREADY_CALLED, m_state != State::Initial);
555560
if (RequestsLegacyWebSocketSemantics(options))
@@ -559,7 +564,7 @@ HRESULT WebSocket::SetOptions(HCWebSocketOptions options) noexcept
559564
return S_OK;
560565
}
561566

562-
RETURN_HR_IF(E_NOT_SUPPORTED, HasBinaryMessageFragmentHandlers());
567+
RETURN_HR_IF(E_NOT_SUPPORTED, hasBinaryFragmentHandlers);
563568

564569
HRESULT hr = m_provider.OptionsResult(options);
565570
RETURN_IF_FAILED(hr);

0 commit comments

Comments
 (0)