Gracefully Disable TCP Socket

I am writing an IRC client in C ++, and currently I have a problem when after exiting I do:

  Send ("QUIT: Quit \ r \ n");  // just an inline, variadic send () wrapper
 shutdown (m_hSocket, SD_BOTH);
 closesocket (m_hSocket);

 WSAShutdown ();

However, the problem is that the QUIT message is not sent. I sniffed the packets coming from the client and reminded that this message is never sent. I believe this is a problem with the socket not being reset, but I have no idea how to do this, and Google suggested disabling the Nagle algorithm, but I doubt it is good practice.

Thanks in advance.

+6
source share
1 answer

First of all, you should check the return value of send : is the data you are trying to send actually received by the network stack? (In general, this should be done after each send call, and not just in this case).

Assuming the data has been accepted, AFAIK should actually be passed as a result of the shutdown call. You can try using SO_LINGER to find out if it doesn’t matter, see Graceful shutdown, delay options and closing the socket on MSDN .

+5
source

Source: https://habr.com/ru/post/886103/


All Articles