Some experiences related to linuxsocket and epoll

Source: Internet
Author: User
For some experiences related to linuxsocket and epoll cooperation-general Linux technology-Linux programming and kernel information, the following is a detailed description. From: lingxiao web tribe

There are not many profound things that are well documented. Although simple, it is easy to get confused if you haven't done any tests.

Int nRecvBuf = 32*1024; // set it to 32 K
Setsockopt (s, SOL_SOCKET, SO_RCVBUF, (const char *) & nRecvBuf, sizeof (int ));

The preceding statement can be used to set the buffer size. The test proves that when combined with epoll, the buffer is triggered again only when all data sent at a time is read from the buffer, if data is sent multiple times but not read, when the buffer is not full, the data will not be lost and will be accumulated to the end.

If the buffer zone is not full, the EPOLLIN event is received multiple times when the same connection sends data multiple times.

Data sent at a time> data in the socket buffer size will be blocked and sent in multiple times. Therefore, the error can be determined by ENLIGE for cyclic reception.

If the buffer zone is full, the newly sent data will not trigger the epoll event (and there is no exception), and each recv will free up space for the buffer zone, the epollIN event can be triggered again only when the buffer is idle.

When the receiving size is 0, the client is disconnected (it is impossible to trigger EPOLLIN with 0 data packets),-1 indicates an exception, and errorno determines whether it is a reasonable exception or an exception that needs to be terminated.> 0, not equal to the buffer size, indicates that a single sending ends.

If the size of the receiving cache is temporarily adjusted in the middle, and the user space is not fully received in the last time, the data will not be lost and will be accumulated together.

To sum up, the system ensures the integrity of the data and does not perform further tests on the stability.
Related Article

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.