This is the mail archive of the
libc-help@sourceware.org
mailing list for the glibc project.
Re: select stops after first byte even when more bytes are available
- From: Godmar Back <godmar at gmail dot com>
- To: Przemek <przemekr at sdfeu dot org>
- Cc: "libc-help at sourceware dot org" <libc-help at sourceware dot org>
- Date: Fri, 3 Apr 2015 11:02:11 -0400
- Subject: Re: select stops after first byte even when more bytes are available
- Authentication-results: sourceware.org; auth=none
- References: <43b1b3ceab67b616b8ebc1ebab33df38 at mx dot sdfeu dot org>
stdio uses buffering, select is a system call, the terminal is line-oriented.
On Fri, Apr 3, 2015 at 10:22 AM, Przemek <przemekr@sdfeu.org> wrote:
> Hi,
>
> I noticed this select behaviour and I am not sure if it is a bug. Can not
> understand why it happens.
> Here is a small test program:
>
> #include <stdio.h>
> #include <sys/select.h>
> int
> main(void)
> {
> fd_set rfds;
> struct timeval tv;
> int retval;
>
> while (1)
> {
> FD_ZERO(&rfds);
> FD_SET(fileno(stdin), &rfds);
>
> retval = select(1, &rfds, 0, 0, 0);
> if (retval == -1)
> perror("select()");
>
> if (FD_ISSET(fileno(stdin), &rfds))
> printf("R:%02x\n", getc(stdin));
> }
> return 0;
> }
>
>
>
> Then I run it, write a few characters on a first line, hit enter, and only
> one number appears on the terminal back. Then I type some more characters on
> a second line, enter, and I have all the missing numbers from the first line
> + all the numbers from the second one:
>
> $ ./select_issue
> abcd
> R:61
> efgh
> R:62
> R:63
> R:64
> R:0a
> R:65
>
> When the terminal is set to 'per char mode', select returns after every key
> pressed, but the issue is still there when I paste several characters at
> once (only the first character code is displayed, then program waits for
> more input).
>
> GCC (Ubuntu 4.8.2-19ubuntu1) 4.8.2
> GNU C Library (Ubuntu EGLIBC 2.19-0ubuntu6.6) stable release version 2.19
>
> Best regards,
> Przemyslaw.