def METHOD_NAME(fd, settings):
    ssize = struct.calcsize("<iLiiLL")
    currtty, prevtime, prefdir = 0, 0, 0
    color = None
    stdout = sys.stdout.buffer
    while 1:
        try:
            (op, tty, length, dir, sec, usec) = struct.unpack("<iLiiLL", fd.read(ssize))
            data = fd.read(length)
        except struct.error:
            if settings["tail"]:
                prevtime = 0
                time.sleep(0.1)
                settings["maxdelay"] = 0
                continue
            break
        if currtty == 0:
            currtty = tty
        if str(tty) == str(currtty) and op == OP_WRITE:
            # the first stream seen is considered 'output'
            if prefdir == 0:
                prefdir = dir
                # use the other direction
                if settings["input_only"]:
                    prefdir = TYPE_INPUT
                    if dir == TYPE_INPUT:
                        prefdir = TYPE_OUTPUT
            if dir == TYPE_INTERACT:
                color = b"\033[36m"
            elif dir == TYPE_INPUT:
                color = b"\033[33m"
            if dir == prefdir or settings["both_dirs"]:
                curtime = float(sec) + float(usec) / 1000000
                if prevtime != 0:
                    sleeptime = curtime - prevtime
                    if sleeptime > settings["maxdelay"]:
                        sleeptime = settings["maxdelay"]
                    if settings["maxdelay"] > 0:
                        time.sleep(sleeptime)
                prevtime = curtime
                if settings["colorify"] and color:
                    stdout.write(color)
                stdout.write(data)
                if settings["colorify"] and color:
                    stdout.write(b"\033[0m")
                    color = None
                sys.stdout.flush()
        elif str(tty) == str(currtty) and op == OP_CLOSE:
            break