-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathae_select.c
31 lines (25 loc) · 863 Bytes
/
ae_select.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/*************************************************************************
> File Name: ae_select.c
> Author: 刘艳明
> Mail: liuyanming@live.cn
> Created Time: 2018年10月10日 星期三 13时40分27秒
************************************************************************/
#include <errno.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/time.h>
#include "ae_select.h"
int input_timeout(int filedes, unsigned int seconds) {
fd_set set;
struct timeval timeout;
/* Initialize the file descriptor set. */
FD_ZERO (&set);
FD_SET (filedes, &set);
/* Initialize the timeout data structure. */
timeout.tv_sec = seconds;
timeout.tv_usec = 0;
/* select returns 0 if timeout, 1 if input available, -1 if error. */
return select(FD_SETSIZE, &set, NULL, NULL,
&timeout);
}