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

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: 
                     20:        sa.sa_len = sl = sizeof sa;
                     21:        sin.sin_len = sizeof sin;
                     22:        sin.sin_family = AF_INET;
                     23:        sin.sin_port = htons(5000);
                     24:        sin.sin_addr.s_addr = inet_addr("127.0.0.1");
                     25: 
                     26:        s = socket(AF_INET, SOCK_STREAM, 0);
                     27:        if (s == -1) {
                     28:                perror("socket");
                     29:                return 2;
                     30:        }
                     31:        if (bind(s, (struct sockaddr*) &sin, sizeof sin) == -1) {
                     32:                perror("bind");
                     33:                close(s);
                     34:                return 3;
                     35:        }
                     36:        if (listen(s, 5) == -1) {
                     37:                perror("listen");
                     38:                close(s);
                     39:                return 4;
                     40:        }
                     41: 
1.3     ! misho      42:        if ((c = accept(s, &sa, (socklen_t*) &sl)) != -1) {
        !            43:                sl = ioRecvFile(c, argv[1], strtol(argv[2], NULL, 0), 0644, 
        !            44:                                argv[3] ? strtol(argv[3], NULL, 0) : 0);
1.2       misho      45:                printf("received %d bytes\n", sl);
                     46:                if (!sl)
                     47:                        printf("#%d - %s\n", io_GetErrno(), io_GetError());
                     48:                close(c);
                     49:        }
                     50: 
                     51:        close(s);
                     52:        return 0;
                     53: }

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