This commit is contained in:
qicosmos
2025-09-23 08:36:11 +08:00
parent 5e501503fb
commit f02df7ffa4
3 changed files with 33 additions and 4 deletions
+1 -2
View File
@@ -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;
+26 -1
View File
@@ -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)