o
    ڷi                     @  s   d Z ddlmZ ddlZddlmZmZmZ ddlZddl	Zddl
mZ G dd deZdddZdddZe	dd ddZe	dd!ddZ	dd"ddZddgZdS )#zJModule holding utility and convenience functions for zmq event monitoring.    )annotationsN)	Awaitable	TypedDictoverload)_check_versionc                   @  s&   e Zd ZU ded< ded< ded< dS )_MonitorMessageinteventvaluebytesendpointN)__name__
__module____qualname____annotations__ r   r   G/home/ubuntu/vllm_env/lib/python3.10/site-packages/zmq/utils/monitor.pyr      s   
 r   msglist[bytes]returnc                 C  s^   t | dkst | d dkrtd|  td| d \}}t|t|| d d}|S )a  decode zmq_monitor event messages.

    Parameters
    ----------
    msg : list(bytes)
        zmq multipart message that has arrived on a monitor PAIR socket.

        First frame is::

            16 bit event id
            32 bit event value
            no padding

        Second frame is the endpoint as a bytestring

    Returns
    -------
    event : dict
        event description as dict with the keys `event`, `value`, and `endpoint`.
       r      zInvalid event message format: z=hi   )r	   r
   r   )lenRuntimeErrorstructunpackzmqEvent)r   event_idr
   r	   r   r   r   parse_monitor_message   s   r    awaitable_msgAwaitable[list[bytes]]c                   s   | I dH }t |S )zyLike parse_monitor_msg, but awaitable

    Given awaitable message, return awaitable for the parsed monitor message.
    N)r    )r!   r   r   r   r   _parse_monitor_msg_async6   s   
r#   socketzmq.asyncio.Socketflagsr   Awaitable[_MonitorMessage]c                 C     d S Nr   r$   r&   r   r   r   recv_monitor_messageC      r+   zmq.Socket[bytes]c                 C  r(   r)   r   r*   r   r   r   r+   J   r,   
zmq.Socket,_MonitorMessage | Awaitable[_MonitorMessage]c                 C  s.   t dd | |}t|trt|S t|S )u  Receive and decode the given raw message from the monitoring socket and return a dict.

    Requires libzmq ≥ 4.0

    The returned dict will have the following entries:
      event : int
        the event id as described in `libzmq.zmq_socket_monitor`
      value : int
        the event value associated with the event, see `libzmq.zmq_socket_monitor`
      endpoint : str
        the affected endpoint

    .. versionchanged:: 23.1
        Support for async sockets added.
        When called with a async socket,
        returns an awaitable for the monitor message.

    Parameters
    ----------
    socket : zmq.Socket
        The PAIR socket (created by other.get_monitor_socket()) on which to recv the message
    flags : int
        standard zmq recv flags

    Returns
    -------
    event : dict
        event description as dict with the keys `event`, `value`, and `endpoint`.
    )   r   zlibzmq event API)r   recv_multipart
isinstancer   r#   r    )r$   r&   r   r   r   r   r+   Q   s
   
"

)r   r   r   r   )r!   r"   r   r   )r   )r$   r%   r&   r   r   r'   )r$   r-   r&   r   r   r   )r$   r.   r&   r   r   r/   )__doc__
__future__r   r   typingr   r   r   r   zmq.asyncio	zmq.errorr   r   r    r#   r+   __all__r   r   r   r   <module>   s&    

 /