With the help of the epoll generated, do I need to forward the package?

I use epoll to record a media server. Fds are set to non-block, and I use edge related events. I know that for EPOLLIN I need to loop read fd until EAGAIN is returned. But what about spelling?

When I want to write, I queue the data and set EPOLLOUT | EPOLLIN | EPOLLET on fd. When the EPOLLOUT event occurs, I write the entire buffer in the queue with one shot:

n = send ( fd, buf, buf_len, MSG_NOSIGNAL ); 

If n> 0 && n <buf_len I just reset EPOLLOUT and return. I see no reason to get hung up on sending (which, I think, implies a man page for epoll). Looks like send indicated that it had just taken everything it could and would return EAGAIN if called immediately.

Excludes a system call here is the most efficient route?

+6
source share
2 answers

epoll man page says:

For stream-oriented files (e.g. pipe, FIFO, stream socket), the condition that the read / write I / O space can also be detected can also be detected by checking the amount of data read / written to the target descriptor file. For example, if you call read (2), asking to read a certain amount of data, and read (2) returns fewer bytes, you can be sure that you have exhausted the space for reading I / O for the file descriptor. The same is true when writing using write (2). (Avoid this last method if you cannot guarantee that the monitored file descriptor always refers to a stream-oriented file.)

+4
source

I did a bunch of tests, and it seems like the forwarding cycle is a waste of time.

+1
source

Source: https://habr.com/ru/post/892045/


All Articles