HOME


Mini Shell 1.0
DIR: /usr/lib/python3/dist-packages/twisted/internet/iocpreactor/__pycache__/
Upload File :
Current File : //usr/lib/python3/dist-packages/twisted/internet/iocpreactor/__pycache__/udp.cpython-312.pyc
�

Ϫ�f�7���dZddlZddlZddlZddlZddlmZddlmZddl	m
Z
mZmZm
Z
ddlmZmZddlmZmZddlmZmZmZdd	lmZdd
lmZmZeee
j<e
j>e
j@�Gd�dejB��Z"Gd
�d�Z#ee
jH�Gd�de#e"��Z%y)z
UDP support for IOCP reactor
�N)�Optional)�implementer)�address�defer�error�
interfaces)�isIPAddress�
isIPv6Address)�abstract�iocpsupport)�ERROR_CONNECTION_REFUSED�ERROR_IO_PENDING�ERROR_PORT_UNREACHABLE)�IReadWriteHandle)�failure�logc���eZdZUdZej
ZejZdZ	dZ
eee
d<dd�Zd�Zdefd�Zd	�Zd
�Zd�Zd�Zd
�Zd�Zd�Zd�Zdd�Zd�Zd�Zd�Zd�Zd�Zdd�Z d�Z!d�Z"d�Z#d�Z$d�Z%y)�Portz�
    UDP port, listening for packets.

    @ivar addressFamily: L{socket.AF_INET} or L{socket.AF_INET6}, depending on
        whether this port is listening on an IPv4 address or an IPv6 address.
    FN�_realPortNumberc���||_||_||_||_|j	�d|_|j
�tjj||�tj|j|j�}tj|j��}t!|�|_t!t%j&d��|_y)z>
        Initialize with a numeric port to listen on.
        N�i)�port�protocol�readBufferSize�	interface�	setLogStr�_connectedAddr�_setAddressFamilyr�
FileHandle�__init__�socket�
addressFamily�
socketType�_iocp�
maxAddrLen�fileno�	bytearray�
addressBuffer�struct�calcsize�addressLengthBuffer)�selfr�protor�
maxPacketSize�reactor�skt�addrLens        �B/usr/lib/python3/dist-packages/twisted/internet/iocpreactor/udp.pyr z
Port.__init__2s�����	���
�+���"�������"������ ����$�$�T�7�3��m�m�D�.�.����@���"�"�3�:�:�<�0��&�w�/���#,�V�_�_�S�-A�#B�� �c��t|j�rtj|_yt|j�rtj|_y|jr tj|jd��y)z8
        Resolve address family for the socket.
        znot an IPv4 or IPv6 addressN)	r
rr!�AF_INET6r"r	�AF_INETr�InvalidAddressError�r,s r2rzPort._setAddressFamilyFs]������(�!'���D��
����
(�!'���D��
�^�^��+�+���� =��
�r3�returnc��|j�'d|jj�d|j�d�Sd|jj�d�S)N�<z on �>z not connected>)rr�	__class__r8s r2�__repr__z
Port.__repr__SsO�����+��t�}�}�.�.�/�t�D�4H�4H�3I��K�K��t�}�}�.�.�/��?�?r3c��|jS)z)
        Return a socket object.
        )r!r8s r2�	getHandlezPort.getHandleY����{�{�r3c�D�|j�|j�y)z�
        Create and bind my socket, and begin listening on it.

        This is called on unserialization, and must be called after creating a
        server to begin listening on the specified port.
        N)�_bindSocket�_connectToProtocolr8s r2�startListeningzPort.startListening_s��	
�������!r3c�b�|jj|j|j�S�N)r/�createSocketr"r#r8s r2rHzPort.createSocketis#���|�|�(�(��);�);�T�_�_�M�Mr3c���	|j�}|j|j|jf�|j�d|_tj|j|j��d|j���d|_
||_|jj|_y#t$r0}tj|j|j|��d}~wwxYw)N�z
 starting on T)rH�bindrr�OSErrorr�CannotListenError�getsocknamerr�msg�
