HEX
Server: Apache
System: Linux server2.voipitup.com.au 4.18.0-553.104.1.lve.el8.x86_64 #1 SMP Tue Feb 10 20:07:30 UTC 2026 x86_64
User: posscale (1027)
PHP: 8.2.29
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/cheroot/__pycache__/connections.cpython-310.pyc
o

�N�g�3�@s.dZddlmZmZmZeZddlZddlZddl	Z	ddl
Z
ddlZddlm
Z
ddlmZddlmZddlmZddlZzddlZWn>ey�z#dd	lmZmZddlZejjZejjejjejjge_ ejj!e_"Wn
ey{d
d�Z#Ynwdd�Z#Ynwd
d�Z#Gdd�d�Z$Gdd�d�Z%dS)z%Utilities to manage open connections.�)�absolute_import�division�print_functionN�)�errors)�	selectors)�suppress)�MakeFile)�windll�WinErrorcCsdS)ztStub inheritance prevention.

            Dummy function, since neither fcntl nor ctypes are available.
            N���sockrr�G/opt/saltstack/salt/lib/python3.10/site-packages/cheroot/connections.py�prevent_socket_inheritance!srcCst|��dd�st��dS)z6Mark the given socket fd as non-inheritable (Windows).rrN)�_SetHandleInformation�filenorr
rrrr(s�cCs0|��}t�|tj�}t�|tj|tjB�dS)z4Mark the given socket fd as non-inheritable (POSIX).N)r�fcntl�F_GETFD�F_SETFD�
FD_CLOEXEC)r�fdZ	old_flagsrrrr-sc@sPeZdZdZdd�Zdd�Zedd��Zdd	d
�Zdd�Z	dd
d�Z
dd�ZdS)�_ThreadsafeSelectora�Thread-safe wrapper around a DefaultSelector.

    There are 2 thread contexts in which it may be accessed:
      * the selector thread
      * one of the worker threads in workers/threadpool.py

    The expected read/write patterns are:
      * :py:func:`~iter`: selector thread
      * :py:meth:`register`: selector thread and threadpool,
        via :py:meth:`~cheroot.workers.threadpool.ThreadPool.put`
      * :py:meth:`unregister`: selector thread only

    Notably, this means :py:class:`_ThreadsafeSelector` never needs to worry
    that connections will be removed behind its back.

    The lock is held when iterating or modifying the selector but is not
    required when :py:meth:`select()ing <selectors.BaseSelector.select>` on it.
    cCst��|_t��|_dS�N)r�DefaultSelector�	_selector�	threading�Lock�_lock��selfrrr�__init__Hs
z_ThreadsafeSelector.__init__cCs<|j�t|j��pi�Wd�S1swYdSr)r�lenr�get_maprrrr�__len__Ls$�z_ThreadsafeSelector.__len__ccs`�|j�"|j��pi}|��D]
\}\}}}}||fVqWd�dS1s)wYdS)z2Retrieve connections registered with the selector.N)rrr#�items)r �mapping�_�sock_fd�connrrr�connectionsPs��"�z_ThreadsafeSelector.connectionsNcCs:|j�|j�|||�Wd�S1swYdS)z'Register ``fileobj`` with the selector.N)rr�register)r �fileobj�events�datarrrr+Xs$�z_ThreadsafeSelector.registercCs6|j�|j�|�Wd�S1swYdS)z)Unregister ``fileobj`` from the selector.N)rr�
unregister)r r,rrrr/]s
$�z_ThreadsafeSelector.unregistercCsdd�|jj|d�D�S)z�Return socket fd and data pairs from selectors.select call.

        Returns entries ready to read in the form:
            (socket_file_descriptor, connection)
        css �|]\}}|j|jfVqdSr)rr.)�.0�keyr'rrr�	<genexpr>hs
�
�
�z-_ThreadsafeSelector.select.<locals>.<genexpr>��timeout)r�select)r r4rrrr5bs�z_ThreadsafeSelector.selectcCs6|j�|j��Wd�dS1swYdS)zClose the selector.N)rr�closerrrrr6ms"�z_ThreadsafeSelector.closer)�__name__�
__module__�__qualname__�__doc__r!r$�propertyr*r+r/r5r6rrrrr4s


rc@speZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Ze
dd��Ze
dd��ZdS)�ConnectionManagerz�Class which manages HTTPConnection objects.

    This is for connections which are being kept-alive for follow-up requests.
    cCs8d|_d|_||_t�|_|jj|j��tj	|d�dS)z�Initialize ConnectionManager object.

        Args:
            server (cheroot.server.HTTPServer): web server object
                that uses this ConnectionManager instance.
        F�r.N)
�_serving�_stop_requested�serverrrr+�socketrr�
EVENT_READ)r r@rrrr!ys
�zConnectionManager.__init__cCsBt��|_|j��r|j�|�dS|jj|j�	�t
j|d�dS)z�Put idle connection into the ConnectionManager to be managed.

        :param conn: HTTP connection to be managed
        :type conn: cheroot.server.HTTPConnection
        r=N)�time�	last_usedZrfileZhas_datar@�process_connrr+rArrrB)r r)rrr�put�s


�zConnectionManager.putcsNt���jj���fdd��jjD�}|D]\}}�j�|�|��qdS)z�Expire least recently used connections.

        This happens if there are either too many open connections, or if the
        connections have been timed out.

        This should be called periodically.
        cs,g|]\}}|�jkr|j�kr||f�qSr)r@rD)r0r(r)�r Z	thresholdrr�
<listcomp>�s
�z-ConnectionManager._expire.<locals>.<listcomp>N)rCr@r4rr*r/r6)r Ztimed_out_connectionsr(r)rrGr�_expire�s
�
�zConnectionManager._expirecCs$d|_|jrt�d�|jsdSdS)z^Stop the selector loop in run() synchronously.

        May take up to half a second.
        T�{�G�z�?N)r?r>rC�sleeprrrr�stop�s
�zConnectionManager.stopcCs&d|_z|�|�Wd|_dSd|_w)a�Run the connections selector indefinitely.

        Args:
            expiration_interval (float): Interval, in seconds, at which
                connections will be checked for expiration.

        Connections that are ready to process are submitted via
        self.server.process_conn()

        Connections submitted for processing must be `put()`
        back if they should be examined again for another request.

        Can be shut down by calling `stop()`.
        TFN)r>�_run)r �expiration_intervalrrr�run�szConnectionManager.runcCs�t��}|js]z	|jjdd�}Wn
ty|��Yqw|D]'\}}||jur;|�|jj�}|dur:|j�	|�q |j�
|�|j�	|�q t��}|||krX|��|}|jrdSdS)NrJr3)rCr?rr5�OSError�_remove_invalid_socketsr@�_from_server_socketrArEr/rI)r rNZlast_expiration_checkZactive_listr(r)Znew_conn�nowrrrrM�s*�
��zConnectionManager._runc	Cs�g}|jjD]!\}}||jurqzt�|�Wqty'|�||f�Yqw|D]#\}}|j�|�tt	j
��|��Wd�n1sHwYq*dS)aClean up the resources of any broken connections.

        This method attempts to detect any connections in an invalid state,
        unregisters them from the selector and closes the file descriptors of
        the corresponding network sockets where possible.
        N)rr*r@�os�fstatrP�appendr/rrA�errorr6)r Z
invalid_connsr(r)rrrrQ�s 
�
���z)ConnectionManager._remove_invalid_socketsc
Csrz�|��\}}|jjdr|jjdd7<t|�t|d�r'|�|jj�t}i}|jjdur�z|jj�	|�\}}WnWt
jy�d}d|jjdt
|�d|g}tjsY|n|j}||d	tj�}	z|	�d
�|��d��WYWdStjy�}
z|
jdt
jvr��WYd}
~
YWdSd}
~
www|s�WdS|jjj}t|d�r�|�|jj�|j�|j||�}t|jjtjtjf�s�|dur�t
|� ��d
kr�d}nd}|d|_!|d|_"||_#|WStjy�YdStj�y8}
zB|jjd�r|jjdd7<|
jdt
j$v�rWYd}
~
dS|
jdt
j%v�r#WYd}
~
dS|
jdt
jv�r3WYd}
~
dS�d}
~
ww)NZEnabledZAcceptsr�
settimeoutzUThe client sent a plain HTTP request, but this server only speaks HTTPS on this port.z%s 400 Bad Request
zContent-Length: %s
zContent-Type: text/plain

�wb�z
ISO-8859-1r�)z0.0.0.0r)z::rz
Socket Errors)&�acceptr@Zstatsr�hasattrrXr4r	Zssl_adapter�wraprZ
NoSSLError�protocolr"�sixZPY2�_sock�io�DEFAULT_BUFFER_SIZE�write�join�encoderArW�argsZsocket_errors_to_ignore�makefileZConnectionClass�
isinstanceZ	bind_addrZ	text_typeZbinary_type�getsocknameZremote_addrZremote_port�ssl_envZsocket_error_eintrZsocket_errors_nonblocking)r Z
server_socket�s�addrZmfrk�msg�bufZsock_to_makeZwfile�exr)rrrrRs�
�

��
����


�

��z%ConnectionManager._from_server_socketcCs2|jjD]
\}}||jur|��q|j��dS)z Close all monitored connections.N)rr*r@r6)r r'r)rrrr6\s

�zConnectionManager.closecCst|j�dS)z�Return the current number of connections.

        Includes all connections registered with the selector,
        minus one for the server socket, which is always registered
        with the selector.
        r)r"rrrrr�_num_connectionscsz"ConnectionManager._num_connectionscCs|jj}|dup|j|kS)z>Flag whether it is allowed to add a new keep-alive connection.N)r@Zkeep_alive_conn_limitrq)r Zka_limitrrr�can_add_keepalive_connectionmsz.ConnectionManager.can_add_keepalive_connectionN)r7r8r9r:r!rFrIrLrOrMrQrRr6r;rqrrrrrrr<ss	Z
	r<)&r:Z
__future__rrr�typeZ
__metaclass__rbrTrArrCrZrZ_compatrrrhr	r`r�ImportError�ctypesr
rZctypes.wintypesZkernel32ZSetHandleInformationrZwintypesZHANDLEZDWORD�argtypesZBOOL�restyperrr<rrrr�<module>sD����?