
    \d"                     X   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n# e$ rZ ee          dZ[ww xY w ee           G d dej        ej                              Zd ZddgZdS )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                   j    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dS )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	        
                    |            dS )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    =lib/python3.11/site-packages/twisted/internet/epollreactor.pyr   zEPollReactor.__init__G   s_     T{{eeuu"+">t"D"D"++D11111    c                     |                                 }||vr^|}||v r!||z  }| j                            ||           n| j                            ||           |                    |           |||<   dS dS )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   s     ZZ\\WE U{{"##B....%%b%000 KKOOO!KOOO! r   c                     	 |                      || j        | j        | j        t          t
                     dS # t          $ r<}|j        t          j        k    r| j	        
                    |           n Y d}~dS 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   s    	IIT\43Dgx      	 	 	w%+%% '11&9999 :99999	   37 
A=1A88A=c                     	 |                      || j        | j        | j        t          t
                     dS # t          $ r<}|j        t          j        k    r| j	        
                    |           n Y d}~dS 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   writerr0   s      r   r3   zEPollReactor.addWriter   s    	IIdk43DhPW      	 	 	w%+%% '11&9999 :99999	r1   c                 2   |                                 }|dk    r"|                                D ]\  }}||u r ndS ||v rV||v r|}	| j                            ||	           n||= | j                            |           |                    |           dS dS )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\\88'--//  D$;;E  ==U{{!##B....O''+++NN2 =r   c                     | j                             |          r| j                             |           dS |                     || j        | j        | j        t          t                     dS )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   sm     ",,V44 	#00888FDKt/@'8	
 	
 	
 	
 	
r   c                     | j                             |          r| j                             |           dS |                     || j        | j        | j        t          t                     dS )zR
        Remove a Selectable for notification of data available to write.
        N)	r   	isWritingremoveWriterr;   r   r   r   r   r
   )r   r4   s     r   rA   zEPollReactor.removeWriter   sm     ",,V44 	#00888FDL$+t/@(G	
 	
 	
 	
 	
r   c                                             fd j        D              fd j        D                        j                                        z   S )zD
        Remove all selectables, and return a list of them.
        c                 *    g | ]}j         |         S  r   .0r'   r   s     r   
<listcomp>z*EPollReactor.removeAll.<locals>.<listcomp>   s!    ===2"2&===r   c                 *    g | ]}j         |         S rD   rE   rF   s     r   rH   z*EPollReactor.removeAll.<locals>.<listcomp>   s!    >>>2"2&>>>r   )
_removeAllr   r   r   	removeAllr   s   `r   rK   zEPollReactor.removeAll   sf    
 OO=======>>>>>>>  %//11	2	
r   c                 ^      fd j         D              j                                        z   S )Nc                 *    g | ]}j         |         S rD   rE   rF   s     r   rH   z+EPollReactor.getReaders.<locals>.<listcomp>   .     
 
 
&(Db!
 
 
r   )r   r   
getReadersr   s   `r   rO   zEPollReactor.getReaders   sG    
 
 
 
,0K
 
 
#..001 	1r   c                 ^      fd j         D              j                                        z   S )Nc                 *    g | ]}j         |         S rD   rE   rF   s     r   rH   z+EPollReactor.getWriters.<locals>.<listcomp>   rN   r   )r   r   
getWritersr   s   `r   rR   zEPollReactor.getWriters   sG    
 
 
 
,0L
 
 
#..001 	1r   c                 R   |d}	 | j                             |t          | j                            }n.# t          $ r!}|j        t
          j        k    rY d}~dS  d}~ww xY w| j        }|D ];\  }}	 | j        |         }t          j	        |||||           ,# t          $ r Y 8w xY wdS )z1
        Poll the poller for new events.
        Nr6   )r   polllenr   r+   r,   EINTR_doReadOrWriter   callWithLoggerKeyError)r   timeoutlerr_drdwr'   r%   
selectables           r   doPollzEPollReactor.doPoll   s     ?G	
 !!'3t/@+A+ABBAA 	 	 	yEK''
 	 # 	M 	MIBM!.r2
 ":uj"eLLLL    	M 	Ms,   -4 
AAAA1B
B$#B$N)__name__
__module____qualname____doc__r   r	   _POLL_DISCONNECTEDr
   _POLL_INr   	_POLL_OUTr   r)   r.   r3   r;   r>   rA   rK   rO   rR   r_   doIterationrD   r   r   r   r   %   s         8 "H,HI2 2 2" " "4  "  "  2	
 	
 	
	
 	
 	


 

 

1 1 1
1 1 1
M M M> KKKr   r   c                  D    t                      } ddlm}  ||            dS )z&
    Install the epoll() reactor.
    r   )installReactorN)r   twisted.internet.mainri   )pri   s     r   installrl      s5     	A444444N1r   rl   )rc   r,   selectzope.interfacer   twisted.internetr   twisted.internet.interfacesr   twisted.pythonr   getattrr   r   r	   r
   r   AttributeErrorr0   ImportErrorr   _PollLikeMixinr   rl   __all__rD   r   r   <module>rw      sg      & & & & & & & & & & & & 5 5 5 5 5 5      
 GFG$$Ewvz**Hwvz**Hgfi((Gwvz**HH   
+a.. ]P P P P P9-y/G P P Pf   9
%s   <A! !A6&A11A6