File:  [ELWIX - Embedded LightWeight unIX -] / libaitio / example / recvfile.c
Revision 1.3: download - view: text, annotated - select for diffs - revision graph
Wed Jun 26 22:48:53 2013 UTC (11 years ago) by misho
Branches: MAIN
CVS tags: io7_3, io7_2, io7_1, io7_0, io6_9, io6_8, io6_7, io6_6, io6_5, io6_4, io6_3, io6_2, io6_1, io6_0, io5_9, io5_8, io5_7, io5_6, io5_5, IO7_2, IO7_1, IO7_0, IO6_9, IO6_8, IO6_7, IO6_6, IO6_5, IO6_4, IO6_3, IO6_2, IO6_1, IO6_0, IO5_9, IO5_8, IO5_7, IO5_6, IO5_5, IO5_4, HEAD
version 5.4

    1: #include <stdio.h>
    2: #include <unistd.h>
    3: #include <sys/types.h>
    4: #include <sys/socket.h>
    5: #include <netinet/in.h>
    6: #include <arpa/inet.h>
    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: 
   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);
   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>