TIME_WAIT another solution: SO_LINGER, time_waitso_linger

Source: Internet
Author: User

TIME_WAIT another solution: SO_LINGER, time_waitso_linger
The TIME_WAIT problem is annoying, and another solution is found, SO_LINGER. the most common interpretation of SO_LINGER is "UNP". The following SO_LINGER values are extracted and expressed in the following data structure:

struct linger {     int l_onoff; /* 0 = off, nozero = on */     int l_linger; /* linger time */};
The value and processing are as follows: 1. If l_onoff is set to 0, this option is disabled. The value of l_linger is ignored, which is equal to the default kernel. The close call will be immediately returned to the caller, if any unsent data may be transmitted, 2. If l_onoff is set to a non-0 value and l_linger is set to 0, TCP will abort the connection when the interface is closed, TCP will discard any data retained in the sending buffer of the Set interface and send an RST to the other party, instead of the usual four-group termination sequence, which avoids the TIME_WAIT status; 3. Set l_onoff to a non-0, rochelle linger is not 0. When the set of interfaces is closed, the kernel will be delayed for a period of time (determined by Rochelle linger ). If data remains in the interface buffer, the process will be sleep until (a) all data is sent and confirmed by the other party, then, perform a normal termination sequence (the descriptive word access count is 0), or (B) Delay Time. In this case, it is very important for the application to check the return value of close. If the time is up before the data is sent and confirmed, close will return the EWOULDBLOCK error, and any data in the sending buffer zone of the interface is lost. The successful return of close only tells us that the data (and FIN) sent has been confirmed by the other party's TCP. It does not tell us whether the other party's application process has read the data. If the set of interfaces is set to non-blocking, it will not wait for close to complete. From the results, there is no difference between the first and the Unset, the second can avoid TIME_WAIT, and the third can set the delay time, but it is useless in the non-blocking state. Set SO_LINGER:
struct linger {     int l_onoff; /* 0 = off, nozero = on */     int l_linger; /* linger time */};

 

After setting, there is no TIME_WAIT.

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.