916
|
1 #include <stdio.h>
|
|
2 #include <stdlib.h>
|
|
3 #include <sys/time.h>
|
|
4 #include <sys/types.h>
|
|
5 #include <unistd.h>
|
|
6 #include <sys/stat.h>
|
|
7 #include <fcntl.h>
|
|
8
|
|
9 #define BUFFSIZE (32*65536)
|
|
10
|
|
11 unsigned char *buffer[1];
|
|
12
|
|
13 int main(int argc,char* argv[]){
|
|
14
|
|
15 fd_set rfds;
|
|
16 struct timeval tv;
|
|
17 int retval;
|
|
18 int in_fd=0; // stdin
|
|
19
|
|
20 buffer[0]=malloc(BUFFSIZE);
|
|
21
|
|
22 if(argc>1) in_fd=open(argv[1],O_RDONLY|O_NONBLOCK);
|
|
23
|
|
24 while(1){
|
|
25 FD_ZERO(&rfds); FD_SET(in_fd, &rfds);
|
|
26 tv.tv_sec = 1;
|
|
27 tv.tv_usec = 0;
|
|
28 retval = select(in_fd+1, &rfds, NULL, NULL, &tv);
|
|
29
|
|
30 if (retval){
|
|
31 if(FD_ISSET(in_fd, &rfds)){
|
|
32 // we can read input.
|
|
33 int len;
|
|
34 fprintf(stderr,"r");fflush(stderr);
|
|
35 len=read(in_fd,buffer[0],BUFFSIZE);
|
|
36 fprintf(stderr,"(%d)",len);fflush(stderr);
|
|
37 }
|
|
38 } else {
|
|
39 fprintf(stderr,".");fflush(stderr);
|
|
40 }
|
|
41
|
|
42 fprintf(stderr,"\n");fflush(stderr);
|
|
43 }
|
|
44
|
|
45 return 0;
|
|
46 }
|
|
47
|