MCPcopy Create free account
hub / github.com/EasyIME/PIME / _handle_connection

Method _handle_connection

python/python3/tornado/tcpserver.py:344–394  ·  view source on GitHub ↗
(self, connection: socket.socket, address: Any)

Source from the content-addressed store, hash-verified

342 raise NotImplementedError()
343
344 def _handle_connection(self, connection: socket.socket, address: Any) -> None:
345 if self.ssl_options is not None:
346 assert ssl, "Python 2.6+ and OpenSSL required for SSL"
347 try:
348 connection = ssl_wrap_socket(
349 connection,
350 self.ssl_options,
351 server_side=True,
352 do_handshake_on_connect=False,
353 )
354 except ssl.SSLError as err:
355 if err.args[0] == ssl.SSL_ERROR_EOF:
356 return connection.close()
357 else:
358 raise
359 except socket.error as err:
360 # If the connection is closed immediately after it is created
361 # (as in a port scan), we can get one of several errors.
362 # wrap_socket makes an internal call to getpeername,
363 # which may return either EINVAL (Mac OS X) or ENOTCONN
364 # (Linux). If it returns ENOTCONN, this error is
365 # silently swallowed by the ssl module, so we need to
366 # catch another error later on (AttributeError in
367 # SSLIOStream._do_ssl_handshake).
368 # To test this behavior, try nmap with the -sT flag.
369 # https://github.com/tornadoweb/tornado/pull/750
370 if errno_from_exception(err) in (errno.ECONNABORTED, errno.EINVAL):
371 return connection.close()
372 else:
373 raise
374 try:
375 if self.ssl_options is not None:
376 stream = SSLIOStream(
377 connection,
378 max_buffer_size=self.max_buffer_size,
379 read_chunk_size=self.read_chunk_size,
380 ) # type: IOStream
381 else:
382 stream = IOStream(
383 connection,
384 max_buffer_size=self.max_buffer_size,
385 read_chunk_size=self.read_chunk_size,
386 )
387
388 future = self.handle_stream(stream, address)
389 if future is not None:
390 IOLoop.current().add_future(
391 gen.convert_yielded(future), lambda f: f.result()
392 )
393 except Exception:
394 app_log.error("Error in connection callback", exc_info=True)

Callers

nothing calls this directly

Calls 10

handle_streamMethod · 0.95
ssl_wrap_socketFunction · 0.90
errno_from_exceptionFunction · 0.90
SSLIOStreamClass · 0.90
IOStreamClass · 0.90
add_futureMethod · 0.80
currentMethod · 0.80
resultMethod · 0.80
errorMethod · 0.80
closeMethod · 0.45

Tested by

no test coverage detected