/* * Copyright 2022 The Nakama Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #pragma once #include #include #include #include namespace Nakama { class NHttpClientLibHC : public NHttpTransportInterface { public: NHttpClientLibHC(const NPlatformParameters& platformParameters); ~NHttpClientLibHC() noexcept; void setBaseUri(const std::string& uri) override; void setTimeout(std::chrono::milliseconds time) override; void tick() override; void request(const NHttpRequest& req, const NHttpResponseCallback& callback = nullptr) override; void cancelAllRequests() override; private: void submit_cb(const NHttpResponseCallback& cb, int statusCode, std::string body, std::string err = "") noexcept; HRESULT prep_hc_call(const NHttpRequest& req, std::unique_ptr& call); std::unique_ptr::type, decltype(&XTaskQueueCloseHandle)> m_queue; std::string m_baseUri; std::atomic m_queue_terminated; std::chrono::milliseconds m_timeout = std::chrono::seconds(3); }; } // namespace Nakama