ó ÈHRc@`sÿdZddlmZmZddlmZmZmZmZm Z ddl Z ddl m Z ddl mZddlmZddlmZe eƒd ejejfd „ƒYƒZe eƒd ejejfd „ƒYƒZd „Zd dgZdS(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(tdivisiontabsolute_import(tepolltEPOLLHUPtEPOLLERRtEPOLLINtEPOLLOUTN(t implementer(t IReactorFDSet(tlog(t posixbaset_ContinuousPollingcB`sŒeZdZdZdZdZd„Zd„Zd„Zd„Z d„Z d „Z d „Z d „Z d „Zd „Zd„Zd„ZRS(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. iiicC`s.||_d|_tƒ|_tƒ|_dS(N(t_reactortNonet_looptsett_readerst_writers(tselftreactor((sA/usr/lib/python2.7/dist-packages/twisted/internet/epollreactor.pyt__init__;s   cC`sš|js|jrt|jdkr–ddlm}m}||jƒ|_|j|j_ |jj |dt ƒq–n"|jr–|jj ƒd|_ndS(sh Start or stop a C{LoopingCall} based on whether there are readers and writers. i(t LoopingCallt_EPSILONtnowN( RRRR ttwisted.internet.taskRRtiterateR tclocktstarttFalsetstop(RRR((sA/usr/lib/python2.7/dist-packages/twisted/internet/epollreactor.pyt _checkLoopBs  cC`sdx-t|jƒD]}|j|||jƒqWx-t|jƒD]}|j|||jƒq@WdS(sX Call C{doRead} and C{doWrite} on all readers and writers respectively. N(tlistRt_doReadOrWritet_POLL_INRt _POLL_OUT(Rtreader((sA/usr/lib/python2.7/dist-packages/twisted/internet/epollreactor.pyRTscC`s|jj|ƒ|jƒdS(sU Add a C{FileDescriptor} for notification of data available to read. N(RtaddR(RR#((sA/usr/lib/python2.7/dist-packages/twisted/internet/epollreactor.pyt addReader^scC`s|jj|ƒ|jƒdS(sV Add a C{FileDescriptor} for notification of data available to write. N(RR$R(Rtwriter((sA/usr/lib/python2.7/dist-packages/twisted/internet/epollreactor.pyt addWriterfscC`s7y|jj|ƒWntk r(dSX|jƒdS(sY Remove a C{FileDescriptor} from notification of data available to read. N(RtremovetKeyErrorR(RR#((sA/usr/lib/python2.7/dist-packages/twisted/internet/epollreactor.pyt removeReaderns  cC`s7y|jj|ƒWntk r(dSX|jƒdS(sb Remove a C{FileDescriptor} from notification of data available to write. N(RR(R)R(RR&((sA/usr/lib/python2.7/dist-packages/twisted/internet/epollreactor.pyt removeWriterys  cC`s4t|j|jBƒ}|jjƒ|jjƒ|S(s1 Remove all readers and writers. (RRRtclear(Rtresult((sA/usr/lib/python2.7/dist-packages/twisted/internet/epollreactor.pyt removeAll…s  cC`s t|jƒS(s/ Return a list of the readers. (RR(R((sA/usr/lib/python2.7/dist-packages/twisted/internet/epollreactor.pyt getReaders‘scC`s t|jƒS(s/ Return a list of the writers. (RR(R((sA/usr/lib/python2.7/dist-packages/twisted/internet/epollreactor.pyt getWriters˜scC`s ||jkS(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(Rtfd((sA/usr/lib/python2.7/dist-packages/twisted/internet/epollreactor.pyt isReadingŸs cC`s ||jkS(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(RR1((sA/usr/lib/python2.7/dist-packages/twisted/internet/epollreactor.pyt isWriting­s (t__name__t __module__t__doc__t_POLL_DISCONNECTEDR!R"RRRR%R'R*R+R.R/R0R2R3(((sA/usr/lib/python2.7/dist-packages/twisted/internet/epollreactor.pyR s        t EPollReactorcB`seZdZeeBZeZeZ d„Z d„Z d„Z d„Z d„Zd„Zd„Zd„Zd „Zd „Zd „ZeZRS( 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)}. cC`sStdƒ|_tƒ|_tƒ|_i|_t|ƒ|_tj j |ƒdS(sm Initialize epoll object, file descriptor tracking dictionaries, and the base class. iN( Rt_pollerRt_readst_writest _selectablesR t_continuousPollingR tPosixReactorBaseR(R((sA/usr/lib/python2.7/dist-packages/twisted/internet/epollreactor.pyRÞs    c C`s{|jƒ}||krw|}||krJ||O}|jj||ƒn|jj||ƒ|j|ƒ||| read/write for example). N(tfilenoR9tmodifytregisterR$( Rtxertprimarytothert selectablesteventt antieventR1tflags((sA/usr/lib/python2.7/dist-packages/twisted/internet/epollreactor.pyt_addîs     cC`sky)|j||j|j|jttƒWn;tk rf}|jtjkr`|j j |ƒqg‚nXdS(sR Add a FileDescriptor for notification of data available to read. N( RIR:R;R<RRtIOErrorterrnotEPERMR=R%(RR#te((sA/usr/lib/python2.7/dist-packages/twisted/internet/epollreactor.pyR% scC`sky)|j||j|j|jttƒWn;tk rf}|jtjkr`|j j |ƒqg‚nXdS(sS Add a FileDescriptor for notification of data available to write. N( RIR;R:R<RRRJRKRLR=R'(RR&RM((sA/usr/lib/python2.7/dist-packages/twisted/internet/epollreactor.pyR'sc C`s«|jƒ}|dkrLx1|jƒD]\}}||kr%Pq%q%WdSn||kr§||kr€|} |jj|| ƒn||=|jj|ƒ|j|ƒ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. iÿÿÿÿN(R?titemsR9R@t unregisterR(( RRBRCRDRERFRGR1tfdesRH((sA/usr/lib/python2.7/dist-packages/twisted/internet/epollreactor.pyt_remove+s     cC`sO|jj|ƒr&|jj|ƒdS|j||j|j|jttƒdS(sQ Remove a Selectable for notification of data available to read. N( R=R2R*RQR:R;R<RR(RR#((sA/usr/lib/python2.7/dist-packages/twisted/internet/epollreactor.pyR*Es cC`sO|jj|ƒr&|jj|ƒdS|j||j|j|jttƒdS(sR Remove a Selectable for notification of data available to write. N( R=R3R+RQR;R:R<RR(RR&((sA/usr/lib/python2.7/dist-packages/twisted/internet/epollreactor.pyR+Ps cC`sW|jg|jD]}|j|^qg|jD]}|j|^q0ƒ|jjƒS(sD Remove all selectables, and return a list of them. (t _removeAllR:R<R;R=R.(RR1((sA/usr/lib/python2.7/dist-packages/twisted/internet/epollreactor.pyR.[s #cC`s.g|jD]}|j|^q |jjƒS(N(R:R<R=R/(RR1((sA/usr/lib/python2.7/dist-packages/twisted/internet/epollreactor.pyR/es cC`s.g|jD]}|j|^q |jjƒS(N(R;R<R=R0(RR1((sA/usr/lib/python2.7/dist-packages/twisted/internet/epollreactor.pyR0js cC`sÈ|dkrd}ny"|jj|t|jƒƒ}Wn,tk re}|jtjkr_dS‚nX|j}xR|D]J\}}y|j|}Wnt k r¦qvXt j |||||ƒqvWdS(s1 Poll the poller for new events. iÿÿÿÿN( R R9tpolltlenR<RJRKtEINTRR R)R tcallWithLogger(Rttimeouttlterrt_drdwR1RFt selectable((sA/usr/lib/python2.7/dist-packages/twisted/internet/epollreactor.pytdoPollos  "  (R4R5R6RRR7RR!RR"RRIR%R'RQR*R+R.R/R0R\t doIteration(((sA/usr/lib/python2.7/dist-packages/twisted/internet/epollreactor.pyR8¼s          cC`s'tƒ}ddlm}||ƒdS(s& Install the epoll() reactor. i(tinstallReactorN(R8ttwisted.internet.mainR^(tpR^((sA/usr/lib/python2.7/dist-packages/twisted/internet/epollreactor.pytinstall‘s Ra(R6t __future__RRtselectRRRRRRKtzope.interfaceRttwisted.internet.interfacesRttwisted.pythonR ttwisted.internetR t_PollLikeMixint_DisconnectSelectableMixinR R>R8Rat__all__(((sA/usr/lib/python2.7/dist-packages/twisted/internet/epollreactor.pyt s(  ž Ô