Annotation of researchv10dc/ipc/bin/loopback.c, revision 1.1.1.1

1.1       root        1: #include <stdio.h>
                      2: #include <libc.h>
                      3: #include <ipc.h>
                      4: 
                      5: timeout()
                      6: {
                      7:        fprintf(stderr, "timeout\n");
                      8:        exit(1);
                      9: }
                     10: 
                     11: main(ac,av)
                     12:        int ac;
                     13:        char *av[];
                     14: {
                     15:        char buf[8*1024];
                     16:        char buf2[8*1024];
                     17:        int fd, n;
                     18:        unsigned int i, j, count, size, bytes;
                     19:        char *ipcpath();
                     20:        long start, end;
                     21: 
                     22:        bytes=1024*1024;
                     23:        size=1024;
                     24:        switch(ac) {
                     25:        default:
                     26:                fprintf(stderr, "usage: loopback host [size] [bytes]\n");
                     27:                exit(1);
                     28:        case 4:
                     29:                bytes=atoi(av[3]);
                     30:        case 3:
                     31:                size=atoi(av[2]);
                     32:                if(size>sizeof(buf))
                     33:                        size=sizeof(buf);
                     34:        case 2:
                     35:                break;
                     36:        }
                     37:        count=bytes/size;
                     38: 
                     39:        /*
                     40:         * set up pattern
                     41:         */
                     42:        for(i=0; i<sizeof(buf); i++)
                     43:                buf[i] = i&0xff;
                     44: 
                     45:        fd = ipcopen(ipcpath(av[1], "dk", "loopback"), "heavy");
                     46:        if (fd<0){
                     47:                fprintf(stderr, "error connecting to %s: %s\n", av[1], errstr);
                     48:                exit(1);
                     49:        }
                     50:        printf("connected to %s\n", av[1]);
                     51:        fflush(stdout);
                     52: 
                     53:        /*
                     54:         * separate reader and writer
                     55:         */
                     56:        switch(fork()) {
                     57:        case -1:
                     58:                perror("forking:");
                     59:                exit(1);
                     60:        case 0:
                     61:                for(i=0; i<count; i++){
                     62:                        alarm(60);
                     63:                        if(write(fd, buf, size)!=size) {
                     64:                                perror("write:");
                     65:                                exit(1);
                     66:                        }
                     67:                }
                     68:                exit(0);
                     69:        default:
                     70:                start=time((long *)0);
                     71:                for(i=0; i<count; i++){
                     72:                        alarm(60);
                     73:                        for(j=0; j<size; j+=n){
                     74:                                n=read(fd, buf2+j, size-j);
                     75:                                if(n<=0){
                     76:                                        perror("read");
                     77:                                        exit(1);
                     78:                                }
                     79:                        }
                     80:                        if(memcmp(buf, buf2, size)){
                     81:                                fprintf(stderr,"bad data\n");
                     82:                                exit(1);
                     83:                        }
                     84:                }
                     85:                break;
                     86:        }
                     87:        end=time((long *)0);
                     88:        printf("%d*%d bytes xferred in %d secs = %d bytes/sec\n", count, size,
                     89:                end-start, (size*count)/(end-start));
                     90:        exit(0);
                     91: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.