File:  [ELWIX - Embedded LightWeight unIX -] / libaitio / example / sendfile.c
Revision 1.1.2.1: download - view: text, annotated - select for diffs - revision graph
Wed Nov 2 16:11:09 2011 UTC (12 years, 10 months ago) by misho
Branches: io2_2
add 2 new unit tests for recv/send file feature

#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <aitio.h>


int
main(int argc, char **argv)
{
	int s, sl;
	struct sockaddr_in sin;

	if (argc < 3)
		return 1;

	sin.sin_len = sizeof sin;
	sin.sin_family = AF_INET;
	sin.sin_port = htons(5000);
	sin.sin_addr.s_addr = inet_addr("127.0.0.1");

	s = socket(AF_INET, SOCK_STREAM, 0);
	if (s == -1) {
		perror("socket");
		return 2;
	}
	if (connect(s, (struct sockaddr*) &sin, sizeof sin) == -1) {
		perror("connect");
		close(s);
		return 3;
	}

	sl = ioSendFile(s, argv[1], 0, 0, argv[3] ? strtol(argv[3], NULL, 0) : 0);
	printf("sended %d bytes\n", sl);
	if (!sl)
		printf("#%d - %s\n", io_GetErrno(), io_GetError());

	close(s);
	return 0;
}

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