コード例 #1
0
ファイル: DummyHardware.py プロジェクト: RiceUBonnerLab/GLIB
    def serveForever(self):
        """The only function any user of this class needs to run!
        
        Receives, acts on, and responds to UDP control packets as the Mini-T (or similar hardware) would.
        Packets are received by the main thread and queued for action and response by a second thread.
        """
        chipsLog.info("Dummy Hardware UDP Server starting")
        # This starts the packet "act and respond" handler thread
        self.start()

        while not self.stopServing:
            try:
                data, addr = self._socket.recvfrom(DummyHardware.SOCKET_BUFFER_SIZE)
            except KeyboardInterrupt:
                chipsLog.warning("\nKeyboard interrupt (ctrl-c) received whilst waiting for incoming UDP packet")
                self._stopServingAndJoinThreads()
                return
            except:
                chipsLog.warning("\nException caught whilst waiting for incoming UDP packet")
                self._stopServingAndJoinThreads()
                return

            if not data:
                chipsLog.warning("Socket received an empty packet from " + repr(addr) + \
                                 ".  Assuming socket now closed.\nTerminating dummy hardware server...")
                self._stopServingAndJoinThreads()
                return
            else:
                chipsLog.debug("\nReceived packet from " + repr(addr))
                transaction = Transaction.constructHostTransaction(data, addr)
                self._transaction_queue.put(transaction)
コード例 #2
0
    def serveForever(self):
        """The only function any user of this class needs to run!
        
        Receives, acts on, and responds to TCP control packets as the Mini-T (or similar hardware) would.
        Packets are received by the main thread and queued for action and response by a second thread.
        """
        chipsLog.info("Dummy Hardware TCP Server starting")
        # This starts the packet "act and respond" handler thread
        self.start()

        try:
            chipsLog.debug("Awaiting connection...")
            self._connectedSocket, addr = self._socket.accept()  # TCP
            chipsLog.debug("Client connection accepted.")
        except KeyboardInterrupt:
            chipsLog.warning(
                "\nKeyboard interrupt (ctrl-c) received whilst waiting for a TCP connection"
            )
            self._stopServingAndJoinThreads()
            return

        while not self.stopServing:
            try:
                data = self._connectedSocket.recv(
                    DummyHardware.SOCKET_BUFFER_SIZE)  # TCP
            except KeyboardInterrupt:
                chipsLog.warning(
                    "\nKeyboard interrupt (ctrl-c) received whilst waiting for incoming TCP packet"
                )
                self._stopServingAndJoinThreads()
                return
            except:
                chipsLog.warning(
                    "\nException caught whilst waiting for incoming TCP packet"
                )
                self._stopServingAndJoinThreads()
                return

            if not data:
                chipsLog.debug("TCP socket received an empty packet from " +
                               repr(addr) + ": assuming connection closed.")
                try:
                    chipsLog.debug("Awaiting new connection...")
                    self._connectedSocket, addr = self._socket.accept()  # TCP
                    chipsLog.debug("Client connection accepted.")
                    continue
                except KeyboardInterrupt:
                    chipsLog.warning(
                        "\nKeyboard interrupt (ctrl-c) received whilst waiting for a TCP connection"
                    )
                    self._stopServingAndJoinThreads()
                    return

            chipsLog.debug("\nReceived TCP packet from " + repr(addr))
            transaction = Transaction.constructHostTransaction(data, addr)
            self._transaction_queue.put(transaction)

        chipsLog.info("Dummy Hardware TCP Server stopping.")
コード例 #3
0
ファイル: DummyHardware.py プロジェクト: RiceUBonnerLab/GLIB
    def serveForever(self):
        """The only function any user of this class needs to run!
        
        Receives, acts on, and responds to TCP control packets as the Mini-T (or similar hardware) would.
        Packets are received by the main thread and queued for action and response by a second thread.
        """
        chipsLog.info("Dummy Hardware TCP Server starting")
        # This starts the packet "act and respond" handler thread
        self.start()

        try:
            chipsLog.debug("Awaiting connection...")
            self._connectedSocket, addr = self._socket.accept()  # TCP
            chipsLog.debug("Client connection accepted.")            
        except KeyboardInterrupt:
            chipsLog.warning("\nKeyboard interrupt (ctrl-c) received whilst waiting for a TCP connection")
            self._stopServingAndJoinThreads()
            return            

        while not self.stopServing:
            try:
                data = self._connectedSocket.recv(DummyHardware.SOCKET_BUFFER_SIZE)  # TCP
            except KeyboardInterrupt:
                chipsLog.warning("\nKeyboard interrupt (ctrl-c) received whilst waiting for incoming TCP packet")
                self._stopServingAndJoinThreads()
                return
            except:
                chipsLog.warning("\nException caught whilst waiting for incoming TCP packet")
                self._stopServingAndJoinThreads()
                return

            if not data:
                chipsLog.debug("TCP socket received an empty packet from " + repr(addr) + ": assuming connection closed.")
                try:
                    chipsLog.debug("Awaiting new connection...")
                    self._connectedSocket, addr = self._socket.accept()  # TCP
                    chipsLog.debug("Client connection accepted.")            
                    continue
                except KeyboardInterrupt:
                    chipsLog.warning("\nKeyboard interrupt (ctrl-c) received whilst waiting for a TCP connection")
                    self._stopServingAndJoinThreads()
                    return            

            chipsLog.debug("\nReceived TCP packet from " + repr(addr))
            transaction = Transaction.constructHostTransaction(data, addr)
            self._transaction_queue.put(transaction)

        chipsLog.info("Dummy Hardware TCP Server stopping.")
コード例 #4
0
    def serveForever(self):
        """The only function any user of this class needs to run!
        
        Receives, acts on, and responds to UDP control packets as the Mini-T (or similar hardware) would.
        Packets are received by the main thread and queued for action and response by a second thread.
        """
        chipsLog.info("Dummy Hardware UDP Server starting")
        # This starts the packet "act and respond" handler thread
        self.start()

        while not self.stopServing:
            try:
                data, addr = self._socket.recvfrom(
                    DummyHardware.SOCKET_BUFFER_SIZE)
            except KeyboardInterrupt:
                chipsLog.warning(
                    "\nKeyboard interrupt (ctrl-c) received whilst waiting for incoming UDP packet"
                )
                self._stopServingAndJoinThreads()
                return
            except:
                chipsLog.warning(
                    "\nException caught whilst waiting for incoming UDP packet"
                )
                self._stopServingAndJoinThreads()
                return

            if not data:
                chipsLog.warning("Socket received an empty packet from " + repr(addr) + \
                                 ".  Assuming socket now closed.\nTerminating dummy hardware server...")
                self._stopServingAndJoinThreads()
                return
            else:
                chipsLog.debug("\nReceived packet from " + repr(addr))
                transaction = Transaction.constructHostTransaction(data, addr)
                self._transaction_queue.put(transaction)