Comparison

net/server.lua @ 658:1952fdcf1017

Fix specifying ports in config, and SSL support
author Matthew Wild <mwild1@gmail.com>
date Sat, 27 Dec 2008 21:20:09 +0000
parent 657:7f1946174d4b
child 659:c424bec771d9
comparison
equal deleted inserted replaced
657:7f1946174d4b 658:1952fdcf1017
92 92
93 stats = function( ) 93 stats = function( )
94 return receivestat, sendstat 94 return receivestat, sendstat
95 end 95 end
96 96
97 wrapserver = function( listener, socket, ip, serverport, mode, sslctx ) -- this function wraps a server 97 wrapserver = function( listener, socket, ip, serverport, mode, sslctx, wrapper_function ) -- this function wraps a server
98 98
99 local dispatch, disconnect = listener.listener, listener.disconnect -- dangerous 99 local dispatch, disconnect = listener.listener, listener.disconnect -- dangerous
100 100
101 local wrapclient, err 101 local wrapclient, err
102 102
103 out_put("Starting a new server on "..tostring(serverport).." with ssl: "..tostring(sslctx)); 103 out_put("Starting a new server on "..tostring(serverport).." with ssl: "..tostring(sslctx));
104 104 out_put(traceback())
105 if sslctx then 105 if sslctx then
106 if not ssl_newcontext then 106 if not ssl_newcontext then
107 return nil, "luasec not found" 107 return nil, "luasec not found"
108 end 108 end
109 if type( sslctx ) ~= "table" then 109 if type( sslctx ) ~= "table" then
114 if not sslctx then 114 if not sslctx then
115 err = err or "wrong sslctx parameters" 115 err = err or "wrong sslctx parameters"
116 out_error( "server.lua: ", err ) 116 out_error( "server.lua: ", err )
117 return nil, err 117 return nil, err
118 end 118 end
119 end
120
121 if wrapper_function then
122 wrapclient = wrapper_function
123 elseif sslctx then
119 wrapclient = wrapsslclient 124 wrapclient = wrapsslclient
120 wrapclient = wraptlsclient
121 else 125 else
122 wrapclient = wraptcpclient 126 wrapclient = wraptcpclient
123 end 127 end
124 128
125 local accept = socket.accept 129 local accept = socket.accept
126 local close = socket.close 130 local close = socket.close
127 131
128 --// public methods of the object //-- 132 --// public methods of the object //--
129 133
766 for i, listener in ipairs( timelistener ) do 770 for i, listener in ipairs( timelistener ) do
767 listener( ) 771 listener( )
768 end 772 end
769 end 773 end
770 774
771 addserver = function( listeners, port, addr, mode, sslctx ) -- this function provides a way for other scripts to reg a server 775 addserver = function( listeners, port, addr, mode, sslctx, wrapper_function ) -- this function provides a way for other scripts to reg a server
772 local err 776 local err
773 if type( listeners ) ~= "table" then 777 if type( listeners ) ~= "table" then
774 err = "invalid listener table" 778 err = "invalid listener table"
775 else 779 else
776 for name, func in pairs( listeners ) do 780 for name, func in pairs( listeners ) do
795 local server, err = socket_bind( addr, port ) 799 local server, err = socket_bind( addr, port )
796 if err then 800 if err then
797 out_error( "server.lua: ", err ) 801 out_error( "server.lua: ", err )
798 return nil, err 802 return nil, err
799 end 803 end
800 local handler, err = wrapserver( listeners, server, addr, port, mode, sslctx ) -- wrap new server socket 804 local handler, err = wrapserver( listeners, server, addr, port, mode, sslctx, wrapper_function ) -- wrap new server socket
801 if not handler then 805 if not handler then
802 server:close( ) 806 server:close( )
803 return nil, err 807 return nil, err
804 end 808 end
805 server:settimeout( 0 ) 809 server:settimeout( 0 )
875 loop = loop, 879 loop = loop,
876 stats = stats, 880 stats = stats,
877 closeall = closeall, 881 closeall = closeall,
878 addtimer = addtimer, 882 addtimer = addtimer,
879 wraptcpclient = wraptcpclient, 883 wraptcpclient = wraptcpclient,
884 wrapsslclient = wrapsslclient,
880 wraptlsclient = wraptlsclient, 885 wraptlsclient = wraptlsclient,
881 } 886 }