Domanda

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,

È stato utile?

Soluzione

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top