UNIX Environment Advanced Programming Learning 16th Chapter Network IPC: Socket-non-blocking socket communication Epoll model (multiplexing), practical socket Communication Template

Source: Internet
Author: User
Tags epoll socket


[CPP]  View plain copy/* user:lixiujie           *  date:20101207  * desc:unix (Linux) non-blocking socket communication Epoll model, multiplexing, TCP server-side,  sends response information to the client.   * file:tcp_server_epoll.c    * system:ubuntu 64bit    *  gcc tcp_server_epoll.c -o  tcp_server_epoll  * tcp_server_epoll 7878  *   epoll  Function Introduction   Epoll is an improved poll of the Linux kernel to handle large batches of handles and is an enhanced version of the select/poll of the multiplexed IO interface under Linux. It can significantly reduce the system CPU utilization of programs in a large number of concurrent connections with only a few active cases.     epoll  Advantages   1, it retains the two relative advantages of the poll with Select,   2, the parameters of the epoll_wait events as an argument, and returns directly to the Fd,epoll_ of events that occurred. The return value of wait is both the number of occurrences, and the loop operation after the return of poll is omitted.   3, no longer like Select, poll the identifier is limited to Fd,epoll can be extended to pointers, greatly increasing the flexibility under the Epoll model.     epoll  Usage notes   1, if the FD is registered in two Epoll, two epoll will trigger the event if there is time.   2. If the FD registered in Epoll is closed, it will automatically be cleared out of the Epoll listener list. Note: Turn off automatic cleanup without phone removal   3, if multiple events trigger Epoll at the same time, multiple events will be returned together.   4, Epoll_wait will always listen to epollhup events occur, so it does notNeed to be added to events.  

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.