Close connection when an account is deleted
Added a __gc metamethod to take care of the finalization of active connections by logging out, when an account is deleted, or at the end of the configuration (for Lua 5.2).
This commit is contained in:
parent
89c1366665
commit
c7f507e76f
|
@ -32,6 +32,7 @@ Account._mt.__call = function (self, arg)
|
|||
|
||||
object._mt = {}
|
||||
object._mt.__index = object._attach_mailbox
|
||||
object._mt.__gc = object._logout_user
|
||||
setmetatable(object, object._mt)
|
||||
|
||||
object:_login_user()
|
||||
|
@ -60,6 +61,12 @@ function Account._login_user(self)
|
|||
end
|
||||
end
|
||||
|
||||
function Account._logout_user(self)
|
||||
if ifcore.logout(self._session) == nil then
|
||||
error("logout request failed", 0)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
function Account._attach_mailbox(self, mailbox)
|
||||
self[mailbox] = Mailbox(self, mailbox)
|
||||
|
|
|
@ -86,23 +86,18 @@ main(int argc, char *argv[])
|
|||
}
|
||||
|
||||
get_pathmax();
|
||||
|
||||
open_debug();
|
||||
|
||||
create_homedir();
|
||||
|
||||
catch_signals();
|
||||
|
||||
open_log();
|
||||
if (opts.config == NULL)
|
||||
opts.config = get_filepath("config.lua");
|
||||
|
||||
buffer_init(&ibuf, INPUT_BUF);
|
||||
buffer_init(&obuf, OUTPUT_BUF);
|
||||
buffer_init(&nbuf, NAMESPACE_BUF);
|
||||
buffer_init(&cbuf, CONVERSION_BUF);
|
||||
|
||||
if (opts.config == NULL)
|
||||
opts.config = get_filepath("config.lua");
|
||||
|
||||
regexp_compile(responses);
|
||||
|
||||
#ifndef NO_SSLTLS
|
||||
|
@ -111,7 +106,7 @@ main(int argc, char *argv[])
|
|||
#endif
|
||||
|
||||
start_lua();
|
||||
|
||||
#if LUA_VERSION_NUM < 502
|
||||
{
|
||||
list *l;
|
||||
session *s;
|
||||
|
@ -124,7 +119,7 @@ main(int argc, char *argv[])
|
|||
request_logout(s);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
stop_lua();
|
||||
|
||||
#ifndef NO_SSLTLS
|
||||
|
|
Loading…
Reference in New Issue