6 #include <sys/socket.h>
7 #include <sys/sendfile.h>
15 const char *filename
= "/afs/stacken.kth.se/test/TEXT.txt";
24 if (socketpair(AF_UNIX
, SOCK_STREAM
, 0, sockets
) < 0) {
25 perror("creating socketpair");
29 fd
= open(filename
, O_RDONLY
);
31 perror("opening file");
38 len
= stat_buf
.st_size
;
40 assert(len
< BUFSIZE
);
42 ret
= sendfile(sockets
[0], fd
, &offset
, len
);
48 fprintf(stderr
, "sendfile sent %d of %d bytes\n", ret
, len
);
53 ret
= read(sockets
[1], buf
, BUFSIZE
);
55 perror("read failed");
59 fprintf(stderr
, "read %d of %d bytes\n", ret
, len
);
67 fprintf(stderr
, "happy: sent and read %d bytes\n", ret
);