MCPcopy
hub / github.com/opendevops-cn/opendevops / accept_handler

Function accept_handler

scripts/tornado_source_code/tornado/netutil.py:243–273  ·  view source on GitHub ↗
(fd: socket.socket, events: int)

Source from the content-addressed store, hash-verified

241 removed = [False]
242
243 def accept_handler(fd: socket.socket, events: int) -> None:
244 # More connections may come in while we're handling callbacks;
245 # to prevent starvation of other tasks we must limit the number
246 # of connections we accept at a time. Ideally we would accept
247 # up to the number of connections that were waiting when we
248 # entered this method, but this information is not available
249 # (and rearranging this method to call accept() as many times
250 # as possible before running any callbacks would have adverse
251 # effects on load balancing in multiprocess configurations).
252 # Instead, we use the (default) listen backlog as a rough
253 # heuristic for the number of connections we can reasonably
254 # accept at once.
255 for i in range(_DEFAULT_BACKLOG):
256 if removed[0]:
257 # The socket was probably closed
258 return
259 try:
260 connection, address = sock.accept()
261 except socket.error as e:
262 # _ERRNO_WOULDBLOCK indicate we have accepted every
263 # connection that is available.
264 if errno_from_exception(e) in _ERRNO_WOULDBLOCK:
265 return
266 # ECONNABORTED indicates that there was a connection
267 # but it was closed while still in the accept queue.
268 # (observed on FreeBSD).
269 if errno_from_exception(e) == errno.ECONNABORTED:
270 continue
271 raise
272 set_close_exec(connection.fileno())
273 callback(connection, address)
274
275 def remove_handler() -> None:
276 io_loop.remove_handler(sock)

Callers

nothing calls this directly

Calls 5

errno_from_exceptionFunction · 0.90
callbackFunction · 0.85
acceptMethod · 0.80
set_close_execFunction · 0.50
filenoMethod · 0.45

Tested by

no test coverage detected