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/kqreactor.pyc


[XMc@sdZddlZddlZddlmZddlmZmZmZm	Z	ddlm
Z
mZddlm
Z
ddlmZmZddlmZmZd	ejfd
YZdZd	dgZdS(
s
A kqueue()/kevent() 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 kqreactor
    | kqreactor.install()

This reactor only works on FreeBSD and requires PyKQueue 1.3, which is
available at:  U{http://people.freebsd.org/~dwhite/PyKQueue/}



You're going to need to patch PyKqueue::

    =====================================================
    --- PyKQueue-1.3/kqsyscallmodule.c	Sun Jan 28 21:59:50 2001
    +++ PyKQueue-1.3/kqsyscallmodule.c.new	Tue Jul 30 18:06:08 2002
    @@ -137,7 +137,7 @@
     }
     
     statichere PyTypeObject KQEvent_Type = {
    -  PyObject_HEAD_INIT(NULL)
    +  PyObject_HEAD_INIT(&PyType_Type)
       0,                             // ob_size
       "KQEvent",                     // tp_name
       sizeof(KQEventObject),         // tp_basicsize
    @@ -291,13 +291,14 @@
     
       /* Build timespec for timeout */
       totimespec.tv_sec = timeout / 1000;
    -  totimespec.tv_nsec = (timeout % 1000) * 100000;
    +  totimespec.tv_nsec = (timeout % 1000) * 1000000;
     
       // printf("timespec: sec=%d nsec=%d\n", totimespec.tv_sec, totimespec.tv_nsec);
     
       /* Make the call */
    -
    +  Py_BEGIN_ALLOW_THREADS
       gotNumEvents = kevent (self->fd, changelist, haveNumEvents, triggered, wantNumEvents, &totimespec);
    +  Py_END_ALLOW_THREADS
     
       /* Don't need the input event list anymore, so get rid of it */
       free (changelist);
    @@ -361,7 +362,7 @@
     statichere PyTypeObject KQueue_Type = {
            /* The ob_type field must be initialized in the module init function
             * to be portable to Windows without using C++. */
    -	PyObject_HEAD_INIT(NULL)
    +	PyObject_HEAD_INIT(&PyType_Type)
            0,			/*ob_size*/
            "KQueue",			/*tp_name*/
            sizeof(KQueueObject),	/*tp_basicsize*/

iN(t
implements(tEVFILT_READtEVFILT_WRITEt	EV_DELETEtEV_ADD(tkqueuetkevent(t
IReactorFDSet(tlogtfailure(tmaint	posixbaset
KQueueReactorcBseZdZeedZdZdZdZdZ	dZ
dZdZd	Z
d
ZdZeZRS(sQ
    A reactor that uses kqueue(2)/kevent(2).

    @ivar _kq: A L{kqueue} 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{_kq} 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{_kq} for write readiness notifications which will be
        dispatched to the corresponding L{FileDescriptor} instances in
        C{_selectables}.
    cCs;t|_i|_i|_i|_tjj|dS(sn
        Initialize kqueue object, file descriptor tracking dictionaries, and the
        base class.
        N(Rt_kqt_readst_writest_selectablesRtPosixReactorBaset__init__(tself((s>/usr/lib/python2.7/dist-packages/twisted/internet/kqreactor.pyRds
			cGs#|jjt|gdddS(Ni(R
R(Rtargs((s>/usr/lib/python2.7/dist-packages/twisted/internet/kqreactor.pyt_updateRegistrationpscCsO|j}||jkrK||j|<d|j|<|j|ttndS(sIAdd a FileDescriptor for notification of data available to read.
        iN(tfilenoRRRRR(Rtreadertfd((s>/usr/lib/python2.7/dist-packages/twisted/internet/kqreactor.pyt	addReaderss


cCsO|j}||jkrK||j|<d|j|<|j|ttndS(sJAdd a FileDescriptor for notification of data available to write.
        iN(RRRRRR(RtwriterR((s>/usr/lib/python2.7/dist-packages/twisted/internet/kqreactor.pyt	addWriter|s


cCs[|j}||jkrW|j|=||jkrA|j|=n|j|ttndS(sHRemove a Selectable for notification of data available to read.
        N(RRRRRRR(RRR((s>/usr/lib/python2.7/dist-packages/twisted/internet/kqreactor.pytremoveReaders

cCs[|j}||jkrW|j|=||jkrA|j|=n|j|ttndS(sIRemove a Selectable for notification of data available to write.
        N(RRRRRRR(RRR((s>/usr/lib/python2.7/dist-packages/twisted/internet/kqreactor.pytremoveWriters

cCsJ|jg|jD]}|j|^qg|jD]}|j|^q0S(sD
        Remove all selectables, and return a list of them.
        (t
_removeAllRRR(RR((s>/usr/lib/python2.7/dist-packages/twisted/internet/kqreactor.pyt	removeAlls cCs!g|jD]}|j|^q
S(N(RR(RR((s>/usr/lib/python2.7/dist-packages/twisted/internet/kqreactor.pyt
getReadersscCs!g|jD]}|j|^q
S(N(RR(RR((s>/usr/lib/python2.7/dist-packages/twisted/internet/kqreactor.pyt
getWriterssc
Cs|dkrd}nt|d}y%|jjgt|j|}Wn-tk
ry}|dtjkrsdSnX|j	}xh|D]`}d}|j
|j}}y|j|}	Wntk
rqnXt
j|	||	||qWdS(sPoll the kqueue for new events.iiN(tNonetintR
RtlenRtOSErrorterrnotEINTRt_doWriteOrReadtidenttfiltertKeyErrorRtcallWithLogger(
Rttimeouttltet_drdwteventtwhyRR*t
selectable((s>/usr/lib/python2.7/dist-packages/twisted/internet/kqreactor.pytdoKEvents$	%	

cCsyX|tkr|j}n|tkr9|j}n|j|ksWtj}nWn!tjd}t	j
nX|r|j||j||j
tj|ndS(Ni(RtdoReadRtdoWriteRR
tCONNECTION_LOSTtsystexc_infoRtdeferrRRtconnectionLostR	tFailure(RR3RR*R2((s>/usr/lib/python2.7/dist-packages/twisted/internet/kqreactor.pyR(s

(t__name__t
__module__t__doc__RRRRRRRRRR R!R4R(tdoIteration(((s>/usr/lib/python2.7/dist-packages/twisted/internet/kqreactor.pyRJs
							
	
						cCst}tj|dS(N(RR
tinstallReactor(tk((s>/usr/lib/python2.7/dist-packages/twisted/internet/kqreactor.pytinstalls	RC(R?R&R8tzope.interfaceRt	kqsyscallRRRRRRttwisted.internet.interfacesRttwisted.pythonRR	ttwisted.internetR
RRRRCt__all__(((s>/usr/lib/python2.7/dist-packages/twisted/internet/kqreactor.pyt<module>;s"