diff --git a/server/wsproxy/mastermgr.cc b/server/wsproxy/mastermgr.cc index 2c333be..1fa12f8 100644 --- a/server/wsproxy/mastermgr.cc +++ b/server/wsproxy/mastermgr.cc @@ -18,6 +18,14 @@ #include "downstreammgr.h" #include "GCListener.h" +struct HttpTunnelRequest +{ + int socket_handle = 0; + long long context_id = 0; + std::shared_ptr request; +}; + + class RequestTarget { public: @@ -234,18 +242,26 @@ std::shared_ptr MasterMgr::GetRequestByContextId(long long contex void MasterMgr::AddHttpTunnelRequest(int socket_handle, std::shared_ptr request) { - pending_http_tunnel_socket_hash_[socket_handle] = request; + ++curr_context_id_; + auto req = std::make_shared(); + req->socket_handle = socket_handle; + req->context_id = curr_context_id_; + req->request = request; + + pending_http_tunnel_socket_hash_[socket_handle] = req; + pending_http_tunnel_context_hash_[curr_context_id_] = req; } void MasterMgr::RemoveHttpTunnelRequest(int socket_handle) { auto req = GetHttpTunnelRequest(socket_handle); if (req) { - pending_http_tunnel_socket_hash_.end(); + pending_http_tunnel_socket_hash_.erase(req->socket_handle); + pending_http_tunnel_context_hash_.erase(req->context_id); } } -std::shared_ptr MasterMgr::GetHttpTunnelRequest(int socket_handle) +std::shared_ptr MasterMgr::GetHttpTunnelRequest(int socket_handle) { auto itr = pending_http_tunnel_socket_hash_.find(socket_handle); return itr != pending_http_tunnel_socket_hash_.end() ? itr->second : nullptr; diff --git a/server/wsproxy/mastermgr.h b/server/wsproxy/mastermgr.h index 87fe77c..4a61653 100644 --- a/server/wsproxy/mastermgr.h +++ b/server/wsproxy/mastermgr.h @@ -11,6 +11,7 @@ namespace ss class SS_MS_HttpTunnelResponse; } +struct HttpTunnelRequest; class RequestTarget; class Master; class MasterMgr : public a8::Singleton @@ -40,7 +41,7 @@ class MasterMgr : public a8::Singleton void AddHttpTunnelRequest(int socket_handle, std::shared_ptr request); private: - std::shared_ptr GetHttpTunnelRequest(int socket_handle); + std::shared_ptr GetHttpTunnelRequest(int socket_handle); std::shared_ptr GetRequestBySocket(int socket_handle); std::shared_ptr GetRequestByContextId(long long context_id); std::shared_ptr GetConnById(int instance_id); @@ -53,5 +54,6 @@ class MasterMgr : public a8::Singleton std::map> pending_socket_hash_; std::map> pending_context_hash_; - std::map> pending_http_tunnel_socket_hash_; + std::map> pending_http_tunnel_socket_hash_; + std::map> pending_http_tunnel_context_hash_; };