载入中...
搜索中...
未找到
HttpRuntime.h
浏览该文件的文档.
1#pragma once
2
3#include <Poco/Crypto/OpenSSLInitializer.h>
4#include <future>
5#include <map>
6#include <mutex>
7#include <unordered_map>
8#include "network/NetTypes.h"
9
10namespace eve::network {
11
12// Module-private HTTP executor. Jobs own request snapshots, never their handles
13// or Network. Registry cookies distinguish successive lifetimes at one address.
14struct HttpPolicy {
15 int timeoutMs = 10000;
16 bool verifySsl = true;
17 std::string caLocation;
18};
19
21 std::string method;
22 std::string url;
23 std::map<std::string, std::string> headers;
24 std::shared_ptr<std::vector<char>> body;
26};
27
28struct HttpOrigin;
29
30struct HttpResult {
32 size_t sentBytes = 0;
33
34private:
35 friend class HttpRuntime;
36 std::shared_ptr<HttpOrigin> origin_;
37};
38
40public:
42 enum class PollStatus { Pending, Ready, Closed };
43 enum class DeliveryStatus { Ready, Retired };
44
46 HttpRuntime() = default;
50 HttpPolicy policy() const;
52 void setTimeout(int ms);
54 int timeout() const;
56 void setVerifySsl(bool verify);
58 bool getVerifySsl() const;
60 void setCaLocation(std::string location);
62 bool isClosed() const;
68 [[nodiscard]] SubmitStatus submit(void* origin, HttpOptions options);
72 [[nodiscard]] PollStatus take(void* origin, HttpResult& result);
76 void drain(std::vector<HttpResult>& out);
82 void cancel(void* origin);
86 void close();
87
88private:
89 struct Job {
90 std::shared_ptr<HttpOrigin> lifetime;
91 std::future<HttpResult> future;
92 };
93
94 // Initialize on construction before starting concurrent Context users.
95 // Unlike uninitializeSSL(), this does not shut down the process SSLManager.
96 Poco::Crypto::OpenSSLInitializer ssl_;
97 mutable std::mutex mu_;
98 HttpPolicy policy_;
99 bool closed_ = false;
100 std::unordered_map<std::uintptr_t, std::shared_ptr<HttpOrigin>> origins_;
101 std::vector<Job> jobs_;
102};
103
104} // namespace eve::network
std::weak_ptr< const void > lifetime
std::future< JobOutput > future
Poco::JSON::Object::Ptr result
glm::dvec3 origin
ScriptStructure out
const SquirrelValueOptions & options
bool getVerifySsl() const
Returns default certificate verification.
void close()
Cancels all origins, then joins jobs without holding the registry lock. @cost Waits for in-flight I/O...
void setVerifySsl(bool verify)
Changes default certificate verification for subsequent jobs.
HttpPolicy policy() const
Copies the authoritative policy for one submission.
int timeout() const
Returns the default I/O timeout.
~HttpRuntime()
Joins remaining jobs after canceling undelivered results.
void cancel(void *origin)
Retires all jobs for the borrowed origin without blocking its destructor. @ownership Origin is identi...
void drain(std::vector< HttpResult > &out)
Transfers ready, still-live results without invoking callbacks. @cost Scans pending requests once per...
SubmitStatus submit(void *origin, HttpOptions options)
Starts an owning snapshot without retaining the handle. @ownership Origin is borrowed identity,...
void setTimeout(int ms)
Changes the default I/O timeout.
void setCaLocation(std::string location)
Owns a custom CA path for subsequent jobs.
PollStatus take(void *origin, HttpResult &result)
Takes only this origin's next ready result. @ownership Origin is a borrowed identity; result transfer...
DeliveryStatus prepareDelivery(HttpResult &result)
Rechecks lifetime immediately before queuing an event, after any reentrant callbacks.
HttpRuntime()=default
Initializes the module-owned executor and SSL lifetime.
bool isClosed() const
Reports whether the owning module has shut down.
std::shared_ptr< std::vector< char > > body
Definition HttpRuntime.h:24
std::map< std::string, std::string > headers
Definition HttpRuntime.h:23
NetCompletion completion
Definition HttpRuntime.h:31
One asynchronous network result/event. handle points at the originating TcpSocket/UdpSocket/HttpReque...
Definition NetTypes.h:33