Software / code / prosody
Comparison
net/server_select.lua @ 5486:bcf27dbef6c6
net.server_select: Add and improve some comments.
| author | Waqas Hussain <waqas20@gmail.com> |
|---|---|
| date | Tue, 16 Apr 2013 18:18:22 -0400 |
| parent | 5485:5147eed0a42e |
| child | 5491:55faa2fd5549 |
comparison
equal
deleted
inserted
replaced
| 5485:5147eed0a42e | 5486:bcf27dbef6c6 |
|---|---|
| 845 handler:force_close() -- forced disconnect | 845 handler:force_close() -- forced disconnect |
| 846 _closelist[ handler ] = nil; | 846 _closelist[ handler ] = nil; |
| 847 end | 847 end |
| 848 _currenttime = luasocket_gettime( ) | 848 _currenttime = luasocket_gettime( ) |
| 849 | 849 |
| 850 -- Check for socket timeouts | |
| 850 local difftime = os_difftime( _currenttime - _starttime ) | 851 local difftime = os_difftime( _currenttime - _starttime ) |
| 851 if difftime > _checkinterval then | 852 if difftime > _checkinterval then |
| 852 _starttime = _currenttime | 853 _starttime = _currenttime |
| 853 for handler, timestamp in pairs( _writetimes ) do | 854 for handler, timestamp in pairs( _writetimes ) do |
| 854 if os_difftime( _currenttime - timestamp ) > _sendtimeout then | 855 if os_difftime( _currenttime - timestamp ) > _sendtimeout then |
| 864 handler:close( ) -- forced disconnect? | 865 handler:close( ) -- forced disconnect? |
| 865 end | 866 end |
| 866 end | 867 end |
| 867 end | 868 end |
| 868 | 869 |
| 870 -- Fire timers | |
| 869 if _currenttime - _timer >= math_min(next_timer_time, 1) then | 871 if _currenttime - _timer >= math_min(next_timer_time, 1) then |
| 870 next_timer_time = math_huge; | 872 next_timer_time = math_huge; |
| 871 for i = 1, _timerlistlen do | 873 for i = 1, _timerlistlen do |
| 872 local t = _timerlist[ i ]( _currenttime ) -- fire timers | 874 local t = _timerlist[ i ]( _currenttime ) -- fire timers |
| 873 if t then next_timer_time = math_min(next_timer_time, t); end | 875 if t then next_timer_time = math_min(next_timer_time, t); end |
| 874 end | 876 end |
| 875 _timer = _currenttime | 877 _timer = _currenttime |
| 876 else | 878 else |
| 877 next_timer_time = next_timer_time - (_currenttime - _timer); | 879 next_timer_time = next_timer_time - (_currenttime - _timer); |
| 878 end | 880 end |
| 879 socket_sleep( _sleeptime ) -- wait some time | 881 |
| 880 --collectgarbage( ) | 882 -- wait some time (0 by default) |
| 883 socket_sleep( _sleeptime ) | |
| 881 until quitting; | 884 until quitting; |
| 882 if once and quitting == "once" then quitting = nil; return; end | 885 if once and quitting == "once" then quitting = nil; return; end |
| 883 return "quitting" | 886 return "quitting" |
| 884 end | 887 end |
| 885 | 888 |