Ejemplo n.º 1
0
    def reader(self):
        data = b''
        while self.alive:
            try:
                received_data = self.io.read()
                if not received_data:
                    continue
                data += received_data
                data, command_list = command_slicer(data)

                for sfp_command in command_list:
                    if sfp_command[3:4] == b'\x08':               # check if it's interrupt event
                        interrupt = self.decodefun(sfp_command)
                        with self.irq_available:
                            self.irq_requests.append(interrupt)
                            self.irq_available.notify()
                    else:
                        self.outq.put(sfp_command)
            except IOError as e:     # absorbs IOError if reading from closed socket due to race condition
                print("Absorb %s" % e)
                #raise e
                break
        # print("KILLLLLL")
        # os.kill(os.getpid(), signal.SIGTERM)
        self.alive = False
Ejemplo n.º 2
0
    def reader(self):
        data = b''
        while self.alive:
            try:
                received_data = self.io.read()
                if not received_data:
                    continue
                data += received_data
                data, command_list = command_slicer(data)

                for sfp_command in command_list:
                    if sfp_command[
                            3:4] == b'\x08':  # check if it's interrupt event
                        interrupt = self.decodefun(sfp_command)
                        with self.irq_available:
                            self.irq_requests.append(interrupt)
                            self.irq_available.notify()
                    else:
                        self.outq.put(sfp_command)
            except IOError as e:  # absorbs IOError if reading from closed socket due to race condition
                print("Absorb %s" % e)
                #raise e
                break
        # print("KILLLLLL")
        # os.kill(os.getpid(), signal.SIGTERM)
        self.alive = False
Ejemplo n.º 3
0
        s.bind(sa)
        s.listen(1)
    except socket.error as msg:
        s.close()
        s = None
        continue
    break
if s is None:
    print('could not open socket')
    sys.exit(1)
while True:
    conn, addr = s.accept()
    print('Connected by', addr)
    io_buffer = b''
    while True:
        received_data = conn.recv(1024)

        if not received_data:
            break

        io_buffer += received_data
        io_buffer, command_list = command_slicer(io_buffer)

        for sfp_command in command_list:
            sfp_machine_result = sfp_machine_instance.execute_sfp(sfp_command)
            if sfp_machine_result:
                conn.send(sfp_machine_result)
    sleep(1)
    conn.close()
    print("Closing connection.")
Ejemplo n.º 4
0
        s.bind(sa)
        s.listen(1)
    except socket.error as msg:
        s.close()
        s = None
        continue
    break
if s is None:
    print('could not open socket')
    sys.exit(1)
while True:
    conn, addr = s.accept()
    print('Connected by', addr)
    io_buffer = b''
    while True:
        received_data = conn.recv(1024)

        if not received_data:
            break

        io_buffer += received_data
        io_buffer, command_list = command_slicer(io_buffer)

        for sfp_command in command_list:
            sfp_machine_result = sfp_machine_instance.execute_sfp(sfp_command)
            if sfp_machine_result:
                conn.send(sfp_machine_result)
    sleep(1)
    conn.close()
    print("Closing connection.")