So_linger and Graceful close connection

Source: Internet
Author: User

http://blog.csdn.net/ccnyou/article/details/8913334

Original: http://unliminet.blog.51cto.com/380895/346686

When calling Closesocket to close a socket, So_linger determines how the system handles the data remaining in the socket send queue. There are two ways to handle this: discard or continue sending data to the peer, gracefully closing the connection. In fact, So_linger is not recommended, and in most cases we recommend using the default closing method (the first case in the table below).

The code snippet below shows the linger structure syntax, and the table is the socket behavior for different parameter cases.

    1. typedef struct Linger {
    2. U_short L_onoff; //switch, 0 or not 0
    3. U_short L_linger; //gracefully close the maximum time limit
    4. } linger;
L_onoff L_linger Closesocket behavior Send Queue Underlying behavior
Zero Ignore Returns immediately. Hold until the send is complete. The system takes over the socket and guarantees that the data is sent to the peer.
Non-Zero Zero Returns immediately. Give up immediately. Send the RST packet directly, reset itself immediately, without going through the 2MSL state. The peer receives a reset error number.
Non-Zero Non-Zero Block until the L_linger time expires or the data is sent to completion. (Sockets must be set to block Zhuan) Keep trying to send within the time-out period, and discard it immediately if it expires. Timeout is the same as the second case, if the transmission is complete, happy.

Information available for reference:

http://msdn.microsoft.com/en-us/library/ms737582 (v=vs.85). aspx

http://msdn.microsoft.com/en-us/library/ms739165 (v=vs.85). aspx

Http://blog.csdn.net/factor2000/archive/2009/02/23/3929816.aspx

So_linger and Graceful close connection

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.