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