| Server IP : 54.37.205.81 / Your IP : 216.73.216.76 Web Server : nginx/1.22.1 System : Linux vps-249481fa 6.1.0-50-cloud-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.176-1 (2026-07-02) x86_64 User : debian ( 1000) PHP Version : 8.2.32 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /lib/python3/dist-packages/tornado/__pycache__/ |
Upload File : |
�
��b�; � �� � d Z ddlZddlZddlZddlZddlmZ ddlmZ ddl m
Z
ddlmZm
Z
ddlmZmZmZmZ ddlmZ dd lmZ ddlZdd
lmZmZmZmZmZmZ ej rddlmZmZ G d� d
e � � Z!dS )z+A non-blocking, single-threaded TCP server.� N)�gen)�app_log)�IOLoop)�IOStream�SSLIOStream)�bind_sockets�add_accept_handler�ssl_wrap_socket�_DEFAULT_BACKLOG)�process)�errno_from_exception)�Union�Dict�Any�Iterable�Optional� Awaitable)�Callable�Listc � � e Zd ZdZ ddeeeeef e j
f dee dee ddfd�Zde
j eddfd ed
ee de
j ded
ee deddfd�Zdee
j
ddfd�Zde
j
ddfd�Zde
j eddfd ed
ee de
j ded
ee deddfd�Z ddee dee ddfd�Zd d�Zded
edeed fd�Zde
j
d
eddfd�ZdS )!� TCPServeraC A non-blocking, single-threaded TCP server.
To use `TCPServer`, define a subclass which overrides the `handle_stream`
method. For example, a simple echo server could be defined like this::
from tornado.tcpserver import TCPServer
from tornado.iostream import StreamClosedError
class EchoServer(TCPServer):
async def handle_stream(self, stream, address):
while True:
try:
data = await stream.read_until(b"\n") await
stream.write(data)
except StreamClosedError:
break
To make this server serve SSL traffic, send the ``ssl_options`` keyword
argument with an `ssl.SSLContext` object. For compatibility with older
versions of Python ``ssl_options`` may also be a dictionary of keyword
arguments for the `ssl.wrap_socket` method.::
ssl_ctx = ssl.create_default_context(ssl.Purpose.CLIENT_AUTH)
ssl_ctx.load_cert_chain(os.path.join(data_dir, "mydomain.crt"),
os.path.join(data_dir, "mydomain.key"))
TCPServer(ssl_options=ssl_ctx)
`TCPServer` initialization follows one of three patterns:
1. `listen`: single-process::
async def main():
server = TCPServer()
server.listen(8888)
await asyncio.Event.wait()
asyncio.run(main())
While this example does not create multiple processes on its own, when
the ``reuse_port=True`` argument is passed to ``listen()`` you can run
the program multiple times to create a multi-process service.
2. `add_sockets`: multi-process::
sockets = bind_sockets(8888)
tornado.process.fork_processes(0)
async def post_fork_main():
server = TCPServer()
server.add_sockets(sockets)
await asyncio.Event().wait()
asyncio.run(post_fork_main())
The `add_sockets` interface is more complicated, but it can be used with
`tornado.process.fork_processes` to run a multi-process service with all
worker processes forked from a single parent. `add_sockets` can also be
used in single-process servers if you want to create your listening
sockets in some way other than `~tornado.netutil.bind_sockets`.
Note that when using this pattern, nothing that touches the event loop
can be run before ``fork_processes``.
3. `bind`/`start`: simple **deprecated** multi-process::
server = TCPServer()
server.bind(8888)
server.start(0) # Forks multiple sub-processes
IOLoop.current().start()
This pattern is deprecated because it requires interfaces in the
`asyncio` module that have been deprecated since Python 3.10. Support for
creating multiple processes in the ``start`` method will be removed in a
future version of Tornado.
.. versionadded:: 3.1
The ``max_buffer_size`` argument.
.. versionchanged:: 5.0
The ``io_loop`` argument has been removed.
N�ssl_options�max_buffer_size�read_chunk_size�returnc �" � || _ i | _ i | _ g | _ d| _ d| _ || _ || _ | j ��t | j t � � r�d| j vrt d� � �t j �
| j d � � st d| j d z � � �d| j v rKt j �
| j d � � s#t d| j d z � � �d S d S d S d S )NF�certfilez%missing key "certfile" in ssl_optionszcertfile "%s" does not exist�keyfilezkeyfile "%s" does not exist)r �_sockets� _handlers�_pending_sockets�_started�_stoppedr r �
isinstance�dict�KeyError�os�path�exists�
ValueError)�selfr r r s �3/usr/lib/python3/dist-packages/tornado/tcpserver.py�__init__zTCPServer.__init__| s* � � '�����
���� "�����
���
�.���.��� ��'�J�t�7G��,N�,N�'���!1�1�1��F�G�G�G��7�>�>�$�"2�:�">�?�?�
� �2�T�5E�j�5Q�Q�� � � �D�,�,�,�R�W�^�^�� ��+�6� 6�,� !�1�D�4D�Y�4O�O�� � � (�'�'�'� -�,�,�,� F�port�address�family�backlog�flags�
reuse_portc �Z � t ||||||�� � }| � |� � dS )aP Starts accepting connections on the given port.
This method may be called more than once to listen on multiple ports.
`listen` takes effect immediately; it is not necessary to call
`TCPServer.start` afterwards. It is, however, necessary to start the
event loop if it is not already running.
All arguments have the same meaning as in
`tornado.netutil.bind_sockets`.
.. versionchanged:: 6.2
Added ``family``, ``backlog``, ``flags``, and ``reuse_port``
arguments to match `tornado.netutil.bind_sockets`.
�r0 r1 r2 r3 r4 N)r �add_sockets�r+ r/ r0 r1 r2 r3 r4 �socketss r, �listenzTCPServer.listen� sF � �0 ������!�
�
�
��
����!�!�!�!�!r. r9 c � � |D ]M}|| j |� � � <