My app does the following:
1) Several tasks outputting debug status messages to stdout on Com1 via printf() calls.
2) Another task that's a simple command processor that takes 1 letter inputs to a case statement using either fgets() or getchar() ie from stdin.
3) A 3rd task roughly modeled on the Serial2TCP examples that diverts IO from Com1 to a telnet connection when one becomes present. The priority for this task is higher (lower PRIO#) than the command processor task. This task listens for, and then accepts a telnet connection. When (fdnet >0), but before the select statement, I call:
Code: Select all
ReplaceStdio( 0, fdnet ); //reroute STDIN from fdnet
ReplaceStdio( 1, fdnet ); //reroute STDOUT to fdnet
ReplaceStdio( 2, fdnet ); //reroute STDERR for fdnet
Just after the ReplaceStdio() calls in the task that makes the telnet connection, I've tried:
Code: Select all
while( charavail()) {
char junk;
junk = getchar();
}
This does not purge the junk, even if I add some delay time.
I've also tried similar code in the command processor when it first finds (fdnet>0). No luck in either case.
Ideas?
By the way, to make stdin work, I had to eliminate the telnet connection's 'read()':
Code: Select all
int n = read( fdnet, buffer, buflen );