This is the mail archive of the
ecos-discuss@sourceware.org
mailing list for the eCos project.
Re: Re: Select() issues
- From: Andre-John Mas <ajmas at sympatico dot ca>
- To: Andrew Lunn <andrew at lunn dot ch>
- Cc: <ecos-discuss at ecos dot sourceware dot org>
- Date: Wed, 10 Jan 2007 11:28:22 -0500
- Subject: Re: Re: [ECOS] Select() issues
Andrew Lunn wrote:
>
> > struct termios ts, ots; /* termios setting, old termios setting */
> > int fd = STDIN_FILENO;
>
> Im not an eCos termios expert, but shouldn't this be a file handle
> returned by opening /dev/termios0 and not standard in?
>
> Andrew
>
On 10-Jan-07, at 10:32 , Andrew Lunn wrote:
struct termios ts, ots; /* termios setting, old termios setting */
int fd = STDIN_FILENO;
Im not an eCos termios expert, but shouldn't this be a file handle
returned by opening /dev/termios0 and not standard in?
Andrew
Up until this particular issue I have had no problems using "standard in".
I will look to see what effect opening /dev/termios0, but most examples
I have seen use STDIN_FILENO directly.
Changing my code slightly, I now find that I now block at cin.get().
I wondering whether I am doing something wrong when changing to canocial
mode?
char InputHandler::DoPressAnyKey()
{
struct termios ts, ots;
int c = 0;
int fd = STDIN_FILENO;
cout << "--0\n";
tcflush(fd,TCIOFLUSH);
cout << "--1\n";
WaitForData();
tcgetattr(fd, &ts); /* save tty state */
ots = ts; /* structure copy */
ts.c_lflag &= ~( ICANON );
ts.c_cc[VMIN] = 1;
ts.c_cc[VTIME] = 0;
tcsetattr(fd, TCSAFLUSH, &ts);
cout << "--2\n";
// INFO: make sure to reset terminal attributes before
// leaving method
if ( !IsTimedOut() )
{
cout << "--2.1\n";
c = cin.get();
cout << "--2.2\n";
}
cout << "--3\n";
tcsetattr(fd, TCSAFLUSH, &ots); /* restore TTY state */
cout << "--4\n";
if ( IsTimedOut() )
{
c = 0;
}
return c;
}
void InputHandler::WaitForData()
{
int fd = STDIN_FILENO;
fd_set fds;
struct timeval tv;
struct timeval *tvPtr = NULL;
cout.flush();
do
{
// INFO: if the time out is not zero then define the timeval and have tvPtr
// refer to it. if it is zero then tvPtr uses a NULL value. I things this
// way to avoid having to duplicate the select call and also not need to
// worry about memory allocation/deallocation
cout << "--a\n";
if ( this->timeout != 0 )
{
tv.tv_sec = this->timeout;
tv.tv_usec = 0;
tvPtr = &tv;
}
else
{
tvPtr = NULL;
}
FD_ZERO( &fds );
FD_SET( STDIN_FILENO, &fds );
cout << "--b\n";
int result = select(fd + 1, &fds, NULL, NULL, tvPtr);
cout << "--c\n";
if ( result == 0 )
{
this->timedout = true;
break;
}
else if ( result > 0 && FD_ISSET(fd,&fds) )
{
break;
}
cout << "--d\n";
}
while ( true );
cout << "--e\n";
}
--
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss