修复释放问题
This commit is contained in:
@@ -47,6 +47,7 @@ namespace ylib
|
||||
cdn();
|
||||
~cdn();
|
||||
bool start(const cdn_config& config);
|
||||
void close();
|
||||
std::string host();
|
||||
virtual bool run() override;
|
||||
const cdn_config& config() { return m_config; }
|
||||
|
||||
@@ -29,6 +29,7 @@ namespace ylib
|
||||
~interceptor();
|
||||
size_t add(const std::string& regex_express, std::function<bool(network::http::reqpack* rp,const std::string& express)> callback);
|
||||
bool trigger(const std::string& url, network::http::reqpack* rp);
|
||||
void clear();
|
||||
private:
|
||||
ylib::nolock_array<interceptor_info*> m_array;
|
||||
};
|
||||
|
||||
@@ -109,14 +109,11 @@ namespace ylib
|
||||
std::string path,
|
||||
network::http::method method
|
||||
);
|
||||
#if HTTP_LUA_ENGINE == 1
|
||||
void subscribe(
|
||||
const std::string& lua_filepath,
|
||||
std::string path,
|
||||
network::http::method method,
|
||||
std::function<void(sol::state& state)> init_state = nullptr
|
||||
);
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// 清理所有订阅
|
||||
/// </summary>
|
||||
void clear_subscribe();
|
||||
/******************************************************************
|
||||
* function:其它
|
||||
* desc:未订阅请求触发该回调
|
||||
|
||||
@@ -49,17 +49,17 @@ namespace ylib
|
||||
ylib::nolock_array<network::http::proxy*>* proxy();
|
||||
private:
|
||||
// 文件缓存
|
||||
network::http::cache* m_cache;
|
||||
network::http::cache* m_cache = nullptr;
|
||||
// SESSION缓存
|
||||
ylib::local_storage* m_session_local_storage;
|
||||
ylib::local_storage* m_session_local_storage = nullptr;
|
||||
// router路由 服务
|
||||
network::http::router* m_router;
|
||||
network::http::router* m_router = nullptr;
|
||||
// CDN服务
|
||||
network::http::cdn* m_cdn;
|
||||
network::http::cdn* m_cdn = nullptr;
|
||||
// HOST
|
||||
std::vector<network::http::host*> m_hosts;
|
||||
// HTTPS
|
||||
bool m_https;
|
||||
bool m_https = false;
|
||||
// 反向代理
|
||||
ylib::nolock_array<network::http::proxy*> m_proxy;
|
||||
// 配置
|
||||
|
||||
@@ -45,7 +45,7 @@ namespace ylib
|
||||
}
|
||||
return m_array[index];
|
||||
}
|
||||
|
||||
inline size_t size() { return m_count; }
|
||||
T* m_array;
|
||||
size_t m_count;
|
||||
};
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include <vector>
|
||||
#include "util/json.h"
|
||||
#include "util/counter.hpp"
|
||||
#include "base/error.h"
|
||||
namespace leveldb
|
||||
{
|
||||
class DB;
|
||||
@@ -12,7 +13,7 @@ namespace ylib
|
||||
/// <summary>
|
||||
/// 本地存储(LevelDB)
|
||||
/// </summary>
|
||||
class local_storage
|
||||
class local_storage:public ylib::error_base
|
||||
{
|
||||
public:
|
||||
local_storage();
|
||||
|
||||
@@ -104,6 +104,12 @@ bool network::http::cdn::start(const cdn_config& config){
|
||||
::ithread::start();
|
||||
return true;
|
||||
}
|
||||
void ylib::network::http::cdn::close()
|
||||
{
|
||||
::ithread::stop();
|
||||
::ithread::wait();
|
||||
m_nodes.clear();
|
||||
}
|
||||
std::string network::http::cdn::host(){
|
||||
int32 score = 0;
|
||||
std::string result_host;
|
||||
|
||||
@@ -13,6 +13,7 @@ ylib::network::http::center::center()
|
||||
|
||||
ylib::network::http::center::~center()
|
||||
{
|
||||
close();
|
||||
}
|
||||
bool ylib::network::http::center::create(const start_config& config)
|
||||
{
|
||||
@@ -80,7 +81,16 @@ void ylib::network::http::center::close()
|
||||
delete m_server[i];
|
||||
}
|
||||
}
|
||||
for (size_t i = 0; i < m_website.size(); i++)
|
||||
{
|
||||
if (m_website[i] != nullptr)
|
||||
{
|
||||
m_website[i]->close();
|
||||
delete m_website[i];
|
||||
}
|
||||
}
|
||||
m_server.clear();
|
||||
m_website.clear();
|
||||
}
|
||||
|
||||
ylib::network::http::server* ylib::network::http::center::server(ushort port)
|
||||
|
||||
@@ -11,7 +11,7 @@ network::http::interceptor::interceptor()
|
||||
}
|
||||
network::http::interceptor::~interceptor()
|
||||
{
|
||||
|
||||
clear();
|
||||
}
|
||||
size_t network::http::interceptor::add(const std::string& express, std::function<bool(network::http::reqpack* rp,const std::string&)> callback)
|
||||
{
|
||||
@@ -40,4 +40,10 @@ bool network::http::interceptor::trigger(const std::string& url, network::http::
|
||||
}
|
||||
return true;
|
||||
}
|
||||
void ylib::network::http::interceptor::clear()
|
||||
{
|
||||
for (size_t i = 0; i < m_array.size(); i++)
|
||||
delete m_array.get(i);
|
||||
m_array.free();
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -67,7 +67,8 @@ void network::http::router::close()
|
||||
delete this->m_threadpool;
|
||||
this->m_threadpool = nullptr;
|
||||
}
|
||||
|
||||
m_interceptor->clear();
|
||||
clear_subscribe();
|
||||
}
|
||||
network::http::interceptor* network::http::router::interceptor(){
|
||||
m_interceptor->center(center());
|
||||
@@ -105,21 +106,12 @@ void network::http::router::subscribe(
|
||||
svie->controller_function = function;
|
||||
m_subscribe.append(svie);
|
||||
}
|
||||
#if HTTP_LUA_ENGINE == 1
|
||||
void ylib::network::http::router::subscribe(const std::string& lua_filepath, std::string path, network::http::method method, std::function<void(sol::state& state)> init_state)
|
||||
void ylib::network::http::router::clear_subscribe()
|
||||
{
|
||||
#if HTTP_ROUTER_PRINT == 1
|
||||
ylib::log->info("[subscribe][ctl][lua] express:" + path + " method:" + method_to_string(method), "router");
|
||||
#endif
|
||||
network::http::subscribe_info* svie = new network::http::subscribe_info;
|
||||
svie->controller = false;
|
||||
svie->method = method;
|
||||
svie->express = std::regex(path.c_str());
|
||||
svie->lua_filepath = lua_filepath;
|
||||
svie->lua_init_state = init_state;
|
||||
m_subscribe.append(svie);
|
||||
for (size_t i = 0; i < m_subscribe.size(); i++)
|
||||
delete m_subscribe.get(i);
|
||||
m_subscribe.free();
|
||||
}
|
||||
#endif
|
||||
void network::http::router::other(std::function<void(network::http::request*,network::http::response*)> callback)
|
||||
{
|
||||
this->m_callback_other = callback;
|
||||
@@ -229,12 +221,7 @@ void ylib::network::http::router::__thread_callback(reqpack* rp)
|
||||
if (m_callback_other != nullptr) {
|
||||
m_callback_other(rp->request(), rp->response());
|
||||
}else{
|
||||
std::string filepath = rp->request()->filepath();
|
||||
if(filepath == "/")
|
||||
filepath = "/index.html";
|
||||
if(rp->response()->send_file(filepath) == false){
|
||||
rp->response()->send((std::string)"404 Not found",404,"Not Found");
|
||||
}
|
||||
rp->response()->send((std::string)"Services that have not been processed",500,"Service Unavailable");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -159,6 +159,10 @@ bool ylib::network::http::website::start(const website_config& config)
|
||||
|
||||
void ylib::network::http::website::close()
|
||||
{
|
||||
m_router->close();
|
||||
m_cache->stop();
|
||||
m_cdn->close();
|
||||
m_session_local_storage->close();
|
||||
}
|
||||
network::http::router* network::http::website::router()
|
||||
{
|
||||
|
||||
@@ -18,7 +18,12 @@ bool ylib::local_storage::open(const std::string& dirpath)
|
||||
|
||||
// 打开数据库
|
||||
leveldb::Status status = leveldb::DB::Open(options, dirpath, &m_db);
|
||||
return status.ok();
|
||||
if (status.ok() == false)
|
||||
{
|
||||
m_lastErrorDesc = status.ToString();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void ylib::local_storage::close()
|
||||
|
||||
Reference in New Issue
Block a user