Re: 4-stable termios diff behaviour lc/lc_r

From: Julian Elischer (julian_at_vicor.com)
Date: 08/31/04

  • Next message: Geert Hendrickx: "Re: What is Stable"
    Date: Tue, 31 Aug 2004 11:36:10 -0700
    To: freebsd-stable@freebsd.org, threads@freebsd.org
    
    

    this should have been sent to -threads..
    --------------------------------------------
    >Hi list,
    >>
    >> I think I've found a possible bug in 4-stable, though I'm not that
    >> kind of an expert so I'll leave that decision up to you.
    >>
    >> Attached is a little test program that opens /dev/cuaa0 and tries to
    >> read a couple bytes.
    >>
    >> When compiled using "gcc vtime.c -o vtime" there's no problem. For
    >> example, when you run vtime without anything attached to cuaa0,
    >> it'll wait about 2 seconds and timeout, since VMIN=0 and VTIME=20.
    >>
    >> When compiled using "gcc -pthread vtime.c -o vtime" however, the
    >> read function returns immediately, which as far as I can understand,
    >> is not what it's supposed to do.
    >>
    >> Does anyone know if this intended or not, or how I can get the right
    >> behaviour in a threaded program?

    I've done some more testing. It appears that when linked with lc_r,
    VTIME is completely ignored.

    As explained in termios(4), when VMIN>0, the read call will wait
    indefinitely for the first byte and then use VTIME as an interbyte
    timer. When using lc_r however, it'll return immediately after the
    first couple bytes read, even if that's less than VMIN.

    The case where VTIME==0 works as it should both with lc and lc_r.

    I dont have access to a box with -current, so I can't say if the same
    applies to it.

    I hope somebody understands this better or could at least give me a
    few pointers as to where to look in the source code.

    Thanks, tijl
    -------------- next part --------------
    #include <fcntl.h>
    #include <stdio.h>
    #include <sys/types.h>
    #include <termios.h>
    #include <unistd.h>

    extern int errno;

    int main(void) {
            int fd, len;
            struct termios termset;
            uint8_t data[256];

            fd = open("/dev/cuaa0", O_RDWR | O_FSYNC);
            printf("%d %d\n", fd, errno);
            if (fd != -1) {
                    tcgetattr(fd, &termset);
                    cfmakeraw(&termset);
                    cfsetspeed(&termset, B9600);
                    termset.c_cc[VMIN] = 1;
                    termset.c_cc[VTIME] = 0;
                    tcsetattr(fd, TCSANOW, &termset);

                    len = read(fd, (void *) data, 3);
                    printf("%d\n", len);

                    close(fd);
            }
            return 0;
    }

    _______________________________________________
    freebsd-stable@freebsd.org mailing list
    http://lists.freebsd.org/mailman/listinfo/freebsd-stable
    To unsubscribe, send any mail to "freebsd-stable-unsubscribe@freebsd.org"


  • Next message: Geert Hendrickx: "Re: What is Stable"

    Relevant Pages

    • Re: Serial I/O from C
      ... VMIN and VTIME can be confusing. ... The timer is not started until the first character is received, ...
      (comp.os.linux.development.apps)
    • Re: Serialport termios & timeout
      ... for VTIME and VMIN I can do it, ... If VTIME and VMIN are both greater than 0 the timer is ... and will timeout if there is the ...
      (comp.os.linux.development.apps)
    • Re: 8ms Timer for serial port access
      ... >> or if VTIME deciseconds elapses between bytes, ... >> and readwill block until VMIN bytes are available. ... It is generally figured that "Advanced Programming in a Unix ... the other is "UNIX Network ...
      (comp.os.linux.development.apps)
    • Re: 8ms Timer for serial port access
      ... >> times for every frame I wait for. ... > If VTIME is zero and VMIN in non-zero, the timer is disabled, ... > and readwill block until VMIN bytes are available. ... > your 23 byte packet. ...
      (comp.os.linux.development.apps)
    • Re: Blocking read() from a USB->Serial adapter.
      ... I have to loop to read all the characters. ... Which makes it the same as a regular port. ... elements you are interested in are VTIME and VMIN. ...
      (comp.os.linux.development.apps)