简体   繁体   中英

How to use epoll and make the handler functions non-blocking?

I know little about epoll , after checking some documents then think it runs like this:

while(true){
    epoll_wait(some_sock_fds);
    foreach(usable_fds){
        handler(one_fd);  <----- this function must be non-blocking ?
    }
}

In the handler function there should be something about network read/write or file operations, I think it should be non-blocking, yes?

How can I write the handler function so that it does not block the main loop?

The io thread should focus on the network tasks. If the socket is blocked, you should handle every socket in a separate thread. One thread per socket.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM