Yohohohohohooho | Sanrei Aya
Sanrei Aya


Server : LiteSpeed
System : Linux barito.iixcp.rumahweb.net 5.14.0-611.49.1.el9_7.x86_64 #1 SMP PREEMPT_DYNAMIC Tue Apr 21 16:39:08 EDT 2026 x86_64
User : elvh3918 ( 1528)
PHP Version : 8.2.31
Disable Function : mail
Directory :  /opt/cloudlinux/venv/lib/python3.11/site-packages/clwpos/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //opt/cloudlinux/venv/lib/python3.11/site-packages/clwpos/__pycache__/socket_utils.cpython-311.pyc
�

rB��w0��	�0�ddlmZddlZddlZddlZddlZddlZddlmZej	e
��ZdZdZ
dZdejdefd	�Zd
edefd�Zdejded
edeefd�Zdejdeefd�Zdejdeefd�Zdejdefd�ZdS)�)�absolute_importN)�Optionalz>I�
i�sock_object�returnc��d}|�tjtjt	j|����}t	j||��\}}}|S)z�
    Retrieve credentials from SO_PEERCRED option
    :param sock_object: Socket object
    :return: uid of user, which connects to this socket.
    �3I)�
getsockopt�socket�
SOL_SOCKET�SO_PEERCRED�struct�calcsize�unpack)r�_format_string�creds�_�_uids     �py/clwpos/socket_utils.py�get_uid_from_socketr!sM���N��"�"�6�#4�f�6H�&�/�Zh�Ji�Ji�j�j�E���~�u�5�5�J�A�t�Q��K��	data_dictc��tj|���d��}tjt
t
|����|zS)z�
    Prefix message with a 4-byte length
    :param data_dict: Data dict for send
    :return: byte array for send to socket
    �utf-8)�json�dumps�encoder�pack�_format�len)r�	msg_bytess  r�pack_data_for_socketr".s@���
�9�%�%�,�,�W�5�5�I��;�w��I���/�/�)�;�;r�	num_bytes�timeout_secc��|���}tj��|z}t��}	t	|��|kr�|tj��z
}|dkr	|�|��dS|�|��|�|t	|��z
��}|s	|�|��dS||z
}t	|��|k��n+#tj$rY|�|��dSwxYw|�|��n#|�|��wxYw|S)z�
    Read amount data from socket
    :param sock_object: Socket object to read data from
    :param num_bytes: Bytes number to read
    :param timeout_sec: Read timeout, None - timeout expired, data not received
    rN)	�
gettimeout�time�	monotonic�bytesr �
settimeout�recvr�timeout)rr#r$�prev_timeout�deadline�msg�	remaining�chunks        r�$_read_bytes_from_socket_with_timeoutr2;sn���)�)�+�+�L��~���+�-�H�
�'�'�C�
-��#�h�h��"�"� �4�>�#3�#3�3�I��A�~�~��	���|�,�,�,�,�,�
�"�"�9�-�-�-��$�$�Y��S���%9�:�:�E��
��
	���|�,�,�,�,�,�	
�5�L�C��#�h�h��"�"����>��������|�,�,�,�,�,�����	���|�,�,�,�,�����|�,�,�,�,�����Js5�/C.�<C.�C.�-D/�.D�=D/�D�D/�/Ec��t|dt��}|�dStjt|��d}|t
krdSt||t��}|�dSt
j|�d����S)��
    Read length-prefixed amount of data from socket
    :param sock_object: Socket object to read data
    :return: Data received from socket dictionary. None - socket data format error
    �Nrr)	r2�_WPOS_SOCKET_READ_TIMEOUT_SECrrr�
_MAX_MSG_SIZEr�loads�decode�r�
raw_msglen�msglenr/s    r�'read_unpack_response_from_socket_daemonr=Zs��6�k�1�Fc�d�d�J����t�
�]�7�J�
/�
/��
2�F�
�
����t�
.�{�F�Da�
b�
b�C�
�{��t��:�c�j�j��)�)�*�*�*rc��	|�d��}tjt|��d}|tkrdSt��}t
|��|kr+||�d��z
}t
|��|k�+n#tj$rYdSwxYwtj
|�d����S)r4r5rNir)r+rrrr7r)r rr,rr8r9r:s    r�'read_unpack_response_from_socket_clientr?ps���	� �%�%�a�(�(�
���w�
�3�3�A�6���M�!�!��4��g�g���#�h�h�&� � ��;�#�#�D�)�)�)�C��#�h�h�&� � ����>�����t�t������:�c�j�j��)�)�*�*�*s�AB�AB�B$�#B$�
connection�data_to_sendc���	|���dkrdSn#t$rYdSwxYwt|��}	|�t��|�|��n2#t$r%}t�d|��Yd}~nd}~wwxYw	|���dS#t$rYdSwxYw#	|���w#t$rYwwxYwxYw)uS
    Send a dictionary to a socket connection and close it.

    This is a fire-and-forget terminal send. It never re-raises socket
    I/O errors to the caller — callers in daemon.py and
    daemon_subscription_handler.py already treat it that way (no
    try/except around the call). Delivery failures are logged at
    WARNING level only; the socket is always closed on the way out
    (best-effort).

    The function does still propagate programming errors (e.g.,
    TypeError from a non-serializable dict) so they surface during
    development instead of being silently swallowed.
    rNz-Failed to deliver response to socket peer: %s)	�fileno�OSErrorr"r*r6�sendall�logger�warning�close)r@rA�
bytes_to_send�excs    r�(send_dict_to_socket_connection_and_closerK�sR��,�������"�"��F�#�������������
)��6�6�M��	���;�<�<�<����=�)�)�)�)���	M�	M�	M�	���F��L�L�L�L�L�L�L�L�����	M����	�����������	�	�	��D�D�	�����	����������	�	�	��D�	������sq��
+�+�/A.�-C�.
B�8B�C�B�C�!B7�7
C�C�C/�
C�C/�
C,�)C/�+C,�,C/)�
__future__rr�loggingrrr'�typingr�	getLogger�__name__rFrr6r7�intr�dictr)r"r2r=r?rK�rr�<module>rTs���'�&�&�&�&�&���������
�
�
�
�
�
�
�
�����������
��	�8�	$�	$����!#�� �
�
�V�]�
�s�
�
�
�
�
<�D�
<�U�
<�
<�
<�
<��f�m��PS��69��>F�u�o�����>+���+�8�TX�>�+�+�+�+�,+���+�8�TX�>�+�+�+�+�,5���5�VZ�5�5�5�5�5�5r

Yohohohohohooho | Sanrei Aya