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,

Était-ce utile?

La 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.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top