Software / code / prosody
Comparison
net/server_select.lua @ 5956:59997f3f5502
net/server_select: pcall require ssl (easy to forget to require ssl)
| author | daurnimator <quae@daurnimator.com> |
|---|---|
| date | Wed, 18 Dec 2013 17:50:38 -0500 |
| parent | 5950:bd1d1c29a7e7 |
| child | 5957:3c5061d937dd |
comparison
equal
deleted
inserted
replaced
| 5955:b3d5aa57c454 | 5956:59997f3f5502 |
|---|---|
| 46 local coroutine_wrap = coroutine.wrap | 46 local coroutine_wrap = coroutine.wrap |
| 47 local coroutine_yield = coroutine.yield | 47 local coroutine_yield = coroutine.yield |
| 48 | 48 |
| 49 --// extern libs //-- | 49 --// extern libs //-- |
| 50 | 50 |
| 51 local luasec = use "ssl" | 51 local has_luasec, luasec = pcall ( require , "ssl" ) |
| 52 local luasocket = use "socket" or require "socket" | 52 local luasocket = use "socket" or require "socket" |
| 53 local luasocket_gettime = luasocket.gettime | 53 local luasocket_gettime = luasocket.gettime |
| 54 | 54 |
| 55 --// extern lib methods //-- | 55 --// extern lib methods //-- |
| 56 | 56 |
| 57 local ssl_wrap = ( luasec and luasec.wrap ) | 57 local ssl_wrap = ( has_luasec and luasec.wrap ) |
| 58 local socket_bind = luasocket.bind | 58 local socket_bind = luasocket.bind |
| 59 local socket_sleep = luasocket.sleep | 59 local socket_sleep = luasocket.sleep |
| 60 local socket_select = luasocket.select | 60 local socket_select = luasocket.select |
| 61 | 61 |
| 62 --// functions //-- | 62 --// functions //-- |
| 583 _ = handler and handler:force_close("ssl handshake failed") | 583 _ = handler and handler:force_close("ssl handshake failed") |
| 584 return false, err -- handshake failed | 584 return false, err -- handshake failed |
| 585 end | 585 end |
| 586 ) | 586 ) |
| 587 end | 587 end |
| 588 if luasec then | 588 if has_luasec then |
| 589 handler.starttls = function( self, _sslctx) | 589 handler.starttls = function( self, _sslctx) |
| 590 if _sslctx then | 590 if _sslctx then |
| 591 handler:set_sslctx(_sslctx); | 591 handler:set_sslctx(_sslctx); |
| 592 end | 592 end |
| 593 if bufferqueuelen > 0 then | 593 if bufferqueuelen > 0 then |
| 636 shutdown = ( ssl and id ) or socket.shutdown | 636 shutdown = ( ssl and id ) or socket.shutdown |
| 637 | 637 |
| 638 _socketlist[ socket ] = handler | 638 _socketlist[ socket ] = handler |
| 639 _readlistlen = addsocket(_readlist, socket, _readlistlen) | 639 _readlistlen = addsocket(_readlist, socket, _readlistlen) |
| 640 | 640 |
| 641 if sslctx and luasec then | 641 if sslctx and has_luasec then |
| 642 out_put "server.lua: auto-starting ssl negotiation..." | 642 out_put "server.lua: auto-starting ssl negotiation..." |
| 643 handler.autostart_ssl = true; | 643 handler.autostart_ssl = true; |
| 644 local ok, err = handler:starttls(sslctx); | 644 local ok, err = handler:starttls(sslctx); |
| 645 if ok == false then | 645 if ok == false then |
| 646 return nil, nil, err | 646 return nil, nil, err |
| 719 end | 719 end |
| 720 if type( port ) ~= "number" or not ( port >= 0 and port <= 65535 ) then | 720 if type( port ) ~= "number" or not ( port >= 0 and port <= 65535 ) then |
| 721 err = "invalid port" | 721 err = "invalid port" |
| 722 elseif _server[ addr..":"..port ] then | 722 elseif _server[ addr..":"..port ] then |
| 723 err = "listeners on '[" .. addr .. "]:" .. port .. "' already exist" | 723 err = "listeners on '[" .. addr .. "]:" .. port .. "' already exist" |
| 724 elseif sslctx and not luasec then | 724 elseif sslctx and not has_luasec then |
| 725 err = "luasec not found" | 725 err = "luasec not found" |
| 726 end | 726 end |
| 727 if err then | 727 if err then |
| 728 out_error( "server.lua, [", addr, "]:", port, ": ", err ) | 728 out_error( "server.lua, [", addr, "]:", port, ": ", err ) |
| 729 return nil, err | 729 return nil, err |