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


}3Nc@szdZddlZddlZddlZddlZddlmZddlmZedkrddl	m
Zddl	mZ
ddl	mZdd	l	mZdd
l	mZeZn(ddl	mZm
Z
mZmZmZddlmZmZmZdd
lmZmZddlmZmZmZdejfdYZdddYZ de efdYZ!dS(sp
Various asynchronous UDP classes.

Please do not use this module directly.

Maintainer: Itamar Shtull-Trauring
iN(t
implements(tplatformTypetwin32(tWSAEWOULDBLOCK(tWSAEINTR(tWSAEMSGSIZE(tWSAECONNREFUSED(t
WSAECONNRESET(tEWOULDBLOCKtEINTRtEMSGSIZEtECONNREFUSEDtEAGAIN(tbasetdefertaddress(tlogtfailure(tabstractterrort
interfacestPortcBseZdZeejejejej	Z
ejZdZ
dZddddZdZdZdZd	Zd
ZdZddZd
ZdZdZdZdZddZdZdZdZ RS(s*
    UDP port, listening for packets.
    iiti cCsNtjj||||_||_||_||_|jd|_	dS(s>
        Initialize with a numeric port to listen on.
        N(
R
tBasePortt__init__tporttprotocolt
maxPacketSizet	interfacet	setLogStrtNonet_connectedAddr(tselfRtprotoRRtreactor((s8/usr/lib/python2.7/dist-packages/twisted/internet/udp.pyR6s				
cCs;|jdk	r&d|jj|jfSd|jjfSdS(Ns
<%s on %s>s<%s not connected>(t_realPortNumberRRt	__class__(R ((s8/usr/lib/python2.7/dist-packages/twisted/internet/udp.pyt__repr__BscCs|jS(s)
        Return a socket object.
        (tsocket(R ((s8/usr/lib/python2.7/dist-packages/twisted/internet/udp.pyt	getHandleHscCs|j|jdS(s
        Create and bind my socket, and begin listening on it.

        This is called on unserialization, and must be called after creating a
        server to begin listening on the specified port.
        N(t_bindSockett_connectToProtocol(R ((s8/usr/lib/python2.7/dist-packages/twisted/internet/udp.pytstartListeningNs
cCsy)|j}|j|j|jfWn1tjk
r\}tj|j|j|fnX|jd|_t	j
d|j|j|jfd|_
||_|jj|_dS(Nis%s starting on %s(tcreateInternetSockettbindRRR&RtCannotListenErrortgetsocknameR#Rtmsgt
_getLogPrefixRt	connectedtfileno(R tskttle((s8/usr/lib/python2.7/dist-packages/twisted/internet/udp.pyR(Xs			cCs|jj||jdS(N(RtmakeConnectiontstartReading(R ((s8/usr/lib/python2.7/dist-packages/twisted/internet/udp.pyR)jscCsd}x||jkry|jj|j\}}Wntjk
r}|jd}|tttfkrrdS|t	kst
dkr|tkr|jr|j
jqqq	X|t|7}y|j
j||Wq	tjq	Xq	WdS(s=
        Called when my socket is ready for reading.
        iNR(t
maxThroughputR&trecvfromRRtargsRR	RRRRRRtconnectionRefusedtlentdatagramReceivedRterr(R treadtdatataddrtsetno((s8/usr/lib/python2.7/dist-packages/twisted/internet/udp.pytdoReados"
$	cCs|jr|d	|jfks$ty|jj|SWqtjk
r}|jd}|tkrs|j|S|t	krtj
dq|tkr|jj
qqXn|d	kst|djddjr|ddkrtjdtddny|jj||SWnmtjk
r}|jd}|tkra|j||S|t	kr|tj
dq|tkrd	SnXd	S(
sz
        Write a datagram.

        @type datagram: C{str}
        @param datagram: The datagram to be sent.

        @type addr: C{tuple} containing C{str} as first element and C{int} as
            second element, or C{None}
        @param addr: A tuple of (I{stringified dotted-quad IP address},
            I{integer port number}); can be C{None} in connected mode.
        ismessage too longt.Rs<broadcast>s.Please only pass IPs to write(), not hostnamest
stackleveliN(RRtAssertionErrorR&tsendRR9R	twriteR
tMessageLengthErrorRRR:treplacetisdigittwarningstwarntDeprecationWarningtsendto(R tdatagramR@RARB((s8/usr/lib/python2.7/dist-packages/twisted/internet/udp.pyRHs8	


-	
cCs|jdj||dS(NR(RHtjoin(R tseqR@((s8/usr/lib/python2.7/dist-packages/twisted/internet/udp.pyt
writeSequencescCsY|jrtdntj|s0tdn||f|_|jj||fdS(s-
        'Connect' to remote server.
        s\already connected, reconnecting is not currently supported (talk to itamar if you want this)s/please pass only IP addresses, not domain namesN(RtRuntimeErrorRtisIPAddresst
ValueErrorR&tconnect(R thostR((s8/usr/lib/python2.7/dist-packages/twisted/internet/udp.pyRWs	cCs0|j|jr,|jjd|jndS(Ni(tstopReadingR1R"t	callLatertconnectionLost(R ((s8/usr/lib/python2.7/dist-packages/twisted/internet/udp.pyt_loseConnections
	cCs3|jrtj}|_nd}|j|S(N(R1RtDeferredtdRR\(R tresult((s8/usr/lib/python2.7/dist-packages/twisted/internet/udp.pyt
stopListenings
	
cCs$tjdtdd|jdS(Ns-Please use stopListening() to disconnect portREi(RLRMRNR`(R ((s8/usr/lib/python2.7/dist-packages/twisted/internet/udp.pytloseConnectionscCstjd|jd|_tjj|||jj|j	j
|`	|`t|dr~|j
jd|`
ndS(s&
        Cleans up my socket.
        s(UDP Port %s Closed)R^N(RR/R#RR
RR[RtdoStopR&tcloseR2thasattrR^tcallback(R treason((s8/usr/lib/python2.7/dist-packages/twisted/internet/udp.pyR[s	

cCs#|j|j}d||_dS(sP
        Initialize the C{logstr} attribute to be used by C{logPrefix}.
        s%s (UDP)N(R0Rtlogstr(R t	logPrefix((s8/usr/lib/python2.7/dist-packages/twisted/internet/udp.pyRscCs|jS(s0
        Return the prefix to log with.
        (Rg(R ((s8/usr/lib/python2.7/dist-packages/twisted/internet/udp.pyRhscCstjd|jjS(si
        Returns an IPv4Address.

        This indicates the address from which I am connecting.
        tUDP(RtIPv4AddressR&R.(R ((s8/usr/lib/python2.7/dist-packages/twisted/internet/udp.pytgetHostsiN(!t__name__t
__module__t__doc__RRtIListeningPortt
IUDPTransportt
ISystemHandleR&tAF_INETt
addressFamilyt
SOCK_DGRAMt
socketTypeR7RR#RR%R'R*R(R)RCRHRSRWR\R`RaR[RRhRk(((s8/usr/lib/python2.7/dist-packages/twisted/internet/udp.pyR&s2
					
			/							tMulticastMixincBsweZdZdZdZdZdZdZdZdZ	dd	Z
d
ZdZddZ
RS(
s,
    Implement multicast functionality.
    cCs4|jjtjtj}tjtjd|S(Ns@i(R&t
getsockoptt
IPPROTO_IPtIP_MULTICAST_IFt	inet_ntoatstructtpack(R ti((s8/usr/lib/python2.7/dist-packages/twisted/internet/udp.pytgetOutgoingInterfacescCs|jj|j|jS(sReturns Deferred of success.(R"tresolvetaddCallbackt
_setInterface(R R@((s8/usr/lib/python2.7/dist-packages/twisted/internet/udp.pytsetOutgoingInterfacescCs/tj|}|jjtjtj|dS(Ni(R&t	inet_atont
setsockoptRxRy(R R@R}((s8/usr/lib/python2.7/dist-packages/twisted/internet/udp.pyRscCs|jjtjtjS(N(R&RwRxtIP_MULTICAST_LOOP(R ((s8/usr/lib/python2.7/dist-packages/twisted/internet/udp.pytgetLoopbackModescCs;tjdtj|}|jjtjtj|dS(Ntb(R{R|toperatorttruthR&RRxR(R tmode((s8/usr/lib/python2.7/dist-packages/twisted/internet/udp.pytsetLoopbackModescCs|jjtjtjS(N(R&RwRxtIP_MULTICAST_TTL(R ((s8/usr/lib/python2.7/dist-packages/twisted/internet/udp.pytgetTTLscCs2tjd|}|jjtjtj|dS(NtB(R{R|R&RRxR(R tttl((s8/usr/lib/python2.7/dist-packages/twisted/internet/udp.pytsetTTLsRcCs"|jj|j|j|dS(s4Join a multicast group. Returns Deferred of success.i(R"RRt
_joinAddr1(R R@R((s8/usr/lib/python2.7/dist-packages/twisted/internet/udp.pyt	joinGroupscCs"|jj|j|j||S(N(R"RRt
_joinAddr2(R R@RRQ((s8/usr/lib/python2.7/dist-packages/twisted/internet/udp.pyR#scCstj|}tj|}|r0tj}n	tj}y!|jjtj|||Wn2tjk
r}tjtj	|||j
SXdS(N(R&RtIP_ADD_MEMBERSHIPtIP_DROP_MEMBERSHIPRRxRRtFailuretMulticastJoinErrorR9(R RR@RQtcmdte((s8/usr/lib/python2.7/dist-packages/twisted/internet/udp.pyR&s	!cCs"|jj|j|j|dS(s2Leave multicast group, return Deferred of success.i(R"RRR(R R@R((s8/usr/lib/python2.7/dist-packages/twisted/internet/udp.pyt
leaveGroup2s(RlRmRnR~RRRRRRRRRR(((s8/usr/lib/python2.7/dist-packages/twisted/internet/udp.pyRvs									t
MulticastPortcBs9eZdZeejdddedZdZ	RS(s.
    UDP Port that supports multicasting.
    Ri cCs)tj||||||||_dS(sX
        @see: L{twisted.internet.interfaces.IReactorMulticast.listenMulticast}
        N(RRtlistenMultiple(R RR!RRR"R((s8/usr/lib/python2.7/dist-packages/twisted/internet/udp.pyR>scCsctj|}|jr_|jtjtjdttdr_|jtjtjdq_n|S(NitSO_REUSEPORT(	RR+RRR&t
SOL_SOCKETtSO_REUSEADDRRdR(R R3((s8/usr/lib/python2.7/dist-packages/twisted/internet/udp.pyR+Es	N(
RlRmRnRRtIMulticastTransportRtFalseRR+(((s8/usr/lib/python2.7/dist-packages/twisted/internet/udp.pyR7s
(("RnR&RR{RLtzope.interfaceRttwisted.python.runtimeRterrnoRRRR	RR
RRRRttwisted.internetR
RRttwisted.pythonRRRRRRRRvR(((s8/usr/lib/python2.7/dist-packages/twisted/internet/udp.pyt<module>s(	(8