Comparison

net/server.lua @ 989:ec239c044f31

net.server: Add server.setquitting() to gracefully quit the socket loop
author Matthew Wild <mwild1@gmail.com>
date Sun, 12 Apr 2009 02:54:45 +0100
parent 962:872f5d85636e
child 994:8fd4efc3ed96
comparison
equal deleted inserted replaced
988:8cb9a0d59e78 989:ec239c044f31
722 722
723 stats = function( ) 723 stats = function( )
724 return _readtraffic, _sendtraffic, _readlistlen, _sendlistlen, _timerlistlen 724 return _readtraffic, _sendtraffic, _readlistlen, _sendlistlen, _timerlistlen
725 end 725 end
726 726
727 local dontstop = true;
728
729 setquitting = function (quit)
730 dontstop = not quit;
731 return;
732 end
733
727 loop = function( ) -- this is the main loop of the program 734 loop = function( ) -- this is the main loop of the program
728 while true do 735 while dontstop do
736 out_put(tostring(dontstop))
729 local read, write, err = socket_select( _readlist, _sendlist, _selecttimeout ) 737 local read, write, err = socket_select( _readlist, _sendlist, _selecttimeout )
730 for i, socket in ipairs( write ) do -- send data waiting in writequeues 738 for i, socket in ipairs( write ) do -- send data waiting in writequeues
731 local handler = _socketlist[ socket ] 739 local handler = _socketlist[ socket ]
732 if handler then 740 if handler then
733 handler.sendbuffer( ) 741 handler.sendbuffer( )
758 _timer = _currenttime 766 _timer = _currenttime
759 end 767 end
760 socket_sleep( _sleeptime ) -- wait some time 768 socket_sleep( _sleeptime ) -- wait some time
761 --collectgarbage( ) 769 --collectgarbage( )
762 end 770 end
771 return "quitting"
763 end 772 end
764 773
765 --// EXPERIMENTAL //-- 774 --// EXPERIMENTAL //--
766 775
767 local wrapclient = function( socket, ip, serverport, listeners, pattern, sslctx, startssl ) 776 local wrapclient = function( socket, ip, serverport, listeners, pattern, sslctx, startssl )
831 stats = stats, 840 stats = stats,
832 closeall = closeall, 841 closeall = closeall,
833 addtimer = addtimer, 842 addtimer = addtimer,
834 addserver = addserver, 843 addserver = addserver,
835 getsettings = getsettings, 844 getsettings = getsettings,
845 setquitting = setquitting,
836 removeserver = removeserver, 846 removeserver = removeserver,
837 changesettings = changesettings, 847 changesettings = changesettings,
838
839 } 848 }