本文整理匯總了Python中twisted.internet.base.BasePort方法的典型用法代碼示例。如果您正苦於以下問題:Python base.BasePort方法的具體用法?Python base.BasePort怎麽用?Python base.BasePort使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類twisted.internet.base
的用法示例。
在下文中一共展示了base.BasePort方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: connectionLost
# 需要導入模塊: from twisted.internet import base [as 別名]
# 或者: from twisted.internet.base import BasePort [as 別名]
def connectionLost(self, reason):
"""
Cleans up the socket.
"""
self._logConnectionLostMsg()
self._realPortNumber = None
base.BasePort.connectionLost(self, reason)
self.connected = False
self._closeSocket(True)
del self.socket
del self.fileno
try:
self.factory.doStop()
finally:
self.disconnecting = False
示例2: connectionLost
# 需要導入模塊: from twisted.internet import base [as 別名]
# 或者: from twisted.internet.base import BasePort [as 別名]
def connectionLost(self, reason):
"""
Cleans up the socket.
"""
self._logConnectionLostMsg()
self._realPortNumber = None
base.BasePort.connectionLost(self, reason)
self.connected = False
self._closeSocket()
del self.socket
del self.fileno
try:
self.factory.doStop()
finally:
self.disconnecting = False
示例3: connectionLost
# 需要導入模塊: from twisted.internet import base [as 別名]
# 或者: from twisted.internet.base import BasePort [as 別名]
def connectionLost(self, reason=None):
"""Cleans up my socket.
"""
log.msg('(Port %s Closed)' % self._realPortNumber)
self._realPortNumber = None
base.BasePort.connectionLost(self, reason)
if hasattr(self, "protocol"):
# we won't have attribute in ConnectedPort, in cases
# where there was an error in connection process
self.protocol.doStop()
self.connected = 0
self.socket.close()
del self.socket
del self.fileno
if hasattr(self, "d"):
self.d.callback(None)
del self.d
示例4: __init__
# 需要導入模塊: from twisted.internet import base [as 別名]
# 或者: from twisted.internet.base import BasePort [as 別名]
def __init__(self, port, proto, interface='', maxPacketSize=8192, reactor=None):
"""
@param port: A port number on which to listen.
@type port: L{int}
@param proto: A C{DatagramProtocol} instance which will be
connected to the given C{port}.
@type proto: L{twisted.internet.protocol.DatagramProtocol}
@param interface: The local IPv4 or IPv6 address to which to bind;
defaults to '', ie all IPv4 addresses.
@type interface: L{str}
@param maxPacketSize: The maximum packet size to accept.
@type maxPacketSize: L{int}
@param reactor: A reactor which will notify this C{Port} when
its socket is ready for reading or writing. Defaults to
L{None}, ie the default global reactor.
@type reactor: L{interfaces.IReactorFDSet}
"""
base.BasePort.__init__(self, reactor)
self.port = port
self.protocol = proto
self.maxPacketSize = maxPacketSize
self.interface = interface
self.setLogStr()
self._connectedAddr = None
self._setAddressFamily()
示例5: connectionLost
# 需要導入模塊: from twisted.internet import base [as 別名]
# 或者: from twisted.internet.base import BasePort [as 別名]
def connectionLost(self, reason=None):
"""
Cleans up my socket.
"""
log.msg('(UDP Port %s Closed)' % self._realPortNumber)
self._realPortNumber = None
self.maxThroughput = -1
base.BasePort.connectionLost(self, reason)
self.protocol.doStop()
self.socket.close()
del self.socket
del self.fileno
if hasattr(self, "d"):
self.d.callback(None)
del self.d
示例6: __init__
# 需要導入模塊: from twisted.internet import base [as 別名]
# 或者: from twisted.internet.base import BasePort [as 別名]
def __init__(self, port, factory, backlog=50, interface='', reactor=None):
"""Initialize with a numeric port to listen on.
"""
base.BasePort.__init__(self, reactor=reactor)
self.port = port
self.factory = factory
self.backlog = backlog
if abstract.isIPv6Address(interface):
self.addressFamily = socket.AF_INET6
self._addressType = address.IPv6Address
self.interface = interface
示例7: createInternetSocket
# 需要導入模塊: from twisted.internet import base [as 別名]
# 或者: from twisted.internet.base import BasePort [as 別名]
def createInternetSocket(self):
s = base.BasePort.createInternetSocket(self)
if platformType == "posix" and sys.platform != "cygwin":
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
return s
示例8: test_listenFailure
# 需要導入模塊: from twisted.internet import base [as 別名]
# 或者: from twisted.internet.base import BasePort [as 別名]
def test_listenFailure(self):
"""
L{IReactorUNIX.listenUNIX} raises L{CannotListenError} if the
underlying port's createInternetSocket raises a socket error.
"""
def raiseSocketError(self):
raise error('FakeBasePort forced socket.error')
self.patch(base.BasePort, "createInternetSocket", raiseSocketError)
reactor = self.buildReactor()
with self.assertRaises(CannotListenError):
reactor.listenUNIX('not-used', ServerFactory())
示例9: _check_valid_port
# 需要導入模塊: from twisted.internet import base [as 別名]
# 或者: from twisted.internet.base import BasePort [as 別名]
def _check_valid_port(self, port):
"""Various Port object validity checks. Raise a ValueError."""
if not isinstance(port, BasePort):
raise ValueError("expected a Port, got %r"%(port))
if not port.connected:
raise ValueError("Port %r is not listening"%(port))
loc_addr = port.getHost()
if loc_addr.port == 0:
raise ValueError("Port %r has port number of 0"%(port))
示例10: __init__
# 需要導入模塊: from twisted.internet import base [as 別名]
# 或者: from twisted.internet.base import BasePort [as 別名]
def __init__(self, port, proto, interface='', maxPacketSize=8192, reactor=None):
"""
Initialize with a numeric port to listen on.
"""
base.BasePort.__init__(self, reactor)
self.port = port
self.protocol = proto
self.maxPacketSize = maxPacketSize
self.interface = interface
self.setLogStr()
self._connectedAddr = None
示例11: connectionLost
# 需要導入模塊: from twisted.internet import base [as 別名]
# 或者: from twisted.internet.base import BasePort [as 別名]
def connectionLost(self, reason=None):
"""
Cleans up my socket.
"""
log.msg('(Port %s Closed)' % self._realPortNumber)
self._realPortNumber = None
base.BasePort.connectionLost(self, reason)
self.protocol.doStop()
self.connected = 0
self.socket.close()
del self.socket
del self.fileno
if hasattr(self, "d"):
self.d.callback(None)
del self.d
示例12: __init__
# 需要導入模塊: from twisted.internet import base [as 別名]
# 或者: from twisted.internet.base import BasePort [as 別名]
def __init__(self, port, factory, backlog=50, interface='', reactor=None):
"""Initialize with a numeric port to listen on.
"""
base.BasePort.__init__(self, reactor=reactor)
self.port = port
self.factory = factory
self.backlog = backlog
self.interface = interface
示例13: __init__
# 需要導入模塊: from twisted.internet import base [as 別名]
# 或者: from twisted.internet.base import BasePort [as 別名]
def __init__(self, interface, proto, maxPacketSize=8192, reactor=None):
if components.implements(proto, ethernet.IEthernetProtocol):
self.ethernet = 1
else:
self.ethernet = 0
assert components.implements(proto, ip.IIPProtocol) # XXX: fix me
base.BasePort.__init__(self, reactor)
self.interface = interface
self.protocol = proto
self.maxPacketSize = maxPacketSize
self.setLogStr()
示例14: connectionLost
# 需要導入模塊: from twisted.internet import base [as 別名]
# 或者: from twisted.internet.base import BasePort [as 別名]
def connectionLost(self, reason=None):
"""Cleans up my socket.
"""
log.msg('(Tuntap %s Closed)' % self.interface)
base.BasePort.connectionLost(self, reason)
if hasattr(self, "protocol"):
# we won't have attribute in ConnectedPort, in cases
# where there was an error in connection process
self.protocol.doStop()
self.connected = 0
os.close(self.fd)
del self.fd
示例15: __init__
# 需要導入模塊: from twisted.internet import base [as 別名]
# 或者: from twisted.internet.base import BasePort [as 別名]
def __init__(self, port, proto, interface='', maxPacketSize=8192, reactor=None):
"""Initialize with a numeric port to listen on.
"""
base.BasePort.__init__(self, reactor)
self.port = port
self.protocol = proto
self.maxPacketSize = maxPacketSize
self.interface = interface
self.setLogStr()
self._connectedAddr = None