X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=tests%2Fvsys_conctest.c;h=2d174a0205b5ffa04e07936f5229f59e73a7c024;hb=1535c8c830919b3df63375a31008e8f0a5d7244f;hp=1f94c69da8d9e21d68dc5512ca70961c85c5c9d1;hpb=39cd5ff0d06a1162c399ec09e12719813d6d64e4;p=vsys.git diff --git a/tests/vsys_conctest.c b/tests/vsys_conctest.c index 1f94c69..2d174a0 100644 --- a/tests/vsys_conctest.c +++ b/tests/vsys_conctest.c @@ -16,37 +16,50 @@ int main() char buf[4096]; int fd_in = -1, fd_out; int res; - int flag; + int flag,flag2; int count = 1; struct timeval tv={.tv_sec=5,.tv_usec=0}; - while (count < 100000) { + while (count < 1000000) { fd_set readSet; int res; int nlines=0; //usleep(200); printf("(%d)", count);fflush(stdout); - if ((fd_out = open(topcmd, O_RDONLY | O_NONBLOCK)) < 0) { fprintf(stderr, "error executing top\n"); exit(-1); } - if ((fd_in = open(top_in_file, O_WRONLY)) < 0) { - fprintf(stderr, "error opening %s\n", top_in_file); - exit(-1); + //printf("((0))");fflush(stdout); + while ((fd_in = open(top_in_file, O_WRONLY| O_NONBLOCK)) < 0) { + fprintf(stderr, "Waiting for %s (%s)\n", top_in_file,strerror(errno)); + usleep (50); } + + //printf("(1)"); if ((flag = fcntl(fd_out, F_GETFL)) == -1) { printf("fcntl get failed\n"); exit(-1); } + //printf("(2)"); + + //printf("(3)"); + if ((flag2 = fcntl(fd_in, F_GETFL)) == -1) { + printf("fcntl get failed\n"); + exit(-1); + } + //printf("(4)"); + while (1) { FD_ZERO(&readSet); FD_SET(fd_out, &readSet); + //printf("(5)"); res = select(fd_out + 1, &readSet, NULL, NULL, NULL); + //printf("(6)"); if (res < 0) { if (errno == EINTR || errno == EAGAIN) { printf("."); @@ -58,21 +71,43 @@ int main() break; /* we're done */ } + //printf("(7)"); if (fcntl(fd_out, F_SETFL, flag & ~O_NONBLOCK) == -1) { printf("fcntl set failed\n"); exit(-1); } + //printf("(8)"); + //printf("(9)"); if ((flag = fcntl(fd_out, F_GETFL)) == -1) { printf("fcntl get failed\n"); exit(-1); } + //printf("(10)"); + + + //printf("(11)"); + if (fcntl(fd_in, F_SETFL, flag2 & ~O_NONBLOCK) == -1) { + printf("fcntl set failed\n"); + exit(-1); + } + + //printf("(11)"); + if ((flag2 = fcntl(fd_in, F_GETFL)) == -1) { + printf("fcntl get failed\n"); + exit(-1); + } + //printf("(12)"); if (flag & O_NONBLOCK == 0) { printf("fd_out still nonblocking\n"); exit(-1); } + if (flag & O_NONBLOCK == 0) { + printf("fd_in still nonblocking\n"); + exit(-1); + } if ((fp = fdopen(fd_out, "r")) == NULL) { printf("fdopen failed\n"); exit(-1);