equal
deleted
inserted
replaced
45 local s_sub = string.sub |
45 local s_sub = string.sub |
46 |
46 |
47 local coroutine_wrap = coroutine.wrap |
47 local coroutine_wrap = coroutine.wrap |
48 local coroutine_yield = coroutine.yield |
48 local coroutine_yield = coroutine.yield |
49 |
49 |
50 local has_luasec, ssl = pcall ( require , "ssl" ) |
50 local has_luasec = pcall ( require , "ssl" ) |
51 local socket = require "socket" |
51 local socket = require "socket" |
52 local levent = require "luaevent.core" |
52 local levent = require "luaevent.core" |
53 local inet = require "util.net"; |
53 local inet = require "util.net"; |
54 local inet_pton = inet.pton; |
54 local inet_pton = inet.pton; |
55 |
55 |
151 local _ |
151 local _ |
152 _ = self.eventread and self.eventread:close( ) -- close events; this must be called outside of the event callbacks! |
152 _ = self.eventread and self.eventread:close( ) -- close events; this must be called outside of the event callbacks! |
153 _ = self.eventwrite and self.eventwrite:close( ) |
153 _ = self.eventwrite and self.eventwrite:close( ) |
154 self.eventread, self.eventwrite = nil, nil |
154 self.eventread, self.eventwrite = nil, nil |
155 local err |
155 local err |
156 self.conn, err = ssl.wrap( self.conn, self._sslctx ) |
156 self.conn, err = self._sslctx:wrap(self.conn) |
157 if err then |
157 if err then |
158 self.fatalerror = err |
158 self.fatalerror = err |
159 self.conn = nil -- cannot be used anymore |
159 self.conn = nil -- cannot be used anymore |
160 if call_onconnect then |
160 if call_onconnect then |
161 self.ondisconnect = nil -- don't call this when client isn't really connected |
161 self.ondisconnect = nil -- don't call this when client isn't really connected |
166 end |
166 end |
167 |
167 |
168 if self.conn.sni then |
168 if self.conn.sni then |
169 if self.servername then |
169 if self.servername then |
170 self.conn:sni(self.servername); |
170 self.conn:sni(self.servername); |
171 elseif self._server and type(self._server.hosts) == "table" and next(self._server.hosts) ~= nil then |
171 elseif next(self._sslctx._sni_contexts) ~= nil then |
172 self.conn:sni(self._server.hosts, true); |
172 self.conn:sni(self._sslctx._sni_contexts, true); |
173 end |
173 end |
174 end |
174 end |
175 |
175 |
176 self.conn:settimeout( 0 ) -- set non blocking |
176 self.conn:settimeout( 0 ) -- set non blocking |
177 local handshakecallback = coroutine_wrap(function( event ) |
177 local handshakecallback = coroutine_wrap(function( event ) |
270 end |
270 end |
271 end |
271 end |
272 |
272 |
273 function interface_mt:pause() |
273 function interface_mt:pause() |
274 return self:_lock(self.nointerface, true, self.nowriting); |
274 return self:_lock(self.nointerface, true, self.nowriting); |
|
275 end |
|
276 |
|
277 function interface_mt:sslctx() |
|
278 return self._sslctx |
|
279 end |
|
280 |
|
281 function interface_mt:ssl_info() |
|
282 return self.conn.info and self.conn:info() |
|
283 end |
|
284 |
|
285 function interface_mt:ssl_peercertificate() |
|
286 return self.conn.getpeercertificate and self.conn:getpeercertificate() |
|
287 end |
|
288 |
|
289 function interface_mt:ssl_peerverification() |
|
290 return self.conn.getpeerverification and self.conn:getpeerverification() |
|
291 end |
|
292 |
|
293 function interface_mt:ssl_peerfinished() |
|
294 return self.conn.getpeerfinished and self.conn:getpeerfinished() |
275 end |
295 end |
276 |
296 |
277 function interface_mt:resume() |
297 function interface_mt:resume() |
278 self:_lock(self.nointerface, false, self.nowriting); |
298 self:_lock(self.nointerface, false, self.nowriting); |
279 if self.readcallback and not self.eventread then |
299 if self.readcallback and not self.eventread then |