Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 14 Aug 2000 14:20:03 -0700 (PDT)
From:      "Daniel M. Eischen" <deischen@gdeb.com>
To:        freebsd-ports@FreeBSD.org
Subject:   Re: ports/20490: Termios timeout parameters, VMIN, VTIME, dont work with  Python.
Message-ID:  <200008142120.OAA11140@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help
The following reply was made to PR ports/20490; it has been noted by GNATS.

From: "Daniel M. Eischen" <deischen@gdeb.com>
To: freebsd-gnats-submit@FreeBSD.org, r_chipi@yahoo.com
Cc: tg@melaten.rwth-aachen.de
Subject: Re: ports/20490: Termios timeout parameters, VMIN, VTIME, dont work with 
 Python.
Date: Mon, 14 Aug 2000 17:13:39 -0400

 I don't think this is a libc_r problem.  The threads library sets
 all file descriptors to non-blocking and uses poll() to determine
 when data is ready.  But before poll()ing, the threads library
 performs a read() on the non-blocking socket.  It expects the
 return value to be -1 with errno set to EAGAIN if there is no
 data ready.  If you set the file to non-blocking in the example
 provided, read() returns 0 instead of -1.
 
 Another problem to arise, even if this is fixed, is that our
 current threads library knows nothing of VMIN/VTIME and tcsetattr().
 Since the file descriptor is non-blocking, the timer will not
 be effective, and the expected 20 second timeout will not occur.
 I'd expect the example program to block indefinitely until the
 requested (40 bytes of) data arrives.  This will work correctly
 when we get scheduler activations.  I don't think it is worth the
 time or effort to get the threads library to wrap tcsetattr() and
 emulate the effects of VMIN/VTIME.  If you want this to work with
 our current threads library, I would suggest recoding it to use
 select() or poll() to give you the needed timeout (and not use
 VMIN/VTIME).
 
 Here's the modified example:
 
 #include <stdio.h>
 #include <stdlib.h>
 #include <termios.h>
 #include <fcntl.h>
 
 #include <assert.h>
 #include <errno.h>
 
 main()
 {
     struct termios term;
     int fd, bytes, flags;
     char buf[80];
 
     fd = open("/dev/cuaa1", O_RDWR);
     if (fd < 0)
     {
 	perror("open");
 	return 1;
     }
 
     tcgetattr(fd, &term);
     term.c_cflag = CS8 | CREAD | CLOCAL;
     term.c_oflag &= ~OPOST;
     term.c_lflag = 0;
     term.c_cc[VMIN] = 0;
     term.c_cc[VTIME] = 200;
     tcsetattr(fd, TCSANOW, &term);
 
     assert((flags = fcntl(fd, F_GETFL, 0)) != -1);
     assert(fcntl(fd, F_SETFL, flags | O_NONBLOCK) == 0);
 
     bytes = read(fd, buf, 40);
     printf("Read returned %d, errno = %d\n", bytes, errno);
     buf[bytes] = 0;
     puts(buf);
     return 0;
 }
 
 --
 Dan Eischen
 


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-ports" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200008142120.OAA11140>