Mail Archives: cygwin/2001/03/01/20:42:44
Hi all,
I was wondering if someone could tell me if the following behavior is
what is expected.
I run the program below with cygwin 1.1.8. Two strange behavior seems
to occur.
1. If I click on the DOS box where this program is running, the select
call returns 1. The output will show this. But the call to read will
block. Probably because there is no input from the keyboard. Is this
the correct behavior? How do I check only for keyboard input?
Note: clicking on the title bar does not cause this behavior. It only
happens if you click inside the window.
2. When I run the program from the DOS prompt and hit Ctrl-Z, the program
freezes. But if I run the program in bash and hit Ctrl-Z, the program
is suspended. Is this normal?
The problem in #1 did not occur in 1.1.6. Since setup.exe does not let
me back-rev to 1.1.6, I can not verify this.
Any info is greatly appreciated.
--jc
---------------------------------------------------------------------
#include <sys/time.h>
#include <sys/types.h>
#include <termios.h>
#include <unistd.h>
#include <stdio.h>
int
cbreak(void)
{
struct termios tio, orig;
if (tcgetattr(STDIN_FILENO, &orig) < 0)
{
fprintf(stderr, "tcgetattr failed.\n");
return -1;
}
tio = orig;
tio.c_lflag &= ~(ICANON);
tio.c_cc[VMIN] = 0;
tio.c_cc[VTIME] = 0;
if (tcsetattr(STDIN_FILENO, TCSAFLUSH, &tio) < 0)
{
fprintf(stderr, "tcsetattr failed.\n");
return -1;
}
return 0;
}
int
main(int argc, char *argv[])
{
fd_set rfds, efds;
int fds, fd_max;
/* Need key-at-a-time input for test. */
cbreak();
while (1)
{
FD_ZERO(&rfds);
FD_ZERO(&efds);
FD_SET(STDIN_FILENO, &rfds);
FD_SET(STDIN_FILENO, &efds);
fd_max = STDIN_FILENO;
fds = select(fd_max + 1, &rfds, 0, &efds, 0);
printf("Select returned with %d ready fds.\n", fds);
if (fds && FD_ISSET(STDIN_FILENO, &rfds))
{
char buf[80];
int len;
len = read(STDIN_FILENO, buf, sizeof(buf) - 1);
if (len > 0)
{
buf[len] = '\0';
printf("Data read: %s (%d)\n", buf, len);
}
else if (len < 0)
perror("read");
else
{
printf("EOF detected on stdin,
quiting...\n");
break;
}
--fds;
}
if (fds && FD_ISSET(STDIN_FILENO, &efds))
{
printf("Exception detected on stdin, quiting...\n");
--fds;
break;
}
}
return 0;
}
---------------------------------------------------------------------
--
jching AT adtech-inc DOT com Adtech, Inc. (808) 734-3300
--
Want to unsubscribe from this list?
Check out: http://cygwin.com/ml/#unsubscribe-simple
- Raw text -