Annotation of Net2/tests/benchmarks/udgdiscard.c, revision 1.1.1.1

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

unix.superglobalmegacorp.com

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