@@ -18,12 +18,16 @@ Result<HC_UNIQUE_PTR<WinHttpProvider>> WinHttpProvider::Initialize()
1818 RETURN_IF_FAILED (XTaskQueueCreate (XTaskQueueDispatchMode::Immediate, XTaskQueueDispatchMode::Immediate, &provider->m_immediateQueue ));
1919
2020#if HC_PLATFORM == HC_PLATFORM_GDK
21- if (! XGameRuntimeIsFeatureAvailable (XGameRuntimeFeature::XNetworking))
21+ if (XGameRuntimeIsFeatureAvailable (XGameRuntimeFeature::XNetworking))
2222 {
23- return E_HC_NO_NETWORK;
23+ RETURN_IF_FAILED (XNetworkingRegisterConnectivityHintChanged (provider->m_immediateQueue , provider.get (), WinHttpProvider::NetworkConnectivityChangedCallback, &provider->m_networkConnectivityChangedToken ));
24+ }
25+ else
26+ {
27+ // XNetworking not available (e.g., PC GDK build), assume network is ready
28+ provider->m_networkInitialized = true ;
2429 }
2530
26- RETURN_IF_FAILED (XNetworkingRegisterConnectivityHintChanged (provider->m_immediateQueue , provider.get (), WinHttpProvider::NetworkConnectivityChangedCallback, &provider->m_networkConnectivityChangedToken ));
2731 RETURN_IF_FAILED (RegisterAppStateChangeNotification (WinHttpProvider::AppStateChangedCallback, provider.get (), &provider->m_appStateChangedToken ));
2832
2933#endif // HC_PLATFORM == HC_PLATFORM_GDK
@@ -44,9 +48,12 @@ WinHttpProvider::~WinHttpProvider()
4448 UnregisterAppStateChangeNotification (m_appStateChangedToken);
4549 }
4650
47- if (m_networkConnectivityChangedToken. token )
51+ if (XGameRuntimeIsFeatureAvailable (XGameRuntimeFeature::XNetworking) )
4852 {
49- XNetworkingUnregisterConnectivityHintChanged (m_networkConnectivityChangedToken, true );
53+ if (m_networkConnectivityChangedToken.token )
54+ {
55+ XNetworkingUnregisterConnectivityHintChanged (m_networkConnectivityChangedToken, true );
56+ }
5057 }
5158#endif
5259
@@ -296,35 +303,45 @@ HRESULT WinHttpProvider::CloseAllConnections()
296303
297304Result<XPlatSecurityInformation> WinHttpProvider::GetSecurityInformation (const char * url)
298305{
306+ constexpr uint32_t defaultSecurityProtocolFlags =
307+ WINHTTP_FLAG_SECURE_PROTOCOL_TLS1 |
308+ WINHTTP_FLAG_SECURE_PROTOCOL_TLS1_1 |
309+ WINHTTP_FLAG_SECURE_PROTOCOL_TLS1_2;
310+
299311#if HC_PLATFORM == HC_PLATFORM_GDK
300- // Synchronously query SecurityInfo
301- XAsyncBlock asyncBlock{};
302- asyncBlock.queue = m_immediateQueue;
303- RETURN_IF_FAILED (XNetworkingQuerySecurityInformationForUrlAsync (url, &asyncBlock));
304- RETURN_IF_FAILED (XAsyncGetStatus (&asyncBlock, true ));
305-
306- size_t securityInformationBufferByteCount{ 0 };
307- RETURN_IF_FAILED (XNetworkingQuerySecurityInformationForUrlAsyncResultSize (&asyncBlock, &securityInformationBufferByteCount));
308- assert (securityInformationBufferByteCount > 0 );
309-
310- XPlatSecurityInformation securityInfo;
311- securityInfo.buffer .resize (securityInformationBufferByteCount);
312- RETURN_IF_FAILED (XNetworkingQuerySecurityInformationForUrlAsyncResult (
313- &asyncBlock,
314- securityInfo.buffer .size (),
315- nullptr ,
316- securityInfo.buffer .data (),
317- &securityInfo.securityInformation ));
312+ bool useXNetworking = XGameRuntimeIsFeatureAvailable (XGameRuntimeFeature::XNetworking);
313+ if (useXNetworking)
314+ {
315+ // Synchronously query SecurityInfo
316+ XAsyncBlock asyncBlock{};
317+ asyncBlock.queue = m_immediateQueue;
318+ RETURN_IF_FAILED (XNetworkingQuerySecurityInformationForUrlAsync (url, &asyncBlock));
319+ RETURN_IF_FAILED (XAsyncGetStatus (&asyncBlock, true ));
320+
321+ size_t securityInformationBufferByteCount{ 0 };
322+ RETURN_IF_FAILED (XNetworkingQuerySecurityInformationForUrlAsyncResultSize (&asyncBlock, &securityInformationBufferByteCount));
323+ assert (securityInformationBufferByteCount > 0 );
324+
325+ XPlatSecurityInformation securityInfo;
326+ securityInfo.buffer .resize (securityInformationBufferByteCount);
327+ RETURN_IF_FAILED (XNetworkingQuerySecurityInformationForUrlAsyncResult (
328+ &asyncBlock,
329+ securityInfo.buffer .size (),
330+ nullptr ,
331+ securityInfo.buffer .data (),
332+ &securityInfo.securityInformation ));
318333
319- // Duplicate security protocol flags for convenience
320- securityInfo.enabledHttpSecurityProtocolFlags = securityInfo.securityInformation ->enabledHttpSecurityProtocolFlags ;
334+ // Duplicate security protocol flags for convenience
335+ securityInfo.enabledHttpSecurityProtocolFlags = securityInfo.securityInformation ->enabledHttpSecurityProtocolFlags ;
321336
322- return std::move (securityInfo);
337+ return std::move (securityInfo);
338+ }
323339#else
324- // Use default security protocol flags independent of URL
325340 UNREFERENCED_PARAMETER (url);
326- return XPlatSecurityInformation{ WINHTTP_FLAG_SECURE_PROTOCOL_TLS1 | WINHTTP_FLAG_SECURE_PROTOCOL_TLS1_1 | WINHTTP_FLAG_SECURE_PROTOCOL_TLS1_2 };
327341#endif
342+
343+ // Fallback to default security protocol flags
344+ return XPlatSecurityInformation{ defaultSecurityProtocolFlags };
328345}
329346
330347Result<HINTERNET> WinHttpProvider::GetHSession (uint32_t securityProtocolFlags, const char * url)
@@ -626,18 +643,26 @@ void WinHttpProvider::NetworkConnectivityChangedCallback(void* context, const XN
626643 // Ignore network connectivity changes if we are suspended
627644 if (!provider->m_isSuspended )
628645 {
629- // Always requery the latest network connectivity hint rather than relying on the passed parameter in case this is a stale notification
630- XNetworkingConnectivityHint hint{};
631- HRESULT hr = XNetworkingGetConnectivityHint (&hint);
632- if (SUCCEEDED (hr))
646+ if (XGameRuntimeIsFeatureAvailable (XGameRuntimeFeature::XNetworking))
633647 {
634- HC_TRACE_INFORMATION (HTTPCLIENT, " NetworkConnectivityChangedCallback, hint.networkInitialized=%d" , hint.networkInitialized );
635- provider->m_networkInitialized = hint.networkInitialized ;
648+ // Always requery the latest network connectivity hint rather than relying on the passed parameter in case this is a stale notification
649+ XNetworkingConnectivityHint hint{};
650+ HRESULT hr = XNetworkingGetConnectivityHint (&hint);
651+ if (SUCCEEDED (hr))
652+ {
653+ HC_TRACE_INFORMATION (HTTPCLIENT, " NetworkConnectivityChangedCallback, hint.networkInitialized=%d" , hint.networkInitialized );
654+ provider->m_networkInitialized = hint.networkInitialized ;
655+ }
656+ else
657+ {
658+ HC_TRACE_ERROR (HTTPCLIENT, " Unable to get NetworkConnectivityHint, setting m_networkInitialized=false" );
659+ provider->m_networkInitialized = false ;
660+ }
636661 }
637662 else
638663 {
639- HC_TRACE_ERROR (HTTPCLIENT, " Unable to get NetworkConnectivityHint, setting m_networkInitialized=false " );
640- provider->m_networkInitialized = false ;
664+ // Fallback to default network state if XNetworking is not available
665+ provider->m_networkInitialized = true ;
641666 }
642667 }
643668}
0 commit comments