_getLogPrefixr�	connectedr!r&�
getFileHandle)r,r0�les   r2rCzPort._bindSocketls���	I��#�#�%�C��H�H�d�n�n�d�i�i�0�1� #���0��3�������!�!�$�-�-�0�$�2F�2F�
H�	
�
������!�[�[�/�/�����	I��)�)�$�.�.�$�)�)�R�H�H��	I�s�7B8�8	C1�+C,�,C1c��|jj|�|j�|jj	|�yrG)r�makeConnection�startReadingr/�addActiveHandler8s r2rDzPort._connectToProtocol�s2���
�
�$�$�T�*��������$�$�T�*r3c�d�|jr$|j|||�|j�yyrG)�reading�
handleRead�doRead�r,�rc�data�evts    r2�cbReadzPort.cbRead�s'���<�<��O�O�B��c�*��K�K�M�r3c��|tjtjttfvr(|j
r|jj�yy|r;tjdtjj|d��d|�d��y	|jjt|jd|�tj |j"��y#t$$rtj&�YywxYw)Nzerror in recvfrom -- z
unknown errorz (�))�errno�WSAECONNREFUSED�
WSAECONNRESETr
rrr�connectionRefusedrrO�	errorcode�get�datagramReceived�bytes�buffr$�makesockaddr�	addr_buff�
BaseException�errr\s    r2rZzPort.handleRead�s���
��!�!����$�"�	
�
��"�"��
�
�/�/�1�#�
��G�G��?�?�&�&�r�?�;�R�A�
�

��
�
�.�.��#�(�(�5�D�/�*�E�,>�,>�s�}�}�,M���!�
����	�
�s�AC#�#D�Dc�|�tj|j|�}|jdx|_}|j
x|_}|jx|_}tj|j�||||�\}}|r4|tk7r*|jjd|j|||�yyy�Nr)r$�Eventr`�_readBuffersrkr(rmr+�
addr_len_buff�recvfromrRrr/�	callLater)r,r_rkrmrtr]r^s       r2r[zPort.doRead�s����k�k�$�+�+�t�,���+�+�A�.�.���4�$(�$6�$6�6��
�	�,0�,D�,D�D���M��>�>���� �$�	�=�#�
���D��"�(�(�
�L�L�"�"�1�d�k�k�2�t�S�A�
)�2r3c��|jr.|d|jfvsJ�	|jj|�S|dk7sJ�t#|d�s/t%|d�s!|ddk7rtj&|dd��t#|d�r6|j(tj*k(rtj&|dd��t%|d�r6|j(tj,k(rtj&|dd��	|jj/||�S#t$r�}|jd}|t
jk(r|j|�cYd}~S|t
jk(rtjd��|t
jt
jttfvr|jj!�n�Yd}~yd}~wwxYw#t$r�}|jd}|t
jk(r|j||�cYd}~S|t
jk(rtjd��|t
jt
jttfvrYd}~y�d}~wwxYw)z~
        Write a datagram.

        @param addr: should be a tuple (ip, port), can be None in connected
        mode.
        Nrzmessage too longz<broadcast>z0write() only accepts IP addresses, not hostnamesz*IPv6 port write() called with IPv4 addressz*IPv4 port write() called with IPv6 address)rr!�sendrL�argsrc�WSAEINTR�write�WSAEMSGSIZEr�MessageLengthErrorrdrer
rrrfr	r
r7r"r5r6�sendto)r,�datagram�addr�se�nos     r2r{z
Port.write�sF������D�$�"5�"5�6�6�6�6�
��{�{�'�'��1�1�"�4�<��<���Q��(�%�d�1�g�.���G�}�,��/�/���G�O����4��7�#��(:�(:�f�o�o�(M��/�/���G�I����T�!�W�%�$�*<�*<����*N��/�/���G�I���
��{�{�)�)�(�D�9�9��E�
��W�W�Q�Z������'��:�:�h�/�/��5�,�,�,��2�2�3E�F�F���)�)��'�'�,�*�	���M�M�3�3�5��6��
��F�
��W�W�Q�Z������'��:�:�h��5�5��5�,�,�,��2�2�3E�F�F���)�)��'�'�,�*�	�����#
�sO�D$�G"�$	G�-2G�G�%A0G�G�"	J�+3I>�J�$AI>�=I>�>Jc�F�|jdj|�|�y)Nr3)r{�join)r,�seqr�s   r2�
writeSequencezPort.writeSequence�s���
�
�3�8�8�C�=�$�'r3c���|jrtd��t|�s!t|�st	j
|d��||f|_|jj||f�y)z-
        'Connect' to remote server.
        z\already connected, reconnecting is not currently supported (talk to itamar if you want this)znot an IPv4 or IPv6 address.N)r�RuntimeErrorr	r
rr7r!�connect)r,�hostrs   r2r�zPort.connect�sf������4��
��4� ��t�)<��+�+�D�2P�Q�Q�#�T�l��������T�4�L�)r3c��|j�|jj|�|jr'|jj	d|j
�yyrq)�stopReadingr/�removeActiveHandlerQrv�connectionLostr8s r2�_loseConnectionzPort._loseConnectionsF���������'�'��-��>�>��L�L�"�"�1�d�&9�&9�:�r3c�z�|jrtj�x}|_nd}|j	�|SrG)rQr�Deferred�dr�)r,�results  r2�
stopListeningzPort.stopListening
s2���>�>�#�n�n�.�.�F�T�V��F������
r3c�\�tjdtd��|j�y)Nz-Please use stopListening() to disconnect port�)�
stacklevel)�warnings�warn�DeprecationWarningr�r8s r2�loseConnectionzPort.loseConnections%���
�
�;���	
�
	
���r3c�Z�tjd|jz�d|_tjj||�|jj�|jj�|`|`
t|d�r|jjd�|`yy)z&
        Cleans up my socket.
        z(UDP Port %s Closed)Nr�)rrOrrrr�r�doStopr!�closerR�hasattrr��callback)r,�reasons  r2r�zPort.connectionLosts���	���&��)=�)=�=�>�#������*�*�4��8��
