Hi all,
I've been using Mongoose for an small project to allow transmitting/streaming video files from an Android device. It works like a charm!. Thanks to all the developers involved!
My mail is just to notice an API existing in most (all?) Unixes called "sendfile". I completely ignore if you are already aware of it so I send this e-mail "just-in-case".
In a Copy&Paste from "The Linux Programming Interface" (Michael Kerrish):
"""
Application such as web servers frequently need to transfer disk files through a socket.
One way to do this would be a loop of the following form:
while ((n = read(diskfilefd, buf, BUZ_SIZE)) > 0) write(sockfd, buf, n);
For many applications, such a loop is perfectly acceptable. However, if we frequently transfer large files it's inefficient.
We must use two system calls (possibly multiple times within a loop): one to copy the file contents from the kernel
buffer cache into user space, and the other to copy the user-space buffer back to kernel space in order to be transmitted via the socket.
This is wasteful if the application doesn't perform any processing of the file contents before transmission.
The sendfile() system call is designed to eliminate this inefficiency. The file contents are transferred directly to the socket, without passing through user space.
"""
I didn't have the time to look at the source code and ignore the internals of Mongoose but I guess It must be easy to use it in platforms with the supported sendfile API. (#ifndef WIN32)
Note: Since new Android/iPhone phones/tables can record H264 files at 10Mbs/sec or more with video files growing to hundreds of Megabytes, I think this "large file" scenario could become more and more usual.
Regards!
Enrique