def _tcp_forward(self, tcp_status):
        ts = tcp_status
        ts.hand_shake()

        # Connection established

        ASIO.connect(ts.sock.fileno(), ts.queue, mtu=Environment.MTU_TCP, tag='from_external')
        
        # handshake done

        while True:
            try:
                tag, pkg_fd, pkg = ts.queue.get(timeout=0.1)
            except Empty:   # IO queue empty
                ts.resend_routine()
                continue

            print "   ###### tag:", tag
            if tag == 'from_external': # download data from relay node, forward to internal net
                ts.send(pkg)
            elif tag == 'from_internal': # outcoming data to relay node
                ts.receive(pkg)
            elif tag == 'check_buf':
                ts.resend_routine()
            elif tag == 'close':
                ts.close()
            elif tag == 'done':
                break

        print "tcp closed"
Exemple #2
0
    def read(self, file_path):
        while not self.writing:
            time.sleep(1)

        print "Read starting..."

        f = ASIO.open(file_path, opener=False)
        s = BufferedReader(f)

        orig_path = f.get_path()
        stale_since = None

        while True:
            if f is None:
                print 'Opening file...'
                f = ASIO.open(file_path, opener=False)
                s = BufferedReader(f)

            # Try read line
            line = s.readline()

            if line:
                stale_since = None
                time.sleep(0.05)
            else:
                if stale_since is None:
                    stale_since = time.time()
                    time.sleep(0.1)
                    continue
                elif (time.time() - stale_since) > 2 and f.get_path() != orig_path:
                    s.close()
                    s = None

                    f.close()
                    f = None
                elif not self.writing:
                    break
                else:
                    time.sleep(0.1)
                    continue

            print 'read %r' % (line,)

        print 'finished'
        s.close()
        f.close()
    def read_line(cls, timeout=30):
        if not cls.log_file:
            cls.log_file = ASIO.open(cls.get_path(), opener=False)
            cls.log_file.seek(cls.log_file.get_size(), SEEK_ORIGIN_CURRENT)
            cls.log_path = cls.log_file.get_path()
            Log.Info('Opened file path: "%s"' % cls.log_path)

        return cls.log_file.read_line(timeout=timeout, timeout_type='return')
    def read_line(cls, timeout=30):
        if not cls.log_file:
            cls.log_file = ASIO.open(cls.get_path(), opener=False)
            cls.log_file.seek(cls.log_file.get_size(), SEEK_ORIGIN_CURRENT)
            cls.log_path = cls.log_file.get_path()
            log.info('Opened file path: "%s"' % cls.log_path)

        return cls.log_file.read_line(timeout=timeout, timeout_type='return')
Exemple #5
0
def read(path):
    f = ASIO.open(path, opener=False)
    orig_path = f.get_path()

    size = f.get_size()
    print "Seeking to end, %s" % size
    print f.seek(size, SEEK_ORIGIN_CURRENT)

    while True:
        line = f.read_line(timeout=1, timeout_type='return')
        if not line and f.get_path() != orig_path:
            f.close()
            return

        print line

    f.close()
    def read_line(self):
        if not self.file:
            path = self.get_path()
            if not path:
                raise Exception('Unable to find the location of "Plex Media Server.log"')

            # Open file
            self.file = ASIO.open(path, opener=False)
            self.file.seek(self.file.get_size(), SEEK_ORIGIN_CURRENT)

            # Create buffered reader
            self.reader = BufferedReader(self.file)

            self.path = self.file.get_path()
            log.info('Opened file path: "%s"' % self.path)

        return self.reader.readline()
    def read_line(self):
        if not self.file:
            path = self.get_path()
            if not path:
                raise Exception(
                    'Unable to find the location of "Plex Media Server.log"')

            # Open file
            self.file = ASIO.open(path, opener=False)
            self.file.seek(self.file.get_size(), SEEK_ORIGIN_CURRENT)

            # Create buffered reader
            self.reader = BufferedReader(self.file)

            self.path = self.file.get_path()
            log.info('Opened file path: "%s"' % self.path)

        return self.reader.readline()