sessionmanager: Make session.send() return true unless there really is an error ...
[prosody.git] / plugins / mod_component.lua
index a5767c9a33039ed0653266d2714630dcbbd93041..11abab799e3b2be35979ad4ba3ccc87e287ca22f 100644 (file)
@@ -25,6 +25,8 @@ local hosts = prosody.hosts;
 
 local log = module._log;
 
+local opt_keepalives = module:get_option_boolean("component_tcp_keepalives", module:get_option_boolean("tcp_keepalives", true));
+
 local sessions = module:shared("sessions");
 
 function module.add_host(module)
@@ -83,10 +85,11 @@ function module.add_host(module)
                session.type = "component";
                module:log("info", "External component successfully authenticated");
                session.send(st.stanza("handshake"));
+               module:fire_event("component-authenticated", { session = session });
        
                return true;
        end
-       module:hook("stanza/jabber:component:accept:handshake", handle_component_auth);
+       module:hook("stanza/jabber:component:accept:handshake", handle_component_auth, -1);
 
        -- Handle stanzas addressed to this component
        local function handle_stanza(event)
@@ -269,6 +272,10 @@ function listener.onconnect(conn)
        local conn_name = "jcp"..tostring(session):match("[a-f0-9]+$");
        session.log = logger.init(conn_name);
        session.close = session_close;
+
+       if opt_keepalives then
+               conn:setoption("keepalive", opt_keepalives);
+       end
        
        session.log("info", "Incoming Jabber component connection");
        
@@ -313,6 +320,10 @@ function listener.ondisconnect(conn, err)
        end
 end
 
+function listener.ondetach(conn)
+       sessions[conn] = nil;
+end
+
 module:provides("net", {
        name = "component";
        private = true;