문제

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,

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top