Delay Decrease
- Reduced the delay to 1ms. Note: this is still a hack. - Added error checking around the 'select' call.
This commit is contained in:
14
src/A3.cpp
14
src/A3.cpp
@@ -279,18 +279,19 @@ bool A3::is_command (
|
|||||||
// Add an Arg for every word from std::cin.
|
// Add an Arg for every word from std::cin.
|
||||||
void A3::append_stdin ()
|
void A3::append_stdin ()
|
||||||
{
|
{
|
||||||
// Delay, to give it a chance to buffer the input.
|
|
||||||
delay (0.05);
|
|
||||||
|
|
||||||
// Use 'select' to determine whether there is any std::cin content buffered
|
// Use 'select' to determine whether there is any std::cin content buffered
|
||||||
// before trying to read it, to prevent blocking.
|
// before trying to read it, to prevent blocking.
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
fd_set fds;
|
|
||||||
tv.tv_sec = 0;
|
tv.tv_sec = 0;
|
||||||
tv.tv_usec = 0;
|
tv.tv_usec = 1000;
|
||||||
|
|
||||||
|
fd_set fds;
|
||||||
FD_ZERO (&fds);
|
FD_ZERO (&fds);
|
||||||
FD_SET (STDIN_FILENO, &fds);
|
FD_SET (STDIN_FILENO, &fds);
|
||||||
select (STDIN_FILENO + 1, &fds, NULL, NULL, &tv);
|
|
||||||
|
int result = select (STDIN_FILENO + 1, &fds, NULL, NULL, &tv);
|
||||||
|
if (result && result != -1)
|
||||||
|
{
|
||||||
if (FD_ISSET (0, &fds))
|
if (FD_ISSET (0, &fds))
|
||||||
{
|
{
|
||||||
std::string arg;
|
std::string arg;
|
||||||
@@ -303,6 +304,7 @@ void A3::append_stdin ()
|
|||||||
this->push_back (Arg (arg));
|
this->push_back (Arg (arg));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|||||||
Reference in New Issue
Block a user