Question

When creating a small webserver with libev in C, what is the best strategy to serve files (open, ready, write to socket) without blocking the reactor?

I have across some recommendations to read a few blocks at a time but I am not sure this would be the right approach.

Thanks,

Was it helpful?

Solution

I have across some recommendations to read a few blocks at a time but I am not sure this would be the right approach.

Yep, this is a pretty standard approach.

If you are on Linux you may like to use sendfile(). This way you don't have to maintain a buffer into which it reads a file in blocks and then sends it through a socket.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top