Software /
code /
prosody
Comparison
net/server_select.lua @ 7094:e8f202856fc0
server_select: Keep track of which server listeners are full
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Fri, 22 Jan 2016 01:58:39 +0100 |
parent | 6381:9ffd582c65d8 |
child | 7095:3e1dac35af87 |
comparison
equal
deleted
inserted
replaced
7093:388281be2bc7 | 7094:e8f202856fc0 |
---|---|
86 local _sendlist | 86 local _sendlist |
87 local _socketlist | 87 local _socketlist |
88 local _closelist | 88 local _closelist |
89 local _readtimes | 89 local _readtimes |
90 local _writetimes | 90 local _writetimes |
91 local _fullservers | |
91 | 92 |
92 --// simple data types //-- | 93 --// simple data types //-- |
93 | 94 |
94 local _ | 95 local _ |
95 local _readlistlen | 96 local _readlistlen |
128 _timerlist = { } -- array of timer functions | 129 _timerlist = { } -- array of timer functions |
129 _socketlist = { } -- key = socket, value = wrapped socket (handlers) | 130 _socketlist = { } -- key = socket, value = wrapped socket (handlers) |
130 _readtimes = { } -- key = handler, value = timestamp of last data reading | 131 _readtimes = { } -- key = handler, value = timestamp of last data reading |
131 _writetimes = { } -- key = handler, value = timestamp of last data writing/sending | 132 _writetimes = { } -- key = handler, value = timestamp of last data writing/sending |
132 _closelist = { } -- handlers to close | 133 _closelist = { } -- handlers to close |
134 _fullservers = { } -- servers in a paused state while there are too many clients | |
133 | 135 |
134 _readlistlen = 0 -- length of readlist | 136 _readlistlen = 0 -- length of readlist |
135 _sendlistlen = 0 -- length of sendlist | 137 _sendlistlen = 0 -- length of sendlist |
136 _timerlistlen = 0 -- lenght of timerlist | 138 _timerlistlen = 0 -- lenght of timerlist |
137 | 139 |
217 socket = socket_bind( ip, serverport, _tcpbacklog ); | 219 socket = socket_bind( ip, serverport, _tcpbacklog ); |
218 socket:settimeout( 0 ) | 220 socket:settimeout( 0 ) |
219 end | 221 end |
220 _readlistlen = addsocket(_readlist, socket, _readlistlen) | 222 _readlistlen = addsocket(_readlist, socket, _readlistlen) |
221 _socketlist[ socket ] = handler | 223 _socketlist[ socket ] = handler |
224 _fullservers[ handler ] = nil | |
222 handler.paused = false; | 225 handler.paused = false; |
223 end | 226 end |
224 end | 227 end |
225 handler.ip = function( ) | 228 handler.ip = function( ) |
226 return ip | 229 return ip |
232 return socket | 235 return socket |
233 end | 236 end |
234 handler.readbuffer = function( ) | 237 handler.readbuffer = function( ) |
235 if _readlistlen >= _maxselectlen or _sendlistlen >= _maxselectlen then | 238 if _readlistlen >= _maxselectlen or _sendlistlen >= _maxselectlen then |
236 handler.pause( ) | 239 handler.pause( ) |
240 _fullservers[ handler ] = _currenttime | |
237 out_put( "server.lua: refused new client connection: server full" ) | 241 out_put( "server.lua: refused new client connection: server full" ) |
238 return false | 242 return false |
239 end | 243 end |
240 local client, err = accept( socket ) -- try to accept | 244 local client, err = accept( socket ) -- try to accept |
241 if client then | 245 if client then |
262 | 266 |
263 if socket:getfd() >= _maxfd then | 267 if socket:getfd() >= _maxfd then |
264 out_error("server.lua: Disallowed FD number: "..socket:getfd()) -- PROTIP: Switch to libevent | 268 out_error("server.lua: Disallowed FD number: "..socket:getfd()) -- PROTIP: Switch to libevent |
265 socket:close( ) -- Should we send some kind of error here? | 269 socket:close( ) -- Should we send some kind of error here? |
266 if server then | 270 if server then |
271 _fullservers[ server ] = _currenttime | |
267 server.pause( ) | 272 server.pause( ) |
268 end | 273 end |
269 return nil, nil, "fd-too-large" | 274 return nil, nil, "fd-too-large" |
270 end | 275 end |
271 socket:settimeout( 0 ) | 276 socket:settimeout( 0 ) |