I wrote a small TCP servers with socket() + POLLIN poll() + recv() + send(), but I don’t know when to use POLLOUT poll or select writefds to poll on writable event.
Can anyone give me an example of the real usage of POLLOUT?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The usual pattern is to use non-blocking file descriptors with
poll()like this:poll(),POLLINbecause you are always interested in reading what the other end of the socket has send you.POLLOUTonly if you have outstanding data to send to the other end.poll(), if it indicates that data is available to read,poll(), if it indicates that the socket is writable,POLLOUTnext time through the loopPOLLOUTthe next time through the loop.POLLOUTthe next time through the loop only if there was some data left.POLLOUTthe next time through the loop. (This choice is often easier to program because you only need to handle writing data in one place in your loop but on the other hand it delays writing the data until the next time through the loop.)