File:  [ELWIX - Embedded LightWeight unIX -] / libaitio / example / recvfile.c
Revision 1.2: download - view: text, annotated - select for diffs - revision graph
Tue Dec 13 02:23:07 2011 UTC (12 years, 6 months ago) by misho
Branches: MAIN
CVS tags: io5_4, io5_3, io5_2, io5_1, io5_0, io4_1, io4_0, io3_9, io3_8, io3_7, io3_6, io3_5, io3_4, io3_3, io3_2, io3_1, io2_8, io2_7, io2_6, io2_5, io2_4, io2_3, IO5_3, IO5_2, IO5_1, IO5_0, IO4_1, IO4_0, IO3_9, IO3_8, IO3_7, IO3_6, IO3_5, IO3_4, IO3_3, IO3_2, IO3_1, IO3_0, IO2_7, IO2_6, IO2_5, IO2_4, IO2_3, IO2_2, HEAD
Release version 2.2

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

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