Your IP : 172.28.240.42


Current Path : /usr/lib/python2.7/dist-packages/twisted/internet/
Upload File :
Current File : //usr/lib/python2.7/dist-packages/twisted/internet/epollreactor.pyc


Mc@sdZddlZddlmZddlmZddlmZmZddl	m
Z
de
je
jfdYZ
d	Zdd
gZdS(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()
iN(t
implements(t
IReactorFDSet(tlogt_epoll(t	posixbasetEPollReactorcBseZdZeeejejBZej	Z
ejZdZ
dZdZdZdZdZdZdZd	Zd
ZdZeZRS(sX
    A reactor that uses epoll(4).

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

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

    @ivar _reads: A dictionary mapping integer file descriptors to arbitrary
        values (this is essentially a set).  Keys in this dictionary will be
        registered with C{_poller} for read readiness notifications which will
        be dispatched to the corresponding L{FileDescriptor} instances in
        C{_selectables}.

    @ivar _writes: A dictionary mapping integer file descriptors to arbitrary
        values (this is essentially a set).  Keys in this dictionary will be
        registered with C{_poller} for write readiness notifications which will
        be dispatched to the corresponding L{FileDescriptor} instances in
        C{_selectables}.
    cCsAtjd|_i|_i|_i|_tjj|dS(sm
        Initialize epoll object, file descriptor tracking dictionaries, and the
        base class.
        iN(	Rtepollt_pollert_readst_writest_selectablesRtPosixReactorBaset__init__(tself((sA/usr/lib/python2.7/dist-packages/twisted/internet/epollreactor.pyR8s
			c
Csz|j}||krvtj}|}	||krI|	|O}	tj}n|jj|||	d||<|||<ndS(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).
        iN(tfilenoRtCTL_ADDtCTL_MODRt_control(
R
txertprimarytothertselectablesteventt	antieventtfdtcmdtflags((sA/usr/lib/python2.7/dist-packages/twisted/internet/epollreactor.pyt_addFs	

cCs/|j||j|j|jtjtjdS(sR
        Add a FileDescriptor for notification of data available to read.
        N(RRR	R
RtINtOUT(R
treader((sA/usr/lib/python2.7/dist-packages/twisted/internet/epollreactor.pyt	addReaderascCs/|j||j|j|jtjtjdS(sS
        Add a FileDescriptor for notification of data available to write.
        N(RR	RR
RRR(R
twriter((sA/usr/lib/python2.7/dist-packages/twisted/internet/epollreactor.pyt	addWriterhscCs|j}|dkrLx1|jD]\}}||kr%Pq%q%WdSn||krtj}	|}
||kr|}
tj}	n||=||=|jj|	||
ndS(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.
        iN(RtitemsRtCTL_DELRRR(R
RRRRRRRtfdesRR((sA/usr/lib/python2.7/dist-packages/twisted/internet/epollreactor.pyt_removeos	cCs/|j||j|j|jtjtjdS(sQ
        Remove a Selectable for notification of data available to read.
        N(R%RR	R
RRR(R
R((sA/usr/lib/python2.7/dist-packages/twisted/internet/epollreactor.pytremoveReaderscCs/|j||j|j|jtjtjdS(sR
        Remove a Selectable for notification of data available to write.
        N(R%R	RR
RRR(R
R ((sA/usr/lib/python2.7/dist-packages/twisted/internet/epollreactor.pytremoveWriterscCsJ|jg|jD]}|j|^qg|jD]}|j|^q0S(sD
        Remove all selectables, and return a list of them.
        (t
_removeAllRR
R	(R
R((sA/usr/lib/python2.7/dist-packages/twisted/internet/epollreactor.pyt	removeAlls cCs!g|jD]}|j|^q
S(N(RR
(R
R((sA/usr/lib/python2.7/dist-packages/twisted/internet/epollreactor.pyt
getReadersscCs!g|jD]}|j|^q
S(N(R	R
(R
R((sA/usr/lib/python2.7/dist-packages/twisted/internet/epollreactor.pyt
getWritersscCs|dkrd}nt|d}y"|jjt|j|}Wn,tk
ru}|jtjkrodSnX|j	}xR|D]J\}}y|j|}Wnt
k
rqXtj|||||qWdS(s1
        Poll the poller for new events.
        iiN(
tNonetintRtwaittlenR
tIOErrorterrnotEINTRt_doReadOrWritetKeyErrorRtcallWithLogger(R
ttimeouttlterrt_drdwRRt
selectable((sA/usr/lib/python2.7/dist-packages/twisted/internet/epollreactor.pytdoPolls 	"	
(t__name__t
__module__t__doc__RRRtHUPtERRt_POLL_DISCONNECTEDRt_POLL_INRt	_POLL_OUTRRRR!R%R&R'R)R*R+R;tdoIteration(((sA/usr/lib/python2.7/dist-packages/twisted/internet/epollreactor.pyRs"
														 cCs't}ddlm}||dS(s&
    Install the epoll() reactor.
    i(tinstallReactorN(Rttwisted.internet.mainRE(tpRE((sA/usr/lib/python2.7/dist-packages/twisted/internet/epollreactor.pytinstalls	RH(R>R1tzope.interfaceRttwisted.internet.interfacesRttwisted.pythonRRttwisted.internetRRt_PollLikeMixinRRHt__all__(((sA/usr/lib/python2.7/dist-packages/twisted/internet/epollreactor.pyt<module>s