File: //usr/lib/python3/dist-packages/twisted/internet/test/__pycache__/test_iocp.cpython-310.pyc
o
�b �
@ sp d Z ddlZddlZddlZddlmZ ddlmZmZmZm Z mZ ddl
mZ ddlm
Z
ddlmZ ddlmZ dd lmZ dd
lmZ z(ddlmZmZmZ ddlmZ dd
lmZ ddlm Z ddl!m"Z"m#Z#m$Z$ W n e%y ej&dkr{� dZ'Y nw z eee��(� W n e)y� Z* zdZ+e,e*�Z-W Y dZ*[*n dZ*[*ww dZ+dZ-G dd� de�Z.G dd� de�Z/dS )z,
Tests for L{twisted.internet.iocpreactor}.
� N)�array)�AF_INET�AF_INET6�SOCK_STREAM�
SOL_SOCKET�socket)�pack)�skipIf)�verifyClass)�
IPushProducer)�msg)�TestCase)�iocpsupport�tcp�udp)�
FileHandle)�SO_UPDATE_ACCEPT_CONTEXT)�IReadWriteHandle)�EVENTS_PER_LOOP�
KEY_NORMAL�IOCPReactor�win32z%This test only applies to IOCPReactorTF� c @ s2 e Zd ZdZdd� Zdd� Zeee�dd� �Z dS ) �SupportTestszn
Tests for L{twisted.internet.iocpreactor.iocpsupport}, low-level reactor
implementation helpers.
c
C s� t d|��� t|t�}| �|j� |�d� |�d� t|t�}| �|j� |�d� z
|�||� � d f� W n t
yV } z| �|jtj
tjf� W Y d}~nd}~ww t|t�}| �|j� tdd�}| �dt�|�� |�� |d�� ttd ��D ]7}z|�tttd
|�� �� W n& t
y� } z| jttd�kr�� |dkr�� W Y d} ~ nd} ~ ww t�d� q}| �||�� dd
� |� � dd
� ft�|�� |�� dS )a�
Create a C{SOCK_STREAM} connection to localhost using a socket with an
address family of C{family} and assert that the result of
L{iocpsupport.get_accept_addrs} is consistent with the result of
C{socket.getsockname} and C{socket.getpeername}.
A port starts listening (is bound) at the low-level socket without
calling accept() yet.
A client is then connected.
After the client is connected IOCP accept() is called, which is the
target of these tests.
Most of the time, the socket is ready instantly, but sometimes
the socket is not ready right away after calling IOCP accept().
It should not take more than 5 seconds for a socket to be ready, as
the client connection is already made over the loopback interface.
These are flaky tests.
Tweak the failure rate by changing the number of retries and the
wait/sleep between retries.
If you will need to update the retries to wait more than 5 seconds
for the port to be available, then there might a bug in the code and
not the test (or a very, very busy VM running the tests).
z family = )r r � FN�Bs r � �P�WSAENOTCONNg�������?� )r r r �
addCleanup�close�bind�listen�setblocking�connect�getsockname�OSError�assertIn�errno�EINPROGRESS�EWOULDBLOCKr �assertEqual�_iocp�accept�fileno�reversed�range�
setsockoptr r r �getattr�time�sleep�getpeername�get_accept_addrs)
�self�family� localhost�port�client�e�server�buff�attemptsRemaining�socketError� rB �A/usr/lib/python3/dist-packages/twisted/internet/test/test_iocp.py�_acceptAddressTest7 sJ
"��
���� �zSupportTests._acceptAddressTestc C � | � td� dS )a
L{iocpsupport.get_accept_addrs} returns a three-tuple of address
information about the socket associated with the file descriptor passed
to it. For a connection using IPv4:
- the first element is C{AF_INET}
- the second element is a two-tuple of a dotted decimal notation IPv4
address and a port number giving the peer address of the connection
- the third element is the same type giving the host address of the
connection
z 127.0.0.1N)rD r �r8 rB rB rC �test_ipv4AcceptAddress� � z#SupportTests.test_ipv4AcceptAddressc C rE )a�
Like L{test_ipv4AcceptAddress}, but for IPv6 connections.
In this case:
- the first element is C{AF_INET6}
- the second element is a two-tuple of a hexadecimal IPv6 address
literal and a port number giving the peer address of the connection
- the third element is the same type giving the host address of the
connection
z::1N)rD r rF rB rB rC �test_ipv6AcceptAddress� rH z#SupportTests.test_ipv6AcceptAddressN)
�__name__�
__module__�__qualname__�__doc__rD rG r �ipv6Skip�ipv6SkipReasonrI rB rB rB rC r 1 s Rr c @ s, e Zd Zdd� Zdd� Zdd� Zdd� Zd S )
�IOCPReactorTestsc C s"