File:  [ELWIX - Embedded LightWeight unIX -] / libaitio / example / sendfile.c
Revision 1.4: download - view: text, annotated - select for diffs - revision graph
Thu Aug 18 09:06:31 2016 UTC (7 years, 10 months ago) by misho
Branches: MAIN
CVS tags: io7_4, IO7_3, HEAD
version 7.3

    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, sl;
   14: 	struct sockaddr_in sin;
   15: 
   16: 	if (argc < 3)
   17: 		return 1;
   18: 
   19: #ifndef __linux__
   20: 	sin.sin_len = sizeof sin;
   21: #endif
   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 (connect(s, (struct sockaddr*) &sin, sizeof sin) == -1) {
   32: 		perror("connect");
   33: 		close(s);
   34: 		return 3;
   35: 	}
   36: 
   37: 	sl = ioSendFile(s, argv[1], 0, 0, argv[3] ? strtol(argv[3], NULL, 0) : 0);
   38: 	printf("sended %d bytes\n", sl);
   39: 	if (!sl)
   40: 		printf("#%d - %s\n", io_GetErrno(), io_GetError());
   41: 
   42: 	close(s);
   43: 	return 0;
   44: }

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