Exemplo n.º 1
0
 def dataReceived(self, data):
     """See `NetstringReceiver.dataReceived`."""
     NetstringReceiver.dataReceived(self, data)
     # XXX: JonathanLange 2007-10-16
     # bug=http://twistedmatrix.com/trac/ticket/2851: There are no hooks in
     # NetstringReceiver to catch a NetstringParseError. The best we can do
     # is check the value of brokenPeer.
     if self.brokenPeer:
         self.puller_protocol.unexpectedError(
             failure.Failure(NetstringParseError(data)))
Exemplo n.º 2
0
 def dataReceived(self, data):
     """See `NetstringReceiver.dataReceived`."""
     NetstringReceiver.dataReceived(self, data)
     # XXX: JonathanLange 2007-10-16
     # bug=http://twistedmatrix.com/trac/ticket/2851: There are no hooks in
     # NetstringReceiver to catch a NetstringParseError. The best we can do
     # is check the value of brokenPeer.
     if self.brokenPeer:
         self.puller_protocol.unexpectedError(
             failure.Failure(NetstringParseError(data)))
Exemplo n.º 3
0
def netstringsToBytes():
    """
    Create a new tube for encoding a sequence of discrete frames of bytes into
    DJB-style netstrings on the wire.

    @return: a L{tube <ITube>} that puts netstring length encoding around
        L{frames <IFrame>} to produce L{segments <ISegment>}.
    """
    return _SegmentsToFrames(NetstringReceiver())
Exemplo n.º 4
0
def bytesToNetstrings():
    """
    Create a new tube for converting a stream of byte segments containing
    DJB-style netstrings into bytes.

    @return: a L{tube <ITube>} that splits a stream of L{segments <ISegment>}
        containing nestrings into L{frame <IFrame>}.
    """
    return _FramesToSegments(NetstringReceiver())
Exemplo n.º 5
0
    def __init__(self, name, channel3_receiver, sub_proto):
        """
        @ivar name: Unique-ish name for the process I'm attached to.

        @ivar channel3_receiver: A function that will be called with
            L{Messages<ch3.Message>} when interesting log events happen.

        @ivar sub_proto: a C{ProcessProtocol} that will actually do interesting
            things with the stdout and write interesting stdin.  Actually,
            there's no guarantee that either input or output will be
            interesting.
        """
        self.done = defer.Deferred()
        self.started = defer.Deferred()
        self.name = name
        self.sub_proto = sub_proto
        self._ch3_receiver = channel3_receiver
        
        # some initialization happens in makeConnection
        self._ch3_netstring = NetstringReceiver()
        self._ch3_netstring.makeConnection(None)
        self._ch3_netstring.stringReceived = self._ch3DataReceived
Exemplo n.º 6
0
 def connectionLost(self, reason):
     NetstringReceiver.connectionLost(self, reason=reason)
     logger.info('connection lost to %s: %s' % (self.partner, str(reason)))
     self.router.removeConnection(self.partner)
Exemplo n.º 7
0
 def connectionLost(self, reason):
     NetstringReceiver.connectionLost(self, reason=reason)
     logger.info('connection to client %s lost: %s' % (self.transport.hostname, str(reason)))
Exemplo n.º 8
0
 def connectionLost(self, reason):
     """当连接失败时停止发送心跳包 """
     self.factory._paused = True
     log.error('connection lost: %s' % reason)
     NetstringReceiver.connectionLost(self,reason)
     self.stopHeartbeat()
Exemplo n.º 9
0
	def makeConnection( self, transport ):
		NetstringReceiver.makeConnection( self, transport )
		address = transport.getPeer()
		self.address = address.host
		self.factory.peer.connections[self.address] = self
Exemplo n.º 10
0
 def connectionMade(self):
     '''
     Connection made
     '''
     NetstringReceiver.connectionMade(self)
     self._manager.connected(self)
Exemplo n.º 11
0
 def makeConnection(self, process):
     """Called when the process has been created."""
     ProcessMonitorProtocolWithTimeout.makeConnection(self, process)
     NetstringReceiver.makeConnection(self, process)
     self.wire_protocol.makeConnection(process)
Exemplo n.º 12
0
 def connectionLost(self, reason):
     NetstringReceiver.connectionLost(self, reason=reason)
     logger.info('connection lost: %s' % str(reason))
Exemplo n.º 13
0
 def connectionLost(self, reason=connectionDone):
     self.controller.disconnected()
     NetstringReceiver.connectionLost(self, reason=reason)
