annotate TOOLS/blocking.c @ 940:108ac8795d19

-fps 1 fixed
author arpi_esp
date Sat, 02 Jun 2001 01:00:22 +0000
parents b9ad3b70fc61
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
916
b9ad3b70fc61 non-blocked disk reading test
arpi_esp
parents:
diff changeset
1 #include <stdio.h>
b9ad3b70fc61 non-blocked disk reading test
arpi_esp
parents:
diff changeset
2 #include <stdlib.h>
b9ad3b70fc61 non-blocked disk reading test
arpi_esp
parents:
diff changeset
3 #include <sys/time.h>
b9ad3b70fc61 non-blocked disk reading test
arpi_esp
parents:
diff changeset
4 #include <sys/types.h>
b9ad3b70fc61 non-blocked disk reading test
arpi_esp
parents:
diff changeset
5 #include <unistd.h>
b9ad3b70fc61 non-blocked disk reading test
arpi_esp
parents:
diff changeset
6 #include <sys/stat.h>
b9ad3b70fc61 non-blocked disk reading test
arpi_esp
parents:
diff changeset
7 #include <fcntl.h>
b9ad3b70fc61 non-blocked disk reading test
arpi_esp
parents:
diff changeset
8
b9ad3b70fc61 non-blocked disk reading test
arpi_esp
parents:
diff changeset
9 #define BUFFSIZE (32*65536)
b9ad3b70fc61 non-blocked disk reading test
arpi_esp
parents:
diff changeset
10
b9ad3b70fc61 non-blocked disk reading test
arpi_esp
parents:
diff changeset
11 unsigned char *buffer[1];
b9ad3b70fc61 non-blocked disk reading test
arpi_esp
parents:
diff changeset
12
b9ad3b70fc61 non-blocked disk reading test
arpi_esp
parents:
diff changeset
13 int main(int argc,char* argv[]){
b9ad3b70fc61 non-blocked disk reading test
arpi_esp
parents:
diff changeset
14
b9ad3b70fc61 non-blocked disk reading test
arpi_esp
parents:
diff changeset
15 fd_set rfds;
b9ad3b70fc61 non-blocked disk reading test
arpi_esp
parents:
diff changeset
16 struct timeval tv;
b9ad3b70fc61 non-blocked disk reading test
arpi_esp
parents:
diff changeset
17 int retval;
b9ad3b70fc61 non-blocked disk reading test
arpi_esp
parents:
diff changeset
18 int in_fd=0; // stdin
b9ad3b70fc61 non-blocked disk reading test
arpi_esp
parents:
diff changeset
19
b9ad3b70fc61 non-blocked disk reading test
arpi_esp
parents:
diff changeset
20 buffer[0]=malloc(BUFFSIZE);
b9ad3b70fc61 non-blocked disk reading test
arpi_esp
parents:
diff changeset
21
b9ad3b70fc61 non-blocked disk reading test
arpi_esp
parents:
diff changeset
22 if(argc>1) in_fd=open(argv[1],O_RDONLY|O_NONBLOCK);
b9ad3b70fc61 non-blocked disk reading test
arpi_esp
parents:
diff changeset
23
b9ad3b70fc61 non-blocked disk reading test
arpi_esp
parents:
diff changeset
24 while(1){
b9ad3b70fc61 non-blocked disk reading test
arpi_esp
parents:
diff changeset
25 FD_ZERO(&rfds); FD_SET(in_fd, &rfds);
b9ad3b70fc61 non-blocked disk reading test
arpi_esp
parents:
diff changeset
26 tv.tv_sec = 1;
b9ad3b70fc61 non-blocked disk reading test
arpi_esp
parents:
diff changeset
27 tv.tv_usec = 0;
b9ad3b70fc61 non-blocked disk reading test
arpi_esp
parents:
diff changeset
28 retval = select(in_fd+1, &rfds, NULL, NULL, &tv);
b9ad3b70fc61 non-blocked disk reading test
arpi_esp
parents:
diff changeset
29
b9ad3b70fc61 non-blocked disk reading test
arpi_esp
parents:
diff changeset
30 if (retval){
b9ad3b70fc61 non-blocked disk reading test
arpi_esp
parents:
diff changeset
31 if(FD_ISSET(in_fd, &rfds)){
b9ad3b70fc61 non-blocked disk reading test
arpi_esp
parents:
diff changeset
32 // we can read input.
b9ad3b70fc61 non-blocked disk reading test
arpi_esp
parents:
diff changeset
33 int len;
b9ad3b70fc61 non-blocked disk reading test
arpi_esp
parents:
diff changeset
34 fprintf(stderr,"r");fflush(stderr);
b9ad3b70fc61 non-blocked disk reading test
arpi_esp
parents:
diff changeset
35 len=read(in_fd,buffer[0],BUFFSIZE);
b9ad3b70fc61 non-blocked disk reading test
arpi_esp
parents:
diff changeset
36 fprintf(stderr,"(%d)",len);fflush(stderr);
b9ad3b70fc61 non-blocked disk reading test
arpi_esp
parents:
diff changeset
37 }
b9ad3b70fc61 non-blocked disk reading test
arpi_esp
parents:
diff changeset
38 } else {
b9ad3b70fc61 non-blocked disk reading test
arpi_esp
parents:
diff changeset
39 fprintf(stderr,".");fflush(stderr);
b9ad3b70fc61 non-blocked disk reading test
arpi_esp
parents:
diff changeset
40 }
b9ad3b70fc61 non-blocked disk reading test
arpi_esp
parents:
diff changeset
41
b9ad3b70fc61 non-blocked disk reading test
arpi_esp
parents:
diff changeset
42 fprintf(stderr,"\n");fflush(stderr);
b9ad3b70fc61 non-blocked disk reading test
arpi_esp
parents:
diff changeset
43 }
b9ad3b70fc61 non-blocked disk reading test
arpi_esp
parents:
diff changeset
44
b9ad3b70fc61 non-blocked disk reading test
arpi_esp
parents:
diff changeset
45 return 0;
b9ad3b70fc61 non-blocked disk reading test
arpi_esp
parents:
diff changeset
46 }
b9ad3b70fc61 non-blocked disk reading test
arpi_esp
parents:
diff changeset
47