ó
ÈHRc           @`  sÿ   d  Z  d d l m Z m Z d d l m Z m Z m Z m Z m	 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	 e j e j f d
 „  ƒ  Yƒ Z e e ƒ d e j e j f d „  ƒ  Yƒ Z d „  Z d d g Z d S(   sõ   
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()
i    (   t   divisiont   absolute_import(   t   epollt   EPOLLHUPt   EPOLLERRt   EPOLLINt   EPOLLOUTN(   t   implementer(   t   IReactorFDSet(   t   log(   t	   posixbaset   _ContinuousPollingc           B`  sŒ   e  Z d  Z d Z d Z d Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d	 „  Z d
 „  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   s±  
    Schedule reads and writes based on the passage of time, rather than
    notification.

    This is useful for supporting polling filesystem files, which C{epoll(7)}
    does not support.

    The implementation uses L{posixbase._PollLikeMixin}, which is a bit hacky,
    but re-implementing and testing the relevant code yet again is
    unappealing.

    @ivar _reactor: The L{EPollReactor} that is using this instance.

    @ivar _loop: A C{LoopingCall} that drives the polling, or C{None}.

    @ivar _readers: A C{set} of C{FileDescriptor} objects that should be read
        from.

    @ivar _writers: A C{set} of C{FileDescriptor} objects that should be
        written to.
    i   i   i   c         C`  s.   | |  _  d  |  _ t ƒ  |  _ t ƒ  |  _ d  S(   N(   t   _reactort   Nonet   _loopt   sett   _readerst   _writers(   t   selft   reactor(    (    sO   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/internet/epollreactor.pyt   __init__;   s    		c         C`  sš   |  j  s |  j rt |  j d k r– d d l m } m } | |  j ƒ |  _ |  j |  j _	 |  j j
 | d t ƒq– n" |  j r– |  j j ƒ  d |  _ n  d S(   sh   
        Start or stop a C{LoopingCall} based on whether there are readers and
        writers.
        i    (   t   LoopingCallt   _EPSILONt   nowN(   R   R   R   R   t   twisted.internet.taskR   R   t   iterateR   t   clockt   startt   Falset   stop(   R   R   R   (    (    sO   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/internet/epollreactor.pyt
   _checkLoopB   s    	c         C`  sd   x- t  |  j ƒ D] } |  j | | |  j ƒ q Wx- t  |  j ƒ D] } |  j | | |  j ƒ q@ Wd S(   sX   
        Call C{doRead} and C{doWrite} on all readers and writers respectively.
        N(   t   listR   t   _doReadOrWritet   _POLL_INR   t	   _POLL_OUT(   R   t   reader(    (    sO   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/internet/epollreactor.pyR   T   s    c         C`  s   |  j  j | ƒ |  j ƒ  d S(   sU   
        Add a C{FileDescriptor} for notification of data available to read.
        N(   R   t   addR   (   R   R#   (    (    sO   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/internet/epollreactor.pyt	   addReader^   s    c         C`  s   |  j  j | ƒ |  j ƒ  d S(   sV   
        Add a C{FileDescriptor} for notification of data available to write.
        N(   R   R$   R   (   R   t   writer(    (    sO   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/internet/epollreactor.pyt	   addWriterf   s    c         C`  s7   y |  j  j | ƒ Wn t k
 r( d SX|  j ƒ  d S(   sY   
        Remove a C{FileDescriptor} from notification of data available to read.
        N(   R   t   removet   KeyErrorR   (   R   R#   (    (    sO   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/internet/epollreactor.pyt   removeReadern   s
    c         C`  s7   y |  j  j | ƒ Wn t k
 r( d SX|  j ƒ  d S(   sb   
        Remove a C{FileDescriptor} from notification of data available to
        write.
        N(   R   R(   R)   R   (   R   R&   (    (    sO   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/internet/epollreactor.pyt   removeWritery   s
    c         C`  s4   t  |  j |  j Bƒ } |  j j ƒ  |  j j ƒ  | S(   s1   
        Remove all readers and writers.
        (   R   R   R   t   clear(   R   t   result(    (    sO   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/internet/epollreactor.pyt	   removeAll…   s    c         C`  s   t  |  j ƒ S(   s/   
        Return a list of the readers.
        (   R   R   (   R   (    (    sO   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/internet/epollreactor.pyt
   getReaders‘   s    c         C`  s   t  |  j ƒ S(   s/   
        Return a list of the writers.
        (   R   R   (   R   (    (    sO   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/internet/epollreactor.pyt
   getWriters˜   s    c         C`  s   | |  j  k S(   sj  
        Checks if the file descriptor is currently being observed for read
        readiness.

        @param fd: The file descriptor being checked.
        @type fd: L{twisted.internet.abstract.FileDescriptor}
        @return: C{True} if the file descriptor is being observed for read
            readiness, C{False} otherwise.
        @rtype: C{bool}
        (   R   (   R   t   fd(    (    sO   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/internet/epollreactor.pyt	   isReadingŸ   s    c         C`  s   | |  j  k S(   sl  
        Checks if the file descriptor is currently being observed for write
        readiness.

        @param fd: The file descriptor being checked.
        @type fd: L{twisted.internet.abstract.FileDescriptor}
        @return: C{True} if the file descriptor is being observed for write
            readiness, C{False} otherwise.
        @rtype: C{bool}
        (   R   (   R   R1   (    (    sO   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/internet/epollreactor.pyt	   isWriting­   s    (   t   __name__t
   __module__t   __doc__t   _POLL_DISCONNECTEDR!   R"   R   R   R   R%   R'   R*   R+   R.   R/   R0   R2   R3   (    (    (    sO   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/internet/epollreactor.pyR      s    			
								t   EPollReactorc           B`  s   e  Z d  Z e e BZ 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 RS(   s†  
    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. filesytem files) that are not supported by
        C{epoll(7)}.
    c         C`  sS   t  d ƒ |  _ t ƒ  |  _ t ƒ  |  _ i  |  _ t |  ƒ |  _ t j	 j
 |  ƒ d S(   sm   
        Initialize epoll object, file descriptor tracking dictionaries, and the
        base class.
        i   N(   R   t   _pollerR   t   _readst   _writest   _selectablesR   t   _continuousPollingR
   t   PosixReactorBaseR   (   R   (    (    sO   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/internet/epollreactor.pyR   Þ   s    	c   	      C`  s{   | j  ƒ  } | | k rw | } | | k rJ | | O} |  j j | | ƒ n |  j j | | ƒ | j | ƒ | | | <n  d S(   sÖ   
        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(   t   filenoR9   t   modifyt   registerR$   (	   R   t   xert   primaryt   othert   selectablest   eventt	   antieventR1   t   flags(    (    sO   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/internet/epollreactor.pyt   _addî   s    
c         C`  sk   y) |  j  | |  j |  j |  j t t ƒ Wn; t k
 rf } | j t j k r` |  j	 j
 | ƒ qg ‚  n Xd S(   sR   
        Add a FileDescriptor for notification of data available to read.
        N(   RI   R:   R;   R<   R   R   t   IOErrort   errnot   EPERMR=   R%   (   R   R#   t   e(    (    sO   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/internet/epollreactor.pyR%   	  s    c         C`  sk   y) |  j  | |  j |  j |  j t t ƒ Wn; t k
 rf } | j t j k r` |  j	 j
 | ƒ qg ‚  n Xd S(   sS   
        Add a FileDescriptor for notification of data available to write.
        N(   RI   R;   R:   R<   R   R   RJ   RK   RL   R=   R'   (   R   R&   RM   (    (    sO   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/internet/epollreactor.pyR'     s    c   
      C`  s«   | j  ƒ  } | d k rL x1 | j ƒ  D] \ } } | | k r% Pq% q% Wd Sn  | | k r§ | | k r€ | }	 |  j j | |	 ƒ n | | =|  j j | ƒ | j | ƒ n  d S(   s·   
        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.
        iÿÿÿÿN(   R?   t   itemsR9   R@   t
   unregisterR(   (
   R   RB   RC   RD   RE   RF   RG   R1   t   fdesRH   (    (    sO   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/internet/epollreactor.pyt   _remove+  s    c         C`  sO   |  j  j | ƒ r& |  j  j | ƒ d S|  j | |  j |  j |  j t t ƒ d S(   sQ   
        Remove a Selectable for notification of data available to read.
        N(	   R=   R2   R*   RQ   R:   R;   R<   R   R   (   R   R#   (    (    sO   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/internet/epollreactor.pyR*   E  s
    c         C`  sO   |  j  j | ƒ r& |  j  j | ƒ d S|  j | |  j |  j |  j t t ƒ d S(   sR   
        Remove a Selectable for notification of data available to write.
        N(	   R=   R3   R+   RQ   R;   R:   R<   R   R   (   R   R&   (    (    sO   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/internet/epollreactor.pyR+   P  s
    c         C`  sW   |  j  g  |  j D] } |  j | ^ q g  |  j D] } |  j | ^ q0 ƒ |  j j ƒ  S(   sD   
        Remove all selectables, and return a list of them.
        (   t
   _removeAllR:   R<   R;   R=   R.   (   R   R1   (    (    sO   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/internet/epollreactor.pyR.   [  s     #c         C`  s.   g  |  j  D] } |  j | ^ q
 |  j j ƒ  S(   N(   R:   R<   R=   R/   (   R   R1   (    (    sO   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/internet/epollreactor.pyR/   e  s     c         C`  s.   g  |  j  D] } |  j | ^ q
 |  j j ƒ  S(   N(   R;   R<   R=   R0   (   R   R1   (    (    sO   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/internet/epollreactor.pyR0   j  s     c         C`  sÈ   | d k r d } n  y" |  j j | t |  j ƒ ƒ } Wn, t k
 re } | j t j k r_ d S‚  n X|  j } xR | D]J \ } } y |  j | } Wn t	 k
 r¦ qv Xt
 j | | | | | ƒ qv Wd S(   s1   
        Poll the poller for new events.
        iÿÿÿÿN(   R   R9   t   pollt   lenR<   RJ   RK   t   EINTRR    R)   R	   t   callWithLogger(   R   t   timeoutt   lt   errt   _drdwR1   RF   t
   selectable(    (    sO   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/internet/epollreactor.pyt   doPollo  s    	"	(   R4   R5   R6   R   R   R7   R   R!   R   R"   R   RI   R%   R'   RQ   R*   R+   R.   R/   R0   R\   t   doIteration(    (    (    sO   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/internet/epollreactor.pyR8   ¼   s    
								
			c          C`  s'   t  ƒ  }  d d l m } | |  ƒ d S(   s&   
    Install the epoll() reactor.
    i    (   t   installReactorN(   R8   t   twisted.internet.mainR^   (   t   pR^   (    (    sO   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/internet/epollreactor.pyt   install‘  s    	Ra   (   R6   t
   __future__R    R   t   selectR   R   R   R   R   RK   t   zope.interfaceR   t   twisted.internet.interfacesR   t   twisted.pythonR	   t   twisted.internetR
   t   _PollLikeMixint   _DisconnectSelectableMixinR   R>   R8   Ra   t   __all__(    (    (    sO   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/internet/epollreactor.pyt   <module>   s   (žÔ		