Exemplo n.º 14
0
 def connectionMade(self):
     NetstringReceiver.connectionMade(self)
     self.controller.connection_established()
Exemplo n.º 15
0
 def makeConnection(self, process):
     """Called when the process has been created."""
     ProcessMonitorProtocolWithTimeout.makeConnection(self, process)
     NetstringReceiver.makeConnection(self, process)
     self.wire_protocol.makeConnection(process)
Exemplo n.º 16
0
 def connectionLost(self, reason):
     NetstringReceiver.connectionLost(self, reason)
     for (_, timer) in self.pendingCalls.itervalues():
         if not timer.called:
             timer.cancel()
Exemplo n.º 17
0
 def connectionLost(self, reason):
     NetstringReceiver.connectionLost(self, reason)
     for (_, timer) in six.itervalues(self.pendingCalls):
         if not timer.called:
             timer.cancel()
Exemplo n.º 18
0
class Channel3Protocol(protocol.ProcessProtocol):
    """
    I am a Channel3 logging protocol and also an C{IProcessTransport}.
    
    Use me like this::
    
        proto = MyProcessProtocol()
        log = []
        logger = Channel3Protocol('myprocess', log.append, proto)
        reactor.spawnProcess(logger, ...)
    
    @ivar done: A C{Deferred} which will fire when the process has 
        finished.
    @ivar started: A C{Deferred} which fires on my L{connectionMade}.
    """
    
    implements(interfaces.IProcessTransport)
    
    
    def __init__(self, name, channel3_receiver, sub_proto):
        """
        @ivar name: Unique-ish name for the process I'm attached to.

        @ivar channel3_receiver: A function that will be called with
            L{Messages<ch3.Message>} when interesting log events happen.

        @ivar sub_proto: a C{ProcessProtocol} that will actually do interesting
            things with the stdout and write interesting stdin.  Actually,
            there's no guarantee that either input or output will be
            interesting.
        """
        self.done = defer.Deferred()
        self.started = defer.Deferred()
        self.name = name
        self.sub_proto = sub_proto
        self._ch3_receiver = channel3_receiver
        
        # some initialization happens in makeConnection
        self._ch3_netstring = NetstringReceiver()
        self._ch3_netstring.makeConnection(None)
        self._ch3_netstring.stringReceived = self._ch3DataReceived


    def connectionMade(self):
        self.sub_proto.makeConnection(self)
        self.started.callback(self)


    def childDataReceived(self, childfd, data):
        if childfd == 3:
            self._ch3_netstring.dataReceived(data)
        else:
            self._ch3_receiver(ch3.fd(self.name, childfd, data))
        self.sub_proto.childDataReceived(childfd, data)


    def _ch3DataReceived(self, data):
        name, key, val = ch3.decode(data)
        name = '.'.join([self.name, name])
        self._ch3_receiver(ch3.Message(name, key, val))


    def inConnectionLost(self):
        self.sub_proto.inConnectionLost()


    def outConnectionLost(self):
        self.sub_proto.outConnectionLost()


    def errConnectionLost(self):
        self.sub_proto.errConnectionLost()


    def processExited(self, status):
        self.sub_proto.processExited(status)


    def processEnded(self, status):
        """
        XXX
        """
        self._ch3_receiver(ch3.exit(self.name,
                                    status.value.exitCode,
                                    status.value.signal))
        self.sub_proto.processEnded(status)
        self.done.callback(status)


    # IProcessTransport
    
    @property
    def pid(self):
        if self.transport:
            return self.transport.pid


    def closeStdin(self):
        return self.transport.closeStdin()


    def closeStdout(self):
        return self.transport.closeStdout()


    def closeStderr(self):
        return self.transport.closeStderr()


    def closeChildFD(self, descriptor):
        return self.transport.closeChildFD(descriptor)


    def loseConnection(self):
        return self.transport.loseConnection()


    def signalProcess(self, signal):
        return self.transport.signalProcess(signal)


    def getPeer(self):
        return self.transport.getPeer()


    def getHost(self):
        return self.transport.getHost()


    def write(self, data):
        """
        Write to stdin
        """
        self._ch3_receiver(ch3.fd(self.name, 0, data))
        return self.transport.write(data)


    def writeToChild(self, childFD, data):
        self._ch3_receiver(ch3.fd(self.name, childFD, data))
        return self.transport.writeToChild(childFD, data)


    def writeSequence(self, seq):
        for x in seq:
            self._ch3_receiver(ch3.fd(self.name, 0, x))
        return self.transport.writeSequence(seq)