Ejemplo n.º 1
0
 def handle(self, header, payload):
     handler = self._getHandler(header)
     if handler is None:
         global sock
         Handler.replyErr(sock)
     else:
         handler.handle(payload)
Ejemplo n.º 2
0
def run():
    dealer = Dealer()
    while True:
        data = sock.recv_multipart()
        if DEBUG: print "received %d parts" % len(data)
        if len(data) > 1:
            try:
                dealer.handle(data[3], data[4:])
            except Exception:
                Handler.replyErr(sock)
        else:
            Handler.replyErr(sock)
Ejemplo n.º 3
0
 def _getHandler(self, header):
     index = self.ucpacker.unpack(header[0])[0]
     if not 0 < index < len(self.handlerList):
         global sock
         Handler.replyErr(sock)
     return self.handlerList[index]
Ejemplo n.º 4
0
        index = self.ucpacker.unpack(header[0])[0]
        if 0 < index < len(self.handlerList):
            return getattr(self.handler, self.handlerList[index])

    def handle(self, header, payload):
        handle = self._getHandler(header)
        if handle is None:
            global sock
            Handler.replyErr(sock)
        else:
            handle(payload)


if __name__ == '__main__':
    if DEBUG: print 'running in DEBUG mode'
    dealer = Dealer()
    while True:
        try:
            data = sock.recv_multipart()
        except zmq.core.error.ZMQError:
            Handler.replyErr(sock)
            data = sock.recv_multipart()
        if DEBUG: print "received", len(data)
        if len(data) > 1:
            try:
                dealer.handle(data[0], data[1:])
            except Exception:
                Handler.replyErr(sock)
        else:
            Handler.replyErr(sock)