Comparison

init.lua @ 20:972066e06f4c

verse: Update for new server connection API
author Matthew Wild <mwild1@gmail.com>
date Tue, 01 Dec 2009 04:14:52 +0000
parent 17:ec6b0b94826c
child 23:33e346283135
comparison
equal deleted inserted replaced
19:5d593126e62d 20:972066e06f4c
46 return nil, err; 46 return nil, err;
47 end 47 end
48 48
49 self.conn = conn; 49 self.conn = conn;
50 local w, t = conn.write, tostring; 50 local w, t = conn.write, tostring;
51 self.send = function (_, data) return w(t(data)); end 51 self.send = function (_, data) return w(conn, t(data)); end
52 end 52 end
53 53
54 -- Logging functions 54 -- Logging functions
55 function stream:debug(...) 55 function stream:debug(...)
56 return self.logger("debug", ...); 56 return self.logger("debug", ...);
88 88
89 -- Listener factory 89 -- Listener factory
90 function new_listener(stream) 90 function new_listener(stream)
91 local conn_listener = {}; 91 local conn_listener = {};
92 92
93 function conn_listener.incoming(conn, data) 93 function conn_listener.onincoming(conn, data)
94 stream:debug("Data"); 94 stream:debug("Data");
95 if not stream.connected then 95 if not stream.connected then
96 stream.connected = true; 96 stream.connected = true;
97 stream.send = function (stream, data) stream:debug("Sending data: "..tostring(data)); return conn.write(tostring(data)); end; 97 stream.send = function (stream, data) stream:debug("Sending data: "..tostring(data)); return conn:write(tostring(data)); end;
98 stream:event("connected"); 98 stream:event("connected");
99 end 99 end
100 if data then 100 if data then
101 stream:event("incoming-raw", data); 101 stream:event("incoming-raw", data);
102 end 102 end
103 end 103 end
104 104
105 function conn_listener.disconnect(conn, err) 105 function conn_listener.ondisconnect(conn, err)
106 stream.connected = false; 106 stream.connected = false;
107 stream:event("disconnected", { reason = err }); 107 stream:event("disconnected", { reason = err });
108 end 108 end
109 109
110 return conn_listener; 110 return conn_listener;