
    Vh"                     2   d Z ddlZddlZddlmZ ddlmZ ddlmZ ddl	m
Z
 	  eed      Z eed      Z eed	      Z eed
      Z eed      Z ee       G d dej(                  ej*                               Zd ZddgZy# e$ rZ ee      dZ[ww xY w)z
An epoll() based implementation of the twisted main loop.

To install the event loop (and you should do this before any connections,
listeners or connectors are added)::

    from twisted.internet import epollreactor
    epollreactor.install()
    N)implementer)	posixbase)IReactorFDSet)logepollEPOLLHUPEPOLLERREPOLLINEPOLLOUTc                   h    e Zd ZdZeez  ZeZe	Z
d Zd Zd Zd Zd Zd Zd Zd	 Zd
 Zd Zd ZeZy)EPollReactora  
    A reactor that uses epoll(7).

    @ivar _poller: A C{epoll} which will be used to check for I/O
        readiness.

    @ivar _selectables: A dictionary mapping integer file descriptors to
        instances of C{FileDescriptor} which have been registered with the
        reactor.  All C{FileDescriptors} which are currently receiving read or
        write readiness notifications will be present as values in this
        dictionary.

    @ivar _reads: A set containing integer file descriptors.  Values in this
        set will be registered with C{_poller} for read readiness notifications
        which will be dispatched to the corresponding C{FileDescriptor}
        instances in C{_selectables}.

    @ivar _writes: A set containing integer file descriptors.  Values in this
        set will be registered with C{_poller} for write readiness
        notifications which will be dispatched to the corresponding
        C{FileDescriptor} instances in C{_selectables}.

    @ivar _continuousPolling: A L{_ContinuousPolling} instance, used to handle
        file descriptors (e.g. filesystem files) that are not supported by
        C{epoll(7)}.
    c                     t        d      | _        t               | _        t               | _        i | _        t        j                  |       | _        t        j                  j                  |        y)zm
        Initialize epoll object, file descriptor tracking dictionaries, and the
        base class.
        i   N)r   _pollerset_reads_writes_selectablesr   _ContinuousPolling_continuousPollingPosixReactorBase__init__)selfs    M/home/dcms/DCMS/lib/python3.12/site-packages/twisted/internet/epollreactor.pyr   zEPollReactor.__init__G   sP     T{eu"+">">t"D""++D1    c                     |j                         }||vr[|}||v r"||z  }| j                  j                  ||       n| j                  j                  ||       |j	                  |       |||<   yy)z
        Private method for adding a descriptor from the event loop.

        It takes care of adding it if  new or modifying it if already added
        for another state (read -> read/write for example).
        N)filenor   modifyregisteradd)	r   xerprimaryotherselectablesevent	antieventfdflagss	            r   _addzEPollReactor._addV   sr     ZZ\WE U{"##B.%%b%0 KKO!KO! r   c                    	 | j                  || j                  | j                  | j                  t        t
               y# t        $ rD}|j                  t        j                  k(  r| j                  j                  |       n Y d}~yd}~ww xY w)zR
        Add a FileDescriptor for notification of data available to read.
        N)r(   r   r   r   r
   r   OSErrorerrnoEPERMr   	addReader)r   readeres      r   r-   zEPollReactor.addReaderp   sn    	IIT\\43D3Dgx  	ww%++% ''11&9 :	   <? 	B:BBc                    	 | j                  || j                  | j                  | j                  t        t
               y# t        $ rD}|j                  t        j                  k(  r| j                  j                  |       n Y d}~yd}~ww xY w)zS
        Add a FileDescriptor for notification of data available to write.
        N)r(   r   r   r   r   r
   r*   r+   r,   r   	addWriter)r   writerr/   s      r   r2   zEPollReactor.addWriter   so    	IIdkk43D3DhPW  	ww%++% ''11&9 :	r0   c                    |j                         }|dk(  r|j                         D ]  \  }}||u s n y||v rS||v r|}	| j                  j                  ||	       n||= | j                  j	                  |       |j                  |       yy)z
        Private method for removing a descriptor from the event loop.

        It does the inverse job of _add, and also add a check in case of the fd
        has gone away.
        N)r   itemsr   r   
