Пример #1
0
def handle_pipe(self):
    #  Get just the commands off the pipe
    request = self.pipe.recv_multipart()
    command = request.pop(0).decode('UTF-8')
    if not command:
        return -1  # Interrupted

    if self.verbose:
        logger.debug("zbeacon: API command={0}".format(command))

    if command == "VERBOSE":
        self.verbose = True
    elif command == "CONFIGURE":
        port = struct.unpack('I', request.pop(0))[0]
        self.configure(port)
    elif command == "PUBLISH":
        self.transmit = request.pop(0)
        if self.interval == 0:
            self.interval = INTERVAL_DFLT
        # Start broadcasting immediately
        self.ping_at = time.time()
    elif command == "SILENCE":
        self.transmit = None
    elif command == "SUBSCRIBE":
        self.filter = request.pop(0)
    elif command == "UNSUBSCRIBE":
        self.filter = None
    elif command == "SEND BEACON":
        self.send_beacon(request.pop(0))
    elif command == "$TERM":
        self.terminated = True
    else:
        logger.error("zbeacon: - invalid command: {0}".format(command))
Пример #2
0
def handle_pipe(self):
    #  Get just the commands off the pipe
    request = self.pipe.recv_multipart()
    command = request.pop(0).decode('UTF-8')
    if not command:
        return -1                  #  Interrupted

    if self.verbose:
        logger.debug("zbeacon: API command={0}".format(command))

    if command == "VERBOSE":
        self.verbose = True
    elif command == "CONFIGURE":
        port = struct.unpack('I', request.pop(0))[0]
        self.configure(port)
    elif command == "PUBLISH":
        self.transmit = request.pop(0)
        if self.interval == 0:
            self.interval = INTERVAL_DFLT
        # Start broadcasting immediately
        self.ping_at = time.time()
    elif command == "SILENCE":
        self.transmit = None
    elif command == "SUBSCRIBE":
        self.filter = request.pop(0)
    elif command == "UNSUBSCRIBE":
        self.filter = None
    elif command == "SEND BEACON":
        self.send_beacon(request.pop(0))
    elif command == "$TERM":
        self.terminated = True
    else:
        logger.error("zbeacon: - invalid command: {0}".format(command))
Пример #3
0
def send_beacon(self, data=None):
    if data is None:
        data = self.transmit
    try:
        self.udpsock.sendto(data, (str(self.broadcast_address),
                                            self.port_nbr))
    except OSError:
        logger.debug("Network seems gone, exiting zbeacon")
        self.terminated = True
Пример #4
0
def send_beacon(self, data=None):
    if data is None:
        data = self.transmit
    try:
        self.udpsock.sendto(data, (str(self.broadcast_address), self.port_nbr))
    except OSError as e:
        # network down, just wait, it could come back up again.
        # socket call errors 50 and 51 relate to the network being
        # down or unreachable, the recommended action to take is to
        # try again so we don't terminate in these cases.
        if e.errno in [ENETDOWN, ENETUNREACH]:
            pass

        # all other cases, we'll terminate
        else:
            logger.debug("Network seems gone, exiting zbeacon")
            self.terminated = True

    except socket.error:
        logger.debug("Network seems gone, exiting zbeacon")
        self.terminated = True