示例#1
0
def EBRPC_ReplicationServer(port, ebrpc):
    factory = protocol.Factory()
    factory.children = set()
    factory.protocol = RepeaterProtocol

    def render(request):
        request.content.seek(0, 0)
        if hasattr(request.content, 'getvalue'):
            c = request.content.getvalue()
            for child in factory.children:
                # don't worry, write is non-blocking
                child.transport.write(ebencode.make_int(len(c)))
                child.transport.write(c)
        else:
            c = buffer.Buffer()
            while True:
                b = request.content.read(100000)
                if len(b) == 0:
                    break
                c.write(b)
            c = str(c)
            for child in factory.children:
                # don't worry, write is non-blocking
                child.transport.write(ebencode.make_int(len(c)))
                child.transport.write(c)
            request.content.seek(0, 0)

    ebrpc.render = decorate_func(render, ebrpc.render)
    reactor.listenTCP(port, factory)
示例#2
0
def EBRPC_ReplicationServer(port, ebrpc):
    factory = protocol.Factory()
    factory.children = set()
    factory.protocol = RepeaterProtocol
    def render(request):
        request.content.seek(0, 0)
        if hasattr(request.content, 'getvalue'):
            c = request.content.getvalue()
            for child in factory.children:
                # don't worry, write is non-blocking
                child.transport.write(ebencode.make_int(len(c)))
                child.transport.write(c)
        else:
            c = buffer.Buffer()
            while True:
                b = request.content.read(100000)
                if len(b) == 0:
                    break
                c.write(b)
            c = str(c)
            for child in factory.children:
                # don't worry, write is non-blocking
                child.transport.write(ebencode.make_int(len(c)))
                child.transport.write(c)
            request.content.seek(0, 0)                    
    ebrpc.render = decorate_func(render, ebrpc.render)
    reactor.listenTCP(port, factory)
示例#3
0
文件: protocol.py 项目: safvan010/123
    def buildProtocol(self, addr):
        prot = protocol.ReconnectingClientFactory.buildProtocol(self, addr)

        # decorate the protocol with a delay reset
        prot.connectionMade = decorate_func(self.resetDelay,
                                            prot.connectionMade)
        
        return prot    
示例#4
0
 def connect(self):
     if debug: print 'connecting', self.host, self.port
     self.started()
     try:
         if self.protocol == 'SSL':
             self.connector = self.reactor.old_connectSSL(
                 self.host, self.port, self.factory, *self.a, **self.kw)
         else:
             self.connector = self.reactor.old_connectTCP(
                 self.host, self.port, self.factory, *self.a, **self.kw)
         # because other callbacks use this one
         self.connector.wasPreempted = self.wasPreempted
     except:
         # make sure failures get removed before we raise
         self.complete()
         raise
     # if connect is re-called on the connector, we want to restart
     self.connector.connect = decorate_func(self.started,
                                            self.connector.connect)
     return self
 def connect(self):
     if debug: print 'connecting', self.host, self.port
     self.started()
     try:
         if self.protocol == 'SSL':
             self.connector = self.reactor.old_connectSSL(self.host,
                                                          self.port,
                                                          self.factory,
                                                          *self.a, **self.kw)
         else:
             self.connector = self.reactor.old_connectTCP(self.host,
                                                          self.port,
                                                          self.factory,
                                                          *self.a, **self.kw)
         # because other callbacks use this one
         self.connector.wasPreempted = self.wasPreempted
     except:
         # make sure failures get removed before we raise
         self.complete()
         raise
     # if connect is re-called on the connector, we want to restart
     self.connector.connect = decorate_func(self.started,
                                            self.connector.connect)
     return self
 def buildProtocol(self, addr):
     p = self.factory.buildProtocol(addr)
     p.connectionMade = decorate_func(self.connector.complete,
                                      p.connectionMade)
     return p
 def buildProtocol(self, addr):
     p = self.factory.buildProtocol(addr)
     p.connectionMade = decorate_func(self.connector.complete,
                                      p.connectionMade)
     return p