ϪfVdZddlZddlmZmZmZmZmZmZ m Z ddl m Z ddl mZddlmZddlmZe eGdd ej&ej(Zd Zd d gZy) z A poll() 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 pollreactor pollreactor.install() N)POLLERRPOLLHUPPOLLINPOLLNVALPOLLOUTerrorpoll) implementer) posixbase) IReactorFDSet)logcneZdZdZeezezZeZ e Z dZ dZ dZdZdZdZdZd Zd ZeZd Zd Zy ) PollReactora^ A reactor that uses poll(2). @ivar _poller: A L{select.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{FileDescriptor}s 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}. ct|_i|_i|_i|_t j j|y)zo Initialize polling object, file descriptor tracking dictionaries, and the base class. N)r _poller _selectables_reads_writesr PosixReactorBase__init__)selfs >/usr/lib/python3/dist-packages/twisted/internet/pollreactor.pyrzPollReactor.__init__Cs7 v   ""++D1c6 |jj|d}||jvr |tz}||j vr |t z}|dk7r|jj||y||jvr|j|=yy#t$rYzwxYw)z*Register/unregister an fd with the poller.rN) r unregisterKeyErrorrrrrregisterr)rfdmasks r_updateRegistrationzPollReactor._updateRegistrationNs  LL # #B '  &=D  '>D 19 LL ! !"d +T&&&%%b)'   sB BBc |j}||||vr||=|j |yy#t$r-|jjD] \}}||us nYyYOwxYwN)fileno BaseExceptionritemsr )r selectablemdictrfdess r _dictRemovezPollReactor._dictRemove`s ""$B "I ;b  $ $R (  !--335 D%    s1-A'A'&A'c|j}||jvr0||j|<d|j|<|j|yy)z@Add a FileDescriptor for notification of data available to read.N)r#rrr )rreaderrs r addReaderzPollReactor.addReaderusI ]]_ T[[ $*D  b !DKKO  $ $R ( !rc|j}||jvr0||j|<d|j|<|j|yy)zAAdd a FileDescriptor for notification of data available to write.r+N)r#rrr )rwriterrs r addWriterzPollReactor.addWriter}sJ ]]_ T\\ !$*D  b ! DLL   $ $R ( "rc:|j||jS)z?Remove a Selectable for notification of data available to read.)r)r)rr,s r removeReaderzPollReactor.removeReaders 44rc:|j||jS)z@Remove a Selectable for notification of data available to write.)r)r)rr/s r removeWriterzPollReactor.removeWriters 55rc|j|jDcgc]}|j|c}|jDcgc]}|j|c}Scc}wcc}w)zD Remove all selectables, and return a list of them. ) _removeAllrrrrrs r removeAllzPollReactor.removeAllsU-1[[ 9rT  r " 9-1\\ :rT  r " :  9 :s AA" cf|t|dz} |jj|}|j}|D].\}} |j|}tj|||||0y#t$r+}|jdt j k(rYd}~yd}~wwxYw#t$rYtwxYw)zPoll the poller for new events.Nir) intrr SelectErrorargserrnoEINTR_doReadOrWriterrr callWithLogger)rtimeoutle_drdwreventr&s rdoPollzPollReactor.doPolls  'D.)G  !!'*A ## IIB !..r2   z5*b% H I  vvayEKK'    s/A-B$- B!6 BBB!$ B0/B0cZ|jDcgc]}|j|c}Scc}wr")rrr7s r getReaderszPollReactor.getReaderss%04 <"!!"%<<<(cZ|jDcgc]}|j|c}Scc}wr")rrr7s r getWriterszPollReactor.getWriterss%04 ="!!"%===rIN)__name__ __module__ __qualname____doc__rrr_POLL_DISCONNECTEDr_POLL_INr _POLL_OUTrr r)r-r0r2r4r8rF doIterationrHrKrrrr$sb2!7*X5HI 2*$)*))56 I,K=>rrc4t}ddlm}||y)zInstall the poll() reactor.r)installReactorN)rtwisted.internet.mainrV)prVs rinstallrYs A41rrY)rOr=selectrrrrrrr;r zope.interfacer twisted.internetr twisted.internet.interfacesr twisted.pythonr r_PollLikeMixinrrY__all__rTrrrasq '&5 ]M>),,i.F.FM>M>` ) $r