mirror of
https://github.com/qicosmos/rest_rpc.git
synced 2026-08-29 08:34:47 +08:00
context
This commit is contained in:
@@ -4,8 +4,6 @@
|
||||
#include <winsock2.h>
|
||||
#else
|
||||
#include <arpa/inet.h>
|
||||
#endif
|
||||
|
||||
inline uint64_t htonll(uint64_t value) {
|
||||
return ((uint64_t)htonl(value & 0xFFFFFFFF) << 32) | htonl(value >> 32);
|
||||
}
|
||||
@@ -13,6 +11,7 @@ inline uint64_t htonll(uint64_t value) {
|
||||
inline uint64_t ntohll(uint64_t value) {
|
||||
return ((uint64_t)ntohl(value & 0xFFFFFFFF) << 32) | ntohl(value >> 32);
|
||||
}
|
||||
#endif
|
||||
|
||||
namespace rest_rpc {
|
||||
inline constexpr uint8_t REST_MAGIC_NUM = 39;
|
||||
|
||||
@@ -6,7 +6,32 @@
|
||||
#include "use_asio.hpp"
|
||||
|
||||
namespace rest_rpc {
|
||||
class rpc_connection {
|
||||
class rpc_connection;
|
||||
|
||||
class rpc_context {
|
||||
public:
|
||||
static auto &context() {
|
||||
thread_local rpc_context instance;
|
||||
delay_ = true;
|
||||
return instance;
|
||||
}
|
||||
|
||||
void set_connection(std::shared_ptr<rpc_connection> conn) { weak_ = conn; }
|
||||
|
||||
auto get_connection() { return weak_; }
|
||||
|
||||
static bool delay() { return delay_; }
|
||||
|
||||
static bool set_delay(bool r) { delay_ = r; }
|
||||
|
||||
template <typename T> void response(T &&t) {}
|
||||
|
||||
private:
|
||||
std::weak_ptr<rpc_connection> weak_;
|
||||
inline static bool delay_ = false;
|
||||
};
|
||||
|
||||
class rpc_connection : public std::enable_shared_from_this<rpc_connection> {
|
||||
public:
|
||||
rpc_connection(tcp_socket socket, uint64_t conn_id, rpc_router &router,
|
||||
bool &cross_ending)
|
||||
|
||||
Reference in New Issue
Block a user