Nonblocking stdin on telnet
Andrei Chichak
groups at chichak.ca
Tue Jul 6 23:13:03 UTC 2010
I am using 4.9.4 on a Coldfire 5282.
I need to do a non-blocking read on stdin in my telnet process. I have done the following, but the getchar blocks.
init.c:
ShellInit(); /* set up the necessary queues etc */
rtems_bsdnet_initialize_network();
rtems_telnetd_initialize(Shell, /* "shell" function */
NULL, /* no context necessary for echoShell */
false, /* true == remain on console */
/* false == listen on sockets */
RTEMS_MINIMUM_STACK_SIZE * 20, /* shell needs a large stack */
SHELL_TASK_PRIO, /* priority */
false /* false = telnetd does NOT ask for password */
/* true = telnetd asks for password */
/* RTEMS Shell always asks for user/passwd */
);
shell.c:
void Shell( char *pty_name, void *cmd_arg) {
char inCh;
struct termios oldt, newt;
int oldf;
if (tcgetattr( STDIN_FILENO, &oldt)) {
rtems_panic("bad tcgetattr");
}
newt = oldt;
newt.c_lflag &= ~(ECHO | ICANON);
if (tcsetattr (STDIN_FILENO, TCSANOW, &newt) < 0) {
rtems_panic("bad tcsetattr");
}
oldf = fcntl( STDIN_FILENO, F_GETFL, 0);
fcntl( STDIN_FILENO, F_SETFL, oldf | O_NONBLOCK);
for (;;) {
inCh = getchar();
if (inCh == EOF) {
return;
} else {
printf(".");
}
}
}
The Shell gets fired up on the telnet call, but the getchar blocks until it receives ^D (terminates telnet if it is the first character in a line), ^J, or ^M. I've tried various versions of this code, setting VMIN and VTIME to 0 and 1, but no go.
Any ideas?
Thanks,
Andrei
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rtems.org/pipermail/users/attachments/20100706/bffc72e3/attachment.html>
More information about the users
mailing list