+
    Dfj                        R t ^ RIt^ RIt^ RIt^ RIHt ^ RIHtHtHtH	t	Ht ^ RI
Ht ^ RIHt ^ RIHt ^ RIHt ^ RIHt ^ R	IHt  ^ R
IHtHtHt ^ RIHt ^ RIHt ^ RIH t  ^ RI!H"t"H#t#H$t$  ]! ]]4      PQ                  4        Rt)Rt* ! R R]4      t. ! R R]4      t/R#   ]% d    ]PL                  R8X  d   h Rt' LQi ; i  ]+ d   t,Rt)]-! ],4      t* Rt,A,LORt,A,ii ; i)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 IOCPReactorF Tc                   N   a  ] tR t^1t o RtR tR t]! ]]	4      R 4       t
RtV tR# )SupportTestszb
Tests for L{twisted.internet.iocpreactor.iocpsupport}, low-level reactor
implementation helpers.
c           
     6   \        RV: 24       \        V\        4      pV P                  VP                  4       VP                  R	4       VP                  ^4       \        V\        4      pV P                  VP                  4       VP                  R4        VP                  W#P                  4       ^,          34       \        V\        4      pV P                  VP                  4       \        RR
4      pV P!                  ^ \"        P$                  ! VP'                  4       VP'                  4       VR4      4       \)        \+        ^4      4       F7  p VP-                  \.        \0        \3        RVP'                  4       4      4        M	  V P!                  WP;                  4       R,          VP                  4       R,          3\"        P<                  ! VP'                  4       V4      4       R#   \         dF   pT P                  TP                  \        P                  \        P                  34        Rp?ELyRp?ii ; i  \         d3   p	T	P                  \5        \        R4      8w  d   h T^ 8X  d   h  Rp	?	MRp	?	ii ; i\6        P8                  ! R4       EKJ  )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 = FNBPWSAENOTCONNg?:N   N)r       s                                                                                                                                                                                                                                                                   )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socketErrors
   &&&       A/usr/lib/python3/dist-packages/twisted/internet/test/test_iocp.py_acceptAddressTestSupportTests._acceptAddressTest7   s   4 	iz"#fk*

#		'A,%5!	KNNI'7'7'9!'<=> ,%S+&ELLtTU!)%(!3!! 8$sDKKM:R  "4B 	'')"-v/A/A/CB/GH""6==?D9	
S  	KMM!''E$5$5u7H7H#IJJ	K0  
$$}(EE %) *
 JJsOs0   'G/ 3I/H?::H::H?I?(I::I?c                2    V P                  \        R4       R# )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   r9   s   &rC   test_ipv4AcceptAddress#SupportTests.test_ipv4AcceptAddress   s     	5    c                2    V P                  \        R4       R# )aP  
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   rG   s   &rC   test_ipv6AcceptAddress#SupportTests.test_ipv6AcceptAddress   s     	%0rJ    N)__name__
__module____qualname____firstlineno____doc__rD   rH   r	   ipv6Skipipv6SkipReasonrL   __static_attributes____classdictcell____classdict__s   @rC   r   r   1   s1     
P
d6 Hn%1 &1rJ   r   c                   8   a  ] tR t^t o R tR tR tR tRtV t	R# )IOCPReactorTestsc                z    \        4       pVP                  4        V P                  VP                  R4      4       R# )zL
Test reactor behavior (doIteration) when there are no pending time
events.
N)r   wakeUpassertFalsedoIteration)r9   irs   & rC   test_noPendingTimerEvents*IOCPReactorTests.test_noPendingTimerEvents   s+    
 ]
		-.rJ   c                    V P                  \        \        \        P                  4      4       V P                  \        \        \
        P                  4      4       R# )zI
Verify that IOCP socket-representing classes implement IReadWriteHandle
N)
assertTruer
   r   r   
Connectionr   PortrG   s   &rC   test_reactorInterfaces'IOCPReactorTests.test_reactorInterfaces   s4     	$4cnnEF$4chh?@rJ   c                L    V P                  \        \        \        4      4       R# )z8
Verify that L{Filehandle} implements L{IPushProducer}.
N)rd   r
   r   r   rG   s   &rC   test_fileHandleInterfaces*IOCPReactorTests.test_fileHandleInterfaces   s     	M:>?rJ   c                    ! R R4      p\        4       pV! 4       p\        P                  ! VP                  V4      p\	        \
        ^,           4       F$  pVP                  P                  ^ \        V4       K&  	  VP                  R4       V P                  VP                  \
        4       VP                  ^ 4       V P                  VP                  \
        ^,           4       R# )zn
Verify that we don't lose an event when more than EVENTS_PER_LOOP
events occur in the same reactor iteration
c                   0   a  ] tR t^t o ^ tR tR tRtV tR# );IOCPReactorTests.test_maxEventsPerIteration.<locals>.FakeFDc                    R # )FakeFDrN   rG   s   &rC   	logPrefixEIOCPReactorTests.test_maxEventsPerIteration.<locals>.FakeFD.logPrefix   s    rJ   c                8    V ;P                   ^,          un         R# )   N)counter)r9   rcbytesevts   &&&&rC   cb>IOCPReactorTests.test_maxEventsPerIteration.<locals>.FakeFD.cb   s    !rJ   rN   N)	rO   rP   rQ   rR   ru   rq   ry   rV   rW   rX   s   @rC   rp   rn      s     G " "rJ   rp   N)r   r.   Eventry   r2   r   r<   	postEventr   r_   r-   ru   )r9   rp   r`   fdevent_s   &     rC   test_maxEventsPerIteration+IOCPReactorTests.test_maxEventsPerIteration   s    	" 	" ]XBEE2&*+AGGaU3 ,
t_5
q_q%89rJ   rN   N)
rO   rP   rQ   rR   ra   rg   rj   r   rV   rW   rX   s   @rC   r[   r[      s      /A@: :rJ   r[   )0rS   r*   sysr5   r   r   r   r   r   r   structr   unittestr	   zope.interface.verifyr
   twisted.internet.interfacesr   twisted.python.logr   twisted.trial.unittestr   twisted.internet.iocpreactorr   r.   r   r   %twisted.internet.iocpreactor.abstractr   "twisted.internet.iocpreactor.constr   'twisted.internet.iocpreactor.interfacesr   $twisted.internet.iocpreactor.reactorr   r   r   ImportErrorplatformskipr"   rT   rU   r(   r>   strr   r[   rN   rJ   rC   <module>r      s     
   E E   - 5 " +3KK@KH 
8[!'') HNr18 r1j.:x .:M  3
||w2D	3  HVNs*   &B" /C "C ?C C

CC