sasian
sasian

Reputation: 211

Question on Stdin

I have the following requirement ;

1) select blocks on the file descriptor associated to stdin

2) Now how do I write a code such that select gets unblocked . The code should make the stdin file descriptor read ready .In other words the code should make the select unblock without waiting for user to give input

Upvotes: 0

Views: 106

Answers (1)

jfg956
jfg956

Reputation: 16730

If we are talking about the select UNIX system call, and your are using it to wait for data on stdin, you could use the timeout parameter to indicate select you want to block for at most timeout seconds.

From the select man on Linux:

#include <sys/select.h>
int select(int nfds, fd_set *readfds, fd_set *writefds,
           fd_set *exceptfds, struct timeval *timeout);

timeout is an upper bound on the amount of time elapsed before select() returns. It may be zero, causing select() to return immediately. (This is useful for polling.) If timeout is NULL (no timeout), select() can block indefinitely.

The time structures involved are defined in and look like

struct timeval {
  long    tv_sec;         /* seconds */
  long    tv_usec;        /* microseconds */
};

Upvotes: 1

Related Questions