문제

Is it wrong to wait for EPOLLIN, read all data from the socket, and then immediately send the response?

Is it better to wait for EPOLLOUT before sending the response? If so - why? If not - what exactly is the purpose of EPOLLOUT?

I've seen some epoll examples that wait for EPOLLOUT and some that don't.

도움이 되었습니까?

해결책

If you wait for EPOLLOUT, you are guaranteed that the next send will not block. That means it will accept at least 1 byte (this is admittedly a quite poor guaranteee, but unluckily it's just that, you're never guaranteed that send accepts more than at least 1 byte).

You can do perfectly well without waiting for EPOLLOUT if either blocking is no issue or if the socket is nonblocking (in which case send would fail with EWOULDBLOCK). It sure results in much less complicated code.
It's not wrong to do either.

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