Comparison

net/server_event.lua @ 8529:257fd322fc9f

net.server_event: Better outgoing connection error handling Same as 67311cda0625. Check for readability. If a socket is readable after initial connection, it likely means an error, so we call the readcallback for that connection to handle it (and ultimately close).
author Matthew Wild <mwild1@gmail.com>
date Fri, 23 Feb 2018 15:33:02 +0000
parent 8384:4a5c6f6214ee
child 8530:075df839c110
comparison
equal deleted inserted replaced
8528:67311cda0625 8529:257fd322fc9f
103 if EV_TIMEOUT == event then -- timeout during connection 103 if EV_TIMEOUT == event then -- timeout during connection
104 self.fatalerror = "connection timeout" 104 self.fatalerror = "connection timeout"
105 self:ontimeout() -- call timeout listener 105 self:ontimeout() -- call timeout listener
106 self:_close() 106 self:_close()
107 debug( "new connection failed. id:", self.id, "error:", self.fatalerror ) 107 debug( "new connection failed. id:", self.id, "error:", self.fatalerror )
108 elseif EV_READWRITE == event then
109 self.readcallback(event);
108 else 110 else
109 if plainssl and has_luasec then -- start ssl session 111 if plainssl and has_luasec then -- start ssl session
110 self:starttls(self._sslctx, true) 112 self:starttls(self._sslctx, true)
111 else -- normal connection 113 else -- normal connection
112 self:_start_session(true) 114 self:_start_session(true)
114 debug( "new connection established. id:", self.id ) 116 debug( "new connection established. id:", self.id )
115 end 117 end
116 self.eventconnect = nil 118 self.eventconnect = nil
117 return -1 119 return -1
118 end 120 end
119 self.eventconnect = addevent( base, self.conn, EV_WRITE, callback, cfg.CONNECT_TIMEOUT ) 121 self.eventconnect = addevent( base, self.conn, EV_READWRITE, callback, cfg.CONNECT_TIMEOUT )
120 return true 122 return true
121 end 123 end
122 function interface_mt:_start_session(call_onconnect) -- new session, for example after startssl 124 function interface_mt:_start_session(call_onconnect) -- new session, for example after startssl
123 if self.type == "client" then 125 if self.type == "client" then
124 local callback = function( ) 126 local callback = function( )