Preamble: lightweight http server written in C based on libevent v2 (evhttp), Linux, ARM, glibc2.3.4
I'm trying to serve big files (over 2GB) using evbuffer_add_file() on 32 bit system. The libevent was compiled with -D_FILE_OFFSET_BITS=64 flag. Here is the simplified code:
int fd = -1;
if ((fd = open(path, O_RDONLY)) < 0) {
// error handling
}
struct stat st;
if (fstat(fd, &st) < 0) {
// error handling
}
struct evbuffer *buffer = evbuffer_new();
evbuffer_set_flags(buffer, EVBUFFER_FLAG_DRAINS_TO_FD); // force using system's sendfile
evbuffer_add_file(buffer, fd, 0, st.st_size);
evhttp_send_reply(req, 200, NULL, buffer);
evbuffer_free(buffer);
st.st_size has correct value, in this case 4913809524, but response header Content-Length has value of 618842228. Even if i set Content-Length header to appropriate value the file transfer stops at 618842228 ...
Do i miss or do something wrong? Is it possible at all?
Thanks in advance
As i said in comment obviously the problem is not in libevent, but in system's sendfile implementation. So with a little workaround i found the way to solve this problem using evhttp_send_reply_(start|chunk|end) functions family: