Software /
code /
verse
Comparison
init.lua @ 135:8adf5fb27ce3
verse: Fire disconnected event even if connection fails instantly
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Tue, 14 Sep 2010 15:02:29 +0100 |
parent | 132:b38397163737 |
child | 141:15706f6492ae |
comparison
equal
deleted
inserted
replaced
134:2101acbb27c4 | 135:8adf5fb27ce3 |
---|---|
65 conn:settimeout(0); | 65 conn:settimeout(0); |
66 local success, err = conn:connect(connect_host, connect_port); | 66 local success, err = conn:connect(connect_host, connect_port); |
67 | 67 |
68 if not success and err ~= "timeout" then | 68 if not success and err ~= "timeout" then |
69 self:warn("connect() to %s:%d failed: %s", connect_host, connect_port, err); | 69 self:warn("connect() to %s:%d failed: %s", connect_host, connect_port, err); |
70 return false, err; | 70 return self:event("disconnected", { reason = err }) or false, err; |
71 end | 71 end |
72 | 72 |
73 local conn = server.wrapclient(conn, connect_host, connect_port, new_listener(self), "*a"); | 73 local conn = server.wrapclient(conn, connect_host, connect_port, new_listener(self), "*a"); |
74 if not conn then | 74 if not conn then |
75 self:warn("connection initialisation failed: %s", err); | 75 self:warn("connection initialisation failed: %s", err); |
76 return false, err; | 76 return self:event("disconnected", { reason = err }) or false, err; |
77 end | 77 end |
78 | 78 |
79 self.conn = conn; | 79 self.conn = conn; |
80 local w, t = conn.write, tostring; | 80 local w, t = conn.write, tostring; |
81 self.send = function (_, data) return w(conn, t(data)); end | 81 self.send = function (_, data) return w(conn, t(data)); end |