Software /
code /
prosody
Comparison
net/server_select.lua @ 6782:ec172dbe9d14
net.server_{select,event}: Don't rely on LuaSocket and LuaSec being present in the globals table
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Mon, 23 Feb 2015 12:04:43 +0100 |
parent | 6459:ba421af3dfd3 |
child | 6791:e813e8cf6046 |
child | 6812:7af63377a1cf |
comparison
equal
deleted
inserted
replaced
6781:05cd80ec107c | 6782:ec172dbe9d14 |
---|---|
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 //-- |
592 _ = handler and handler:force_close("ssl handshake failed") | 592 _ = handler and handler:force_close("ssl handshake failed") |
593 return false, err -- handshake failed | 593 return false, err -- handshake failed |
594 end | 594 end |
595 ) | 595 ) |
596 end | 596 end |
597 if luasec then | 597 if has_luasec then |
598 handler.starttls = function( self, _sslctx) | 598 handler.starttls = function( self, _sslctx) |
599 if _sslctx then | 599 if _sslctx then |
600 handler:set_sslctx(_sslctx); | 600 handler:set_sslctx(_sslctx); |
601 end | 601 end |
602 if bufferqueuelen > 0 then | 602 if bufferqueuelen > 0 then |
645 shutdown = ( ssl and id ) or socket.shutdown | 645 shutdown = ( ssl and id ) or socket.shutdown |
646 | 646 |
647 _socketlist[ socket ] = handler | 647 _socketlist[ socket ] = handler |
648 _readlistlen = addsocket(_readlist, socket, _readlistlen) | 648 _readlistlen = addsocket(_readlist, socket, _readlistlen) |
649 | 649 |
650 if sslctx and luasec then | 650 if sslctx and has_luasec then |
651 out_put "server.lua: auto-starting ssl negotiation..." | 651 out_put "server.lua: auto-starting ssl negotiation..." |
652 handler.autostart_ssl = true; | 652 handler.autostart_ssl = true; |
653 local ok, err = handler:starttls(sslctx); | 653 local ok, err = handler:starttls(sslctx); |
654 if ok == false then | 654 if ok == false then |
655 return nil, nil, err | 655 return nil, nil, err |
729 end | 729 end |
730 if type( port ) ~= "number" or not ( port >= 0 and port <= 65535 ) then | 730 if type( port ) ~= "number" or not ( port >= 0 and port <= 65535 ) then |
731 err = "invalid port" | 731 err = "invalid port" |
732 elseif _server[ addr..":"..port ] then | 732 elseif _server[ addr..":"..port ] then |
733 err = "listeners on '[" .. addr .. "]:" .. port .. "' already exist" | 733 err = "listeners on '[" .. addr .. "]:" .. port .. "' already exist" |
734 elseif sslctx and not luasec then | 734 elseif sslctx and not has_luasec then |
735 err = "luasec not found" | 735 err = "luasec not found" |
736 end | 736 end |
737 if err then | 737 if err then |
738 out_error( "server.lua, [", addr, "]:", port, ": ", err ) | 738 out_error( "server.lua, [", addr, "]:", port, ": ", err ) |
739 return nil, err | 739 return nil, err |