From owner-freebsd-ports Mon Aug 14 14:20: 6 2000 Delivered-To: freebsd-ports@freebsd.org Received: from freefall.freebsd.org (freefall.FreeBSD.ORG [204.216.27.21]) by hub.freebsd.org (Postfix) with ESMTP id 991FB37B582 for ; Mon, 14 Aug 2000 14:20:03 -0700 (PDT) (envelope-from gnats@FreeBSD.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.9.3/8.9.2) id OAA11140; Mon, 14 Aug 2000 14:20:03 -0700 (PDT) (envelope-from gnats@FreeBSD.org) Date: Mon, 14 Aug 2000 14:20:03 -0700 (PDT) Message-Id: <200008142120.OAA11140@freefall.freebsd.org> To: freebsd-ports@FreeBSD.org Cc: From: "Daniel M. Eischen" Subject: Re: ports/20490: Termios timeout parameters, VMIN, VTIME, dont work with Python. Reply-To: "Daniel M. Eischen" Sender: owner-freebsd-ports@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org The following reply was made to PR ports/20490; it has been noted by GNATS. From: "Daniel M. Eischen" 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 #include #include #include #include #include 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