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); |