Annotation of Net2/tests/benchmarks/udgself.c, revision 1.1

1.1     ! root        1: /*
        !             2:  * IPC benchmark,
        !             3:  * write and discard to self using pipes.
        !             4:  */
        !             5: 
        !             6: #include <stdio.h>
        !             7: #include <signal.h>
        !             8: 
        !             9: #include <sys/types.h>
        !            10: #include <sys/socket.h>
        !            11: #include <sys/time.h>
        !            12: #include <sys/un.h>
        !            13: #include <sys/resource.h>
        !            14: 
        !            15: struct sockaddr_un sun;
        !            16: struct sockaddr_un myname;
        !            17: 
        !            18: int    catchsig();
        !            19: char   *malloc();
        !            20: 
        !            21: main(argc, argv)
        !            22:        char *argv[];
        !            23: {
        !            24:        register char *buf;
        !            25:        register int i, msgs = 0;
        !            26:        int msglen = 0, ms;
        !            27:        int pid, s, sunlen;
        !            28: 
        !            29:        if (argc < 3) {
        !            30:                printf("usage: %s #msgs msglen\n", argv[0]);
        !            31:                exit(1);
        !            32:        }
        !            33:        msgs = atoi(argv[1]);
        !            34:        msglen = atoi(argv[2]);
        !            35:        buf = malloc(msglen);
        !            36:        if (buf == 0) {
        !            37:                printf("Couldn't allocate data buffer\n");
        !            38:                exit(1);
        !            39:        }
        !            40:        myname.sun_family = AF_UNIX;
        !            41:        signal(SIGINT, catchsig);
        !            42:        s = socket(AF_UNIX, SOCK_DGRAM, 0);
        !            43:        if (s < 0) {
        !            44:                perror("socket");
        !            45:                exit(1);
        !            46:        }
        !            47:        sprintf(myname.sun_path, "unixdg%d", getpid());
        !            48:        sunlen = strlen(myname.sun_path) + 2;
        !            49:        if (bind(s, &myname, sunlen) < 0) {
        !            50:                perror("bind");
        !            51:                exit(1);
        !            52:        }
        !            53:        for (i = 0; i < msgs; i++) {
        !            54:                sunlen = strlen(myname.sun_path) + 2;
        !            55:                if (sendto(s, buf, msglen, 0, &myname, sunlen) < 0)
        !            56:                        perror("sendto (parent)");
        !            57:                if (recvfrom(s, buf, msglen, 0, &sun, &sunlen) < 0)
        !            58:                        perror("recvfrom (parent)");
        !            59:        }
        !            60:        close(s);
        !            61:        unlink(myname.sun_path);
        !            62: }
        !            63: 
        !            64: catchsig(s)
        !            65:        int s;
        !            66: {
        !            67: 
        !            68:        unlink(myname.sun_path);
        !            69:        exit(1);
        !            70: }

unix.superglobalmegacorp.com

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