Comparison

net/server_event.lua @ 6817:07f43c7aa059

net/server_event: pcall require ssl rather than relying on globals
author daurnimator <quae@daurnimator.com>
date Wed, 18 Dec 2013 18:11:17 -0500
parent 6816:36367fb1ecf9
child 6818:ae9d1289a868
comparison
equal deleted inserted replaced
6816:36367fb1ecf9 6817:07f43c7aa059
714 return interface 714 return interface
715 end 715 end
716 end 716 end
717 717
718 local addserver = ( function( ) 718 local addserver = ( function( )
719 return function( addr, port, listener, pattern, sslcfg, startssl ) -- TODO: check arguments 719 return function( addr, port, listener, pattern, sslctx, startssl ) -- TODO: check arguments
720 --vdebug( "creating new tcp server with following parameters:", addr or "nil", port or "nil", sslcfg or "nil", startssl or "nil") 720 --vdebug( "creating new tcp server with following parameters:", addr or "nil", port or "nil", sslctx or "nil", startssl or "nil")
721 if sslctx and not has_luasec then
722 debug "fatal error: luasec not found"
723 return nil, "luasec not found"
724 end
721 local server, err = socket.bind( addr, port, cfg.ACCEPT_QUEUE ) -- create server socket 725 local server, err = socket.bind( addr, port, cfg.ACCEPT_QUEUE ) -- create server socket
722 if not server then 726 if not server then
723 debug( "creating server socket on "..addr.." port "..port.." failed:", err ) 727 debug( "creating server socket on "..addr.." port "..port.." failed:", err )
724 return nil, err 728 return nil, err
725 end
726 local sslctx
727 if sslcfg then
728 if not has_luasec then
729 debug "fatal error: luasec not found"
730 return nil, "luasec not found"
731 end
732 sslctx, err = sslcfg
733 if err then
734 debug( "error while creating new ssl context for server socket:", err )
735 return nil, err
736 end
737 end 729 end
738 local interface = handleserver( server, addr, port, pattern, listener, sslctx, startssl ) -- new server handler 730 local interface = handleserver( server, addr, port, pattern, listener, sslctx, startssl ) -- new server handler
739 debug( "new server created with id:", tostring(interface)) 731 debug( "new server created with id:", tostring(interface))
740 return interface 732 return interface
741 end 733 end
749 return interface, client 741 return interface, client
750 --function handleclient( client, ip, port, server, pattern, listener, _, sslctx ) -- creates an client interface 742 --function handleclient( client, ip, port, server, pattern, listener, _, sslctx ) -- creates an client interface
751 end 743 end
752 744
753 function addclient( addr, serverport, listener, pattern, sslctx ) 745 function addclient( addr, serverport, listener, pattern, sslctx )
754 if sslctx and not ssl then 746 if sslctx and not has_luasec then
755 debug "need luasec, but not available" 747 debug "need luasec, but not available"
756 return nil, "luasec not found" 748 return nil, "luasec not found"
757 end 749 end
758 local client, err = socket.tcp() -- creating new socket 750 local client, err = socket.tcp() -- creating new socket
759 if not client then 751 if not client then