Annotation of libaitio/example/recvfile.c, revision 1.4

1.2       misho       1: #include <stdio.h>
1.3       misho       2: #include <unistd.h>
1.2       misho       3: #include <sys/types.h>
                      4: #include <sys/socket.h>
                      5: #include <netinet/in.h>
1.3       misho       6: #include <arpa/inet.h>
1.2       misho       7: #include <aitio.h>
                      8: 
                      9: 
                     10: int
                     11: main(int argc, char **argv)
                     12: {
                     13:        int s, c, sl;
                     14:        struct sockaddr sa;
                     15:        struct sockaddr_in sin;
                     16: 
                     17:        if (argc < 3)
                     18:                return 1;
                     19: 
1.4     ! misho      20: #ifndef __linux__
1.2       misho      21:        sa.sa_len = sl = sizeof sa;
                     22:        sin.sin_len = sizeof sin;
1.4     ! misho      23: #endif
1.2       misho      24:        sin.sin_family = AF_INET;
                     25:        sin.sin_port = htons(5000);
                     26:        sin.sin_addr.s_addr = inet_addr("127.0.0.1");
                     27: 
                     28:        s = socket(AF_INET, SOCK_STREAM, 0);
                     29:        if (s == -1) {
                     30:                perror("socket");
                     31:                return 2;
                     32:        }
                     33:        if (bind(s, (struct sockaddr*) &sin, sizeof sin) == -1) {
                     34:                perror("bind");
                     35:                close(s);
                     36:                return 3;
                     37:        }
                     38:        if (listen(s, 5) == -1) {
                     39:                perror("listen");
                     40:                close(s);
                     41:                return 4;
                     42:        }
                     43: 
1.3       misho      44:        if ((c = accept(s, &sa, (socklen_t*) &sl)) != -1) {
                     45:                sl = ioRecvFile(c, argv[1], strtol(argv[2], NULL, 0), 0644, 
                     46:                                argv[3] ? strtol(argv[3], NULL, 0) : 0);
1.2       misho      47:                printf("received %d bytes\n", sl);
                     48:                if (!sl)
                     49:                        printf("#%d - %s\n", io_GetErrno(), io_GetError());
                     50:                close(c);
                     51:        }
                     52: 
                     53:        close(s);
                     54:        return 0;
                     55: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>