Comparison

init.lua @ 163:48a47bca9a63

verse: Change to set conn:send in only one place, and fire new events 'outgoing' and 'outgoing-raw'
author Matthew Wild <mwild1@gmail.com>
date Wed, 15 Dec 2010 14:48:55 +0000
parent 162:2950079d4319
child 173:3112a9e450ac
comparison
equal deleted inserted replaced
162:2950079d4319 163:48a47bca9a63
87 self:warn("connection initialisation failed: %s", err); 87 self:warn("connection initialisation failed: %s", err);
88 return self:event("disconnected", { reason = err }) or false, err; 88 return self:event("disconnected", { reason = err }) or false, err;
89 end 89 end
90 90
91 self.conn = conn; 91 self.conn = conn;
92 local w, t = conn.write, tostring; 92 self.send = function (stream, data)
93 self.send = function (_, data) return w(conn, t(data)); end 93 self:event("outgoing", data);
94 data = tostring(data);
95 self:event("outgoing-raw", data);
96 return conn:write(data);
97 end;
94 return true; 98 return true;
95 end 99 end
96 100
97 function stream:close() 101 function stream:close()
98 if not self.conn then 102 if not self.conn then
184 function new_listener(stream) 188 function new_listener(stream)
185 local conn_listener = {}; 189 local conn_listener = {};
186 190
187 function conn_listener.onconnect(conn) 191 function conn_listener.onconnect(conn)
188 stream.connected = true; 192 stream.connected = true;
189 stream.send = function (stream, data) stream:debug("Sending data: "..tostring(data)); return conn:write(tostring(data)); end;
190 stream:event("connected"); 193 stream:event("connected");
191 end 194 end
192 195
193 function conn_listener.onincoming(conn, data) 196 function conn_listener.onincoming(conn, data)
194 stream:event("incoming-raw", data); 197 stream:event("incoming-raw", data);