�
�����������K����4����F�F�O�O�D�!���r3c�N�|j|j�}d|z|_y)zP
        Initialize the C{logstr} attribute to be used by C{logPrefix}.
        z%s (UDP)N)rPr�logstr)r,�	logPrefixs  r2rzPort.setLogStr)s$���&�&�t�}�}�5�	� �9�,��r3c��|jS)zK
        Returns the name of my class, to prefix log entries with.
        )r�r8s r2r�zPort.logPrefix0rAr3c�
�|jj�}|jtjk(rt	j
dg|���S|jtjk(rt	jdg|dd���Sy)z�
        Return the local address of the UDP connection

        @returns: the local address of the UDP connection
        @rtype: L{IPv4Address} or L{IPv6Address}
        �UDPNr�)r!rNr"r6r�IPv4Addressr5�IPv6Address�r,r�s  r2�getHostzPort.getHost6sq���{�{�&�&�(��������/��&�&�u�4�t�4�4�
�
�
�6�?�?�
2��&�&�u�:��R�a��:�:�3r3c�v�|jjtjtj|�y)z�
        Set whether this port may broadcast. This is disabled by default.

        @param enabled: Whether the port may broadcast.
        @type enabled: L{bool}
        N)r!�
setsockopt�
SOL_SOCKET�SO_BROADCAST)r,�enableds  r2�setBroadcastAllowedzPort.setBroadcastAllowedCs&��	
�����v�0�0�&�2E�2E�w�Or3c��t|jjtjtj��S)z�
        Checks if broadcast is currently allowed on this port.

        @return: Whether this port may broadcast.
        @rtype: L{bool}
        )�boolr!�
getsockoptr�r�r8s r2�getBroadcastAllowedzPort.getBroadcastAllowedLs,���D�K�K�*�*�6�+<�+<�f�>Q�>Q�R�S�Sr3)�� NrG)&�__name__�
__module__�__qualname__�__doc__r!r6r"�
SOCK_DGRAMr#�dynamicReadBuffersrr�int�__annotations__r r�strr>r@rErHrCrDr`rZr[r{r�r�r�r�r�r�rr�r�r�r��r3r2rrs�����N�N�M��"�"�J���&*�O�X�c�]�)�C�(�@�#�@��"�N�0�(+�
�
�,B�$?�B(�*�;���
�-��;�P�Tr3rc�V�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
dd	�Zd
�Zd�Z
dd�Zy
)�MulticastMixinz,
    Implement multicast functionality.
    c���|jjtjtj�}tjtjd|��S)Nz@i)r!r��
IPPROTO_IP�IP_MULTICAST_IF�	inet_ntoar)�pack)r,rs  r2�getOutgoingInterfacez#MulticastMixin.getOutgoingInterface[s@���K�K�"�"�6�#4�#4�f�6L�6L�M��������D�!� 4�5�5r3c�j�|jj|�j|j�S)z.
        Returns Deferred of success.
        )r/�resolve�addCallback�
_setInterfacer�s  r2�setOutgoingInterfacez#MulticastMixin.setOutgoingInterface_s*���|�|�#�#�D�)�5�5�d�6H�6H�I�Ir3c��tj|�}|jjtjtj|�y)NrJ)r!�	inet_atonr�r�r�)r,r�rs   r2r�zMulticastMixin._setInterfacees7�����T�"�������v�0�0�&�2H�2H�!�L�r3c�r�|jjtjtj�SrG)r!r�r��IP_MULTICAST_LOOPr8s r2�getLoopbackModezMulticastMixin.getLoopbackModejs%���{�{�%�%�f�&7�&7��9Q�9Q�R�Rr3c��tjdt|��}|jj	tj
tj|�y)N�b)r)r�r�r!r�r�r�)r,�modes  r2�setLoopbackModezMulticastMixin.setLoopbackModems8���{�{�3��T�
�+�������v�0�0�&�2J�2J�D�Qr3c�r�|jjtjtj�SrG)r!r�r��IP_MULTICAST_TTLr8s r2�getTTLzMulticastMixin.getTTLqs%���{�{�%�%�f�&7�&7��9P�9P�Q�Qr3c��tjd|�}|jjtjtj
|�y)N�B)r)r�r!r�r�r�)r,�ttls  r2�setTTLzMulticastMixin.setTTLts4���k�k�#�s�#�������v�0�0�&�2I�2I�3�Or3c�n�|jj|�j|j|d�S)zF
        Join a multicast group. Returns Deferred of success.
        rJ�r/r�r��
_joinAddr1�r,r�rs   r2�	joinGroupzMulticastMixin.joinGroupx�-���|�|�#�#�D�)�5�5�d�o�o�y�RS�T�Tr3c�n�|jj|�j|j||�SrG)r/r�r��
_joinAddr2)r,r�rr�s    r2r�zMulticastMixin._joinAddr1~s+���|�|�#�#�I�.�:�:�4�?�?�D�RV�W�Wr3c��tj|�}tj|�}|rtj}ntj}	|jj	tj
|||z�y#t$r>}tjtj||g|j����cYd}~Sd}~wwxYwrG)r!r��IP_ADD_MEMBERSHIP�IP_DROP_MEMBERSHIPr�r�rLr�Failurer�MulticastJoinErrorry)r,rr�r��cmd�es      r2r�zMulticastMixin._joinAddr2�s�������%���$�$�Y�/�	���*�*�C��+�+�C�	W��K�K�"�"�6�#4�#4�c�4�)�;K�L���	W��?�?�5�#;�#;�D�)�#U�a�f�f�#U�V�V��	W�s�.A>�>	C�3C�:C�Cc�n�|jj|�j|j|d�S)zD
        Leave multicast group, return Deferred of success.
        rr�r�s   r2�
leaveGroupzMulticastMixin.leaveGroup�r�r3N)r�)r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r3r2r�r�VsG���6�J��
S�R�R�P�U�X�
W�Ur3r�c�&�eZdZdZ				dd�Zd�Zy)�
MulticastPortz.
    UDP Port that supports multicasting.
    Nc�F�tj||||||�||_yrG)rr �listenMultiple)r,rr-rr.r/r�s       r2r zMulticastPort.__init__�s"��	
�
�
�d�D�%��M�7�K�,��r3c�$�tj|�}|jrn|jtj
tjd�ttd�r/|jtj
tjd�|S)NrJ�SO_REUSEPORT)	rrHr�r�r!r��SO_REUSEADDRr�r�)r,r0s  r2rHzMulticastPort.createSocket�sb������%������N�N�6�,�,�f�.A�.A�1�E��v�~�.����v�0�0�&�2E�2E�q�I��
r3)r�r�NF)r�r�r�r�r rHr�r3r2r�r��s�������
-�r3r�)&r�rcr!r)r��typingr�zope.interfacer�twisted.internetrrrr�twisted.internet.abstractr	r
�twisted.internet.iocpreactorrrr$�"twisted.internet.iocpreactor.constr
rr�'twisted.internet.iocpreactor.interfacesr�twisted.pythonrr�IListeningPort�
IUDPTransport�
ISystemHandlerrr��IMulticastTransportr�r�r3r2�<module>rs����
�
�
���&�>�>�@�G���
E�'�
�����������	�qT�8���qT�
�qT�h	;U�;U�|
�Z�
+�
+�,��N�D��-�r3