Skip to content

Commit

Permalink
优化部分组件的退出
Browse files Browse the repository at this point in the history
  • Loading branch information
xiyoo0812 committed May 15, 2024
1 parent 1bf86a5 commit f0934e8
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 2 deletions.
2 changes: 1 addition & 1 deletion extend/lsqlite/src/lsqlite.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ namespace lsqlite {
~sqlite_driver() { close(); }

void close() {
if (m_sdb) sqlite3_close(m_sdb);
if (m_sdb) sqlite3_close_v2(m_sdb);
m_sdb = nullptr;
}

Expand Down
11 changes: 11 additions & 0 deletions script/driver/lmdb.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
local log_debug = logger.debug
local sformat = string.format

local update_mgr = quanta.get("update_mgr")

local MDB_SUCCESS = lmdb.MDB_CODE.MDB_SUCCESS
local MDB_NOTFOUND = lmdb.MDB_CODE.MDB_NOTFOUND

Expand All @@ -24,6 +26,15 @@ prop:reader("jcodec", nil)

function Lmdb:__init()
stdfs.mkdir(LMDB_PATH)
update_mgr:attach_quit(self)
end

function Lmdb:on_quit()
if self.driver then
log_debug("[Lmdb][on_quit]")
self.driver.close()
self.driver = nil
end
end

function Lmdb:open(name, dbname)
Expand Down
17 changes: 17 additions & 0 deletions script/driver/sqlite.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ local log_err = logger.err
local log_debug = logger.debug
local sformat = string.format

local update_mgr = quanta.get("update_mgr")

local SQLITE_OK = sqlite.SQLITE_CODE.SQLITE_OK
local SQLITE_DONE = sqlite.SQLITE_CODE.SQLITE_DONE
local SQLITE_NFOUND = sqlite.SQLITE_CODE.SQLITE_NOTFOUND
Expand All @@ -19,6 +21,21 @@ prop:reader("prepares", {})

function Sqlite:__init()
stdfs.mkdir(SQDB_PATH)
update_mgr:attach_quit(self)
end

function Sqlite:on_quit()
if self.driver then
log_debug("[Sqlite][on_quit]")
for _, stmts in pairs(self.prepares) do
for _, stmt in pairs(stmts) do
stmt.close()
end
end
self.prepares = {}
self.driver.close()
self.driver = nil
end
end

function Sqlite:open(dbname)
Expand Down
11 changes: 11 additions & 0 deletions script/driver/unqlite.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
local log_debug = logger.debug
local sformat = string.format

local update_mgr = quanta.get("update_mgr")

local UNQLITE_OK = unqlite.UNQLITE_CODE.UNQLITE_OK
local UNQLITE_NOTFOUND = unqlite.UNQLITE_CODE.UNQLITE_NOTFOUND

Expand All @@ -17,6 +19,15 @@ prop:reader("jcodec", nil)

function Unqlite:__init()
stdfs.mkdir(UNQLITE_PATH)
update_mgr:attach_quit(self)
end

function Unqlite:on_quit()
if self.driver then
log_debug("[Unqlite][on_quit]")
self.driver.close()
self.driver = nil
end
end

function Unqlite:open(name)
Expand Down
11 changes: 11 additions & 0 deletions script/network/http_server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ local jsoncodec = json.jsoncodec
local httpdcodec = codec.httpdcodec
local derive_port = luabus.derive_port

local update_mgr = quanta.get("update_mgr")

local HttpServer = class()
local prop = property(HttpServer)
prop:reader("ip", nil) --http server地址
Expand All @@ -29,6 +31,15 @@ function HttpServer:__init(http_addr)
self.hcodec = httpdcodec(self.jcodec)
self.handlers = { GET = {}, POST = {}, PUT = {}, DELETE = {} }
self:setup(http_addr)
--注册退出
update_mgr:attach_quit(self)
end

function HttpServer:on_quit()
if self.listener then
log_debug("[HttpServer][on_quit]")
self.listener:close()
end
end

function HttpServer:setup(http_addr)
Expand Down
11 changes: 11 additions & 0 deletions script/network/net_server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
local log_err = logger.err
local log_info = logger.info
local log_warn = logger.warn
local log_debug = logger.debug
local signalquit = signal.quit
local qdefer = quanta.defer
local qxpcall = quanta.xpcall
Expand All @@ -11,6 +12,7 @@ local derive_port = luabus.derive_port
local proto_pb = luabus.eproto_type.pb

local event_mgr = quanta.get("event_mgr")
local update_mgr = quanta.get("update_mgr")
local thread_mgr = quanta.get("thread_mgr")
local socket_mgr = quanta.get("socket_mgr")
local protobuf_mgr = quanta.get("protobuf_mgr")
Expand Down Expand Up @@ -42,6 +44,15 @@ prop:accessor("msgtype", 0) --消息类型
function NetServer:__init(session_type)
self.session_type = session_type
self.codec = protobuf.pbcodec()
--注册退出
update_mgr:attach_quit(self)
end

function NetServer:on_quit()
if self.listener then
log_debug("[NetServer][on_quit]")
self.listener:close()
end
end

--induce:根据 order 推导port
Expand Down
12 changes: 12 additions & 0 deletions script/network/rpc_server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ local signalquit = signal.quit
local log_err = logger.err
local log_warn = logger.warn
local log_info = logger.info
local log_debug = logger.debug
local qdefer = quanta.defer
local qxpcall = quanta.xpcall
local hash_code = codec.hash_code
local derive_port = luabus.derive_port

local event_mgr = quanta.get("event_mgr")
local update_mgr = quanta.get("update_mgr")
local thread_mgr = quanta.get("thread_mgr")
local socket_mgr = quanta.get("socket_mgr")

Expand Down Expand Up @@ -53,8 +55,18 @@ function RpcServer:__init(holder, ip, port, induce)
self.listener = listener
self.ip, self.port = ip, real_port
log_info("[RpcServer][setup] now listen {}:{} success!", ip, real_port)
--监听rpc
event_mgr:add_listener(self, "rpc_heartbeat")
event_mgr:add_listener(self, "rpc_register")
--注册退出
update_mgr:attach_quit(self)
end

function RpcServer:on_quit()
if self.listener then
log_debug("[RpcServer][on_quit]")
self.listener:close()
end
end

--rpc事件
Expand Down
1 change: 0 additions & 1 deletion server/center/gm_mgr.lua
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ function GM_Mgr:__init()

--创建HTTP服务器
local server = HttpServer(environ.get("QUANTA_GM_HTTP"))
service.modify_host(server:get_port())
self.http_server = server
--是否开启GM功能
if environ.status("QUANTA_GM_SERVER") then
Expand Down

0 comments on commit f0934e8

Please sign in to comment.