Comparison

net/multiplex_listener.lua @ 3138:d6151c9a6f7e

net.multiplex_listener: Test to make sure listener.onconnect isn't nil.
author Waqas Hussain <waqas20@gmail.com>
date Wed, 02 Jun 2010 17:25:01 +0500
parent 3137:463d51ee9a2b
comparison
equal deleted inserted replaced
3137:463d51ee9a2b 3138:d6151c9a6f7e
17 buffer[conn] = nil; 17 buffer[conn] = nil;
18 buf = buf and buf..data or data; 18 buf = buf and buf..data or data;
19 if buf:match("^[a-zA-Z]") then 19 if buf:match("^[a-zA-Z]") then
20 local listener = httpserver_listener; 20 local listener = httpserver_listener;
21 conn:setlistener(listener); 21 conn:setlistener(listener);
22 local onconnect = listener.onconnect;
23 if onconnect then onconnect(conn) end
22 listener.onincoming(conn, buf); 24 listener.onincoming(conn, buf);
23 elseif buf:match(">") then 25 elseif buf:match(">") then
24 local listener; 26 local listener;
25 local xmlns = buf:match("%sxmlns%s*=%s*['\"]([^'\"]*)"); 27 local xmlns = buf:match("%sxmlns%s*=%s*['\"]([^'\"]*)");
26 if xmlns == "jabber:server" then 28 if xmlns == "jabber:server" then
29 listener = xmppcomponent_listener; 31 listener = xmppcomponent_listener;
30 else 32 else
31 listener = xmppclient_listener; 33 listener = xmppclient_listener;
32 end 34 end
33 conn:setlistener(listener); 35 conn:setlistener(listener);
34 listener.onconnect(conn); 36 local onconnect = listener.onconnect;
37 if onconnect then onconnect(conn) end
35 listener.onincoming(conn, buf); 38 listener.onincoming(conn, buf);
36 elseif #buf > 1024 then 39 elseif #buf > 1024 then
37 conn:close(); 40 conn:close();
38 else 41 else
39 buffer[conn] = buf; 42 buffer[conn] = buf;