コード例 #1
0
def _updateFromSelf(sock,
                    instruction,
                    awakener,
                    sinfo,
                    client_id,
                    connection_type=''):
    try:
        if helper.isCmdUpdate(instruction):
            if not connection_type:
                sock.sendall(helper.getOkMessage())
            awakener.set()
            logging.debug('Requested update sent')

        elif not connection_type and helper.isCmdGet(instruction):

            sock.sendall(
                helper.getOkMessage(
                    '', '%c %s %c %s %c' % (gdata.SOH, client_id, gdata.ETX,
                                            buildXML(sinfo), gdata.ETX)))

            logging.debug('Requested get sent')

        else:
            sock.send(helper.getUnknownCmdError('Unknown command'))
            logging.debug('Request error sent')

    except socket.error, e:
        pass
コード例 #2
0
ファイル: srvhandlers.py プロジェクト: jponf/dremo
    def run(self):
        """run() -> void

        Handles the communication events and errors with a client.

        """
        CommandHandler._registerThread(CommandHandler, self)
        sock = self.sock
        sock.settimeout(self.timeout)

        try:
            while True:
                data = common.recvEnd(sock, '\n')
                # Connection closed
                if not data: break

                data = data.strip()

                if helper.isCmdQuit(data):          # QUIT
                    break

                elif helper.isCmdList(data):        # LIST
                    self._sendMonitorsList()

                elif helper.isCmdGetAll(data):      # GET ALL
                    self._sendGetAll()

                elif helper.isCmdUpdateAll(data):   # UPDATE ALL
                    self._sendUpdateAll()

                else:
                    cmd, sep, body = data.partition(' ')
                    body = body.strip()

                    if helper.isCmdGet(cmd):        # GET
                        self._handleGet(body)

                    elif helper.isCmdUpdate(cmd):   # UPDATE
                        self._handleUpdate(body)

                    else:
                        logging.info("Unknown command from %s:%d" % self.addr)
                        self.sock.sendall(
                                helper.getUnknownCmdError(
                                "Unknown command: %s" % data)
                            )           

        except socket.timeout:
            logging.debug("Socket TIMEOUT %s:%d" % self.addr)
            sock.sendall( helper.getTimeoutError(
                            "Reached timeout of %.1f seconds" % self.timeout) 
                        )
        except IOError:
            logging.warning("Error sending data to %s:%d" % self.addr)
        finally:
            sock.close()
            logging.debug("Command handler closed socket to %s:%s" % self.addr)
            CommandHandler._unregisterThread(CommandHandler, self)
コード例 #3
0
    def run(self):
        """run() -> void

        Handles the communication events and errors with a client.

        """
        CommandHandler._registerThread(CommandHandler, self)
        sock = self.sock
        sock.settimeout(self.timeout)

        try:
            while True:
                data = common.recvEnd(sock, '\n')
                # Connection closed
                if not data: break

                data = data.strip()

                if helper.isCmdQuit(data):  # QUIT
                    break

                elif helper.isCmdList(data):  # LIST
                    self._sendMonitorsList()

                elif helper.isCmdGetAll(data):  # GET ALL
                    self._sendGetAll()

                elif helper.isCmdUpdateAll(data):  # UPDATE ALL
                    self._sendUpdateAll()

                else:
                    cmd, sep, body = data.partition(' ')
                    body = body.strip()

                    if helper.isCmdGet(cmd):  # GET
                        self._handleGet(body)

                    elif helper.isCmdUpdate(cmd):  # UPDATE
                        self._handleUpdate(body)

                    else:
                        logging.info("Unknown command from %s:%d" % self.addr)
                        self.sock.sendall(
                            helper.getUnknownCmdError("Unknown command: %s" %
                                                      data))

        except socket.timeout:
            logging.debug("Socket TIMEOUT %s:%d" % self.addr)
            sock.sendall(
                helper.getTimeoutError("Reached timeout of %.1f seconds" %
                                       self.timeout))
        except IOError:
            logging.warning("Error sending data to %s:%d" % self.addr)
        finally:
            sock.close()
            logging.debug("Command handler closed socket to %s:%s" % self.addr)
            CommandHandler._unregisterThread(CommandHandler, self)
コード例 #4
0
ファイル: cli.py プロジェクト: jponf/dremo
def _updateFromSelf(sock, instruction, awakener, sinfo, client_id, connection_type=''):
    try:
        if helper.isCmdUpdate(instruction):
                if not connection_type:
                    sock.sendall(helper.getOkMessage())
                awakener.set()
                logging.debug('Requested update sent')

        elif not connection_type and helper.isCmdGet(instruction):
        	  
            sock.sendall(helper.getOkMessage('', '%c %s %c %s %c' % (gdata.SOH, client_id, 
            									gdata.ETX, buildXML(sinfo), gdata.ETX)))

            logging.debug('Requested get sent')

        else:
            sock.send(helper.getUnknownCmdError('Unknown command'))
            logging.debug('Request error sent')

    except socket.error, e:
        pass