From f0934e81846cf77ba1ba626161521b78021a2bc8 Mon Sep 17 00:00:00 2001 From: xiyoo0812 Date: Wed, 15 May 2024 18:18:59 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E9=83=A8=E5=88=86=E7=BB=84?= =?UTF-8?q?=E4=BB=B6=E7=9A=84=E9=80=80=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- extend/lsqlite/src/lsqlite.h | 2 +- script/driver/lmdb.lua | 11 +++++++++++ script/driver/sqlite.lua | 17 +++++++++++++++++ script/driver/unqlite.lua | 11 +++++++++++ script/network/http_server.lua | 11 +++++++++++ script/network/net_server.lua | 11 +++++++++++ script/network/rpc_server.lua | 12 ++++++++++++ server/center/gm_mgr.lua | 1 - 8 files changed, 74 insertions(+), 2 deletions(-) diff --git a/extend/lsqlite/src/lsqlite.h b/extend/lsqlite/src/lsqlite.h index 9191f2a2..226dd35f 100644 --- a/extend/lsqlite/src/lsqlite.h +++ b/extend/lsqlite/src/lsqlite.h @@ -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; } diff --git a/script/driver/lmdb.lua b/script/driver/lmdb.lua index bfa84487..2d00ef3b 100644 --- a/script/driver/lmdb.lua +++ b/script/driver/lmdb.lua @@ -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 @@ -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) diff --git a/script/driver/sqlite.lua b/script/driver/sqlite.lua index a7437d57..5aa30130 100644 --- a/script/driver/sqlite.lua +++ b/script/driver/sqlite.lua @@ -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 @@ -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) diff --git a/script/driver/unqlite.lua b/script/driver/unqlite.lua index 77f37cc2..4e5169c2 100644 --- a/script/driver/unqlite.lua +++ b/script/driver/unqlite.lua @@ -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 @@ -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) diff --git a/script/network/http_server.lua b/script/network/http_server.lua index a5096965..148d4c69 100644 --- a/script/network/http_server.lua +++ b/script/network/http_server.lua @@ -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地址 @@ -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) diff --git a/script/network/net_server.lua b/script/network/net_server.lua index 9f70032d..064c340e 100644 --- a/script/network/net_server.lua +++ b/script/network/net_server.lua @@ -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 @@ -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") @@ -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 diff --git a/script/network/rpc_server.lua b/script/network/rpc_server.lua index fab7b01e..812b4e5b 100644 --- a/script/network/rpc_server.lua +++ b/script/network/rpc_server.lua @@ -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") @@ -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事件 diff --git a/server/center/gm_mgr.lua b/server/center/gm_mgr.lua index 9d9301a3..8679fb9e 100644 --- a/server/center/gm_mgr.lua +++ b/server/center/gm_mgr.lua @@ -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