unregisterremove)
r   r    r!   r"   r#   r$   r%   r&   fdesr'   s
             r   _removezEPollReactor._remove   s     ZZ\8'--/ D$; =U{!##B.O''+NN2 r   c                     | j                   j                  |      r| j                   j                  |       y| j                  || j                  | j
                  | j                  t        t               y)zQ
        Remove a Selectable for notification of data available to read.
        N)	r   	isReadingremoveReaderr:   r   r   r   r
   r   )r   r.   s     r   r=   zEPollReactor.removeReader   sV     "",,V4##008DKKt/@/@'8	
r   c                     | j                   j                  |      r| j                   j                  |       y| j                  || j                  | j
                  | j                  t        t               y)zR
        Remove a Selectable for notification of data available to write.
        N)	r   	isWritingremoveWriterr:   r   r   r   r   r
   )r   r3   s     r   r@   zEPollReactor.removeWriter   sV     "",,V4##008DLL$++t/@/@(G	
r   c                    | j                  | j                  D cg c]  }| j                  |    c}| j                  D cg c]  }| j                  |    c}      | j                  j                         z   S c c}w c c}w )zD
        Remove all selectables, and return a list of them.
        )
_removeAllr   r   r   r   	removeAllr   r&   s     r   rC   zEPollReactor.removeAll   sn    
 OO15=2""2&=15>2""2&> %%//1	2	
=>s   A8 A=
c                     | j                   D cg c]  }| j                  |    c}| j                  j                         z   S c c}w N)r   r   r   
getReadersrD   s     r   rG   zEPollReactor.getReaders   sE    ,0KK
&(Db!
##..01 	1 
   Ac                     | j                   D cg c]  }| j                  |    c}| j                  j                         z   S c c}w rF   )r   r   r   
getWritersrD   s     r   rJ   zEPollReactor.getWriters   sE    ,0LL
&(Db!
##..01 	1 
rH   c                 p   |d}	 | j                   j                  |t        | j                              }| j                  }|D ].  \  }}	 | j                  |   }t        j                  |||||       0 y# t        $ r(}|j
                  t
        j                  k(  rY d}~y d}~ww xY w# t        $ r Y qw xY w)z1
        Poll the poller for new events.
        Nr5   )r   polllenr   r*   r+   EINTR_doReadOrWriter   callWithLoggerKeyError)r   timeoutlerr_drdwr&   r$   
selectables           r   doPollzEPollReactor.doPoll   s     ?G	
 !!'3t/@/@+ABA ## 	MIBM!..r2
 "":uj"eL	M  	yyEKK'
 	  s/   /A5 
B)5	B&>B! B!!B&)	B54B5N)__name__
__module____qualname____doc__r   r	   _POLL_DISCONNECTEDr
   _POLL_INr   	_POLL_OUTr   r(   r-   r2   r:   r=   r@   rC   rG   rJ   rW   doIteration r   r   r   r   %   s]    8 "H,HI2"4""2	
	


1
1
M> Kr   r   c                  4    t               } ddlm}  ||        y)z&
    Install the epoll() reactor.
    r   )installReactorN)r   twisted.internet.mainrb   )prb   s     r   installre      s     	A41r   re   )r[   r+   selectzope.interfacer   twisted.internetr   twisted.internet.interfacesr   twisted.pythonr   getattrr   r   r	   r
   r   AttributeErrorr/   ImportErrorr   _PollLikeMixinr   re   __all__r`   r   r   <module>rp      s      & & 5 
 FG$Evz*Hvz*Hfi(Gvz*H
 ]P9--y/G/G P Pf 9
%E  
a.s   -B B	BB