When to use the POLLOUT event of the poll C function?

后端 未结 3 2041
醉话见心
醉话见心 2021-02-03 12:11

I wrote a small TCP servers with socket() + POLLIN poll() + recv() + send(), but I don\'t know when to use <

3条回答
  •  后悔当初
    2021-02-03 12:55

    Working on a Raspberry PI 3, Debian, using c++ 98 with gcc . . .

    In an implementation of the Acceptor / Connector pattern and Reactor / Proactor / ACT pattern I regulary use POLLOUT in the following sequence:

    1. Open a socket using the socket function.
    2. Set the socket file descriptor to non blocking mode with fcntl.
    3. Call connect and check return code.

    In most cases connect returns a -1. Because of the non blocking file descriptor this is very likely. Then I check the result code.

    If it is EINPROGRESS, I register an event handler in the reactor (which uses ppoll or epoll) with POLLOUT. When the connection is finally done, poll returns with POLLOUT set.

    Then I create a new TcpConnection class and communicate.

提交回复
热议问题