This is the mail archive of the
libc-help@sourceware.org
mailing list for the glibc project.
select stops after first byte even when more bytes are available
- From: Przemek <przemekr at sdfeu dot org>
- To: libc-help at sourceware dot org
- Date: Fri, 03 Apr 2015 16:22:48 +0200
- Subject: select stops after first byte even when more bytes are available
- Authentication-results: sourceware.org; auth=none
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.