Software /
code /
prosody
Comparison
net/server_select.lua @ 3491:e8c06d20a18b
net.server_select: Add server.step() to run through a single iteration of the event loop
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Thu, 09 Sep 2010 20:10:28 +0100 |
parent | 3458:9c3ae41e696c |
child | 3543:90b21508ac27 |
comparison
equal
deleted
inserted
replaced
3490:957b40dc6d7c | 3491:e8c06d20a18b |
---|---|
785 | 785 |
786 stats = function( ) | 786 stats = function( ) |
787 return _readtraffic, _sendtraffic, _readlistlen, _sendlistlen, _timerlistlen | 787 return _readtraffic, _sendtraffic, _readlistlen, _sendlistlen, _timerlistlen |
788 end | 788 end |
789 | 789 |
790 local dontstop = true; -- thinking about tomorrow, ... | 790 local quitting; |
791 | 791 |
792 setquitting = function (quit) | 792 setquitting = function (quit) |
793 dontstop = not quit; | 793 quitting = not not quit; |
794 return; | 794 end |
795 end | 795 |
796 | 796 loop = function(once) -- this is the main loop of the program |
797 loop = function( ) -- this is the main loop of the program | 797 if quitting then return "quitting"; end |
798 while dontstop do | 798 if once then quitting = "once"; end |
799 repeat | |
799 local read, write, err = socket_select( _readlist, _sendlist, _selecttimeout ) | 800 local read, write, err = socket_select( _readlist, _sendlist, _selecttimeout ) |
800 for i, socket in ipairs( write ) do -- send data waiting in writequeues | 801 for i, socket in ipairs( write ) do -- send data waiting in writequeues |
801 local handler = _socketlist[ socket ] | 802 local handler = _socketlist[ socket ] |
802 if handler then | 803 if handler then |
803 handler.sendbuffer( ) | 804 handler.sendbuffer( ) |
827 end | 828 end |
828 _timer = _currenttime | 829 _timer = _currenttime |
829 end | 830 end |
830 socket_sleep( _sleeptime ) -- wait some time | 831 socket_sleep( _sleeptime ) -- wait some time |
831 --collectgarbage( ) | 832 --collectgarbage( ) |
832 end | 833 until quitting; |
834 if once and quitting == "once" then quitting = nil; return; end | |
833 return "quitting" | 835 return "quitting" |
836 end | |
837 | |
838 step = function () | |
839 return loop(true); | |
834 end | 840 end |
835 | 841 |
836 local function get_backend() | 842 local function get_backend() |
837 return "select"; | 843 return "select"; |
838 end | 844 end |