changeset 916:b9ad3b70fc61

non-blocked disk reading test
author arpi_esp
date Thu, 31 May 2001 11:35:01 +0000
parents 604a32fcb501
children b3385775390d
files TOOLS/blocking.c
diffstat 1 files changed, 47 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TOOLS/blocking.c	Thu May 31 11:35:01 2001 +0000
@@ -0,0 +1,47 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/time.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
+#define BUFFSIZE (32*65536)
+
+unsigned char *buffer[1];
+
+int main(int argc,char* argv[]){
+
+           fd_set rfds;
+           struct timeval tv;
+           int retval;
+	   int in_fd=0; // stdin
+
+	   buffer[0]=malloc(BUFFSIZE);
+	   
+	   if(argc>1) in_fd=open(argv[1],O_RDONLY|O_NONBLOCK);
+
+while(1){
+           FD_ZERO(&rfds); FD_SET(in_fd, &rfds);
+           tv.tv_sec = 1;
+           tv.tv_usec = 0;
+           retval = select(in_fd+1, &rfds, NULL, NULL, &tv);
+
+           if (retval){
+	       if(FD_ISSET(in_fd, &rfds)){
+		       // we can read input.
+	               int len;
+	               fprintf(stderr,"r");fflush(stderr);
+		       len=read(in_fd,buffer[0],BUFFSIZE);
+	               fprintf(stderr,"(%d)",len);fflush(stderr);
+		}
+	   } else {
+	           fprintf(stderr,".");fflush(stderr);
+	   }
+
+           fprintf(stderr,"\n");fflush(stderr);
+}
+
+return 0;
+}
+