Skip to content

Commit ab02171

Browse files
authored
Change to use WinHTTP when on GDK PC builds (#900)
* Making XCurl be delay-loaded * PR feedback * PR feedback * Change to use WinHTTP when on GDK PC builds
1 parent 9a4372b commit ab02171

1 file changed

Lines changed: 57 additions & 9 deletions

File tree

Source/Platform/GDK/PlatformComponents_GDK.cpp

Lines changed: 57 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,80 @@
33
#include "HTTP/Curl/CurlProvider.h"
44
#include "HTTP/WinHttp/winhttp_provider.h"
55

6+
#if HC_PLATFORM == HC_PLATFORM_GDK
7+
#include "XSystem.h"
8+
#endif
9+
610
NAMESPACE_XBOX_HTTP_CLIENT_BEGIN
711

12+
// Helper function to detect if running on Xbox console hardware
13+
static bool IsRunningOnXboxConsole()
14+
{
15+
#if HC_PLATFORM == HC_PLATFORM_GDK
16+
auto deviceType = XSystemGetDeviceType();
17+
// Explicitly list all Xbox console device types
18+
return deviceType == XSystemDeviceType::XboxOne ||
19+
deviceType == XSystemDeviceType::XboxOneS ||
20+
deviceType == XSystemDeviceType::XboxOneX ||
21+
deviceType == XSystemDeviceType::XboxScarlettLockhart || // Xbox Series S
22+
deviceType == XSystemDeviceType::XboxScarlettAnaconda; // Xbox Series X
23+
#else
24+
return false;
25+
#endif
26+
}
27+
828
HRESULT PlatformInitialize(PlatformComponents& components, HCInitArgs* initArgs)
929
{
1030
// We don't expect initArgs on GDK
1131
RETURN_HR_IF(E_INVALIDARG, initArgs);
1232

13-
// XCurl will be used for HTTP
14-
auto initXCurlResult = CurlProvider::Initialize();
15-
RETURN_IF_FAILED(initXCurlResult.hr);
33+
// Detect runtime platform to choose appropriate HTTP provider
34+
if (IsRunningOnXboxConsole())
35+
{
36+
HC_TRACE_INFORMATION(HTTPCLIENT, "PlatformInitialize: Detected Xbox console, using XCurl for HTTP");
37+
38+
// Use XCurl for Xbox console with full PLM support
39+
auto initXCurlResult = CurlProvider::Initialize();
40+
RETURN_IF_FAILED(initXCurlResult.hr);
1641

17-
components.HttpProvider = initXCurlResult.ExtractPayload();
42+
components.HttpProvider = initXCurlResult.ExtractPayload();
1843

1944
#ifndef HC_NOWEBSOCKETS
20-
// WinHttp will be used for WebSockets
21-
auto initWinHttpResult = WinHttpProvider::Initialize();
22-
RETURN_IF_FAILED(initWinHttpResult.hr);
45+
// For Xbox consoles with XCurl HTTP, still use WinHttp for WebSockets
46+
auto initWinHttpResult = WinHttpProvider::Initialize();
47+
RETURN_IF_FAILED(initWinHttpResult.hr);
2348

24-
auto winHttpProvider = initWinHttpResult.ExtractPayload();
25-
components.WebSocketProvider = http_allocate_unique<WinHttp_WebSocketProvider>(SharedPtr<WinHttpProvider>{ winHttpProvider.release(), std::move(winHttpProvider.get_deleter()), http_stl_allocator<WinHttpProvider>{} });
49+
auto winHttpProvider = initWinHttpResult.ExtractPayload();
50+
components.WebSocketProvider = http_allocate_unique<WinHttp_WebSocketProvider>(SharedPtr<WinHttpProvider>{ winHttpProvider.release(), std::move(winHttpProvider.get_deleter()), http_stl_allocator<WinHttpProvider>{} });
51+
#endif
52+
}
53+
else
54+
{
55+
HC_TRACE_INFORMATION(HTTPCLIENT, "PlatformInitialize: Detected non-console platform (e.g., Steam Deck), using WinHTTP for HTTP");
56+
57+
// Use WinHTTP for Steam Deck and other non-console platforms
58+
auto initWinHttpResult = WinHttpProvider::Initialize();
59+
RETURN_IF_FAILED(initWinHttpResult.hr);
60+
61+
auto winHttpProvider = initWinHttpResult.ExtractPayload();
62+
63+
// Use the same WinHttpProvider instance for both HTTP and WebSocket
64+
auto sharedWinHttpProvider = SharedPtr<WinHttpProvider>{ winHttpProvider.release(), std::move(winHttpProvider.get_deleter()), http_stl_allocator<WinHttpProvider>{} };
65+
66+
components.HttpProvider = http_allocate_unique<WinHttp_HttpProvider>(sharedWinHttpProvider);
67+
68+
#ifndef HC_NOWEBSOCKETS
69+
components.WebSocketProvider = http_allocate_unique<WinHttp_WebSocketProvider>(sharedWinHttpProvider);
2670
#endif
71+
}
2772

2873
return S_OK;
2974
}
3075

3176
// Test hooks for GDK Suspend/Resume testing
77+
// Note: These hooks assume WinHttp WebSocket provider is available.
78+
// They will work correctly on both Xbox consoles and non-console platforms
79+
// since both configurations use WinHttp for WebSockets.
3280
STDAPI_(void) HCWinHttpSuspend()
3381
{
3482
auto httpSingleton = get_http_singleton();

0 commit comments

Comments
 (0)