diogotr7 / OpenRGB.NET

C# client for the OpenRGB SDK
MIT License
40 stars 16 forks source link

Clean TCP disconnect #11

Closed Faxmachinen closed 2 years ago

Faxmachinen commented 2 years ago

Shutdown should be called before Disconnect on TCP sockets to ensure that data in the socket buffers have been sent.

diogotr7 commented 2 years ago

Hmm, I'm not sure I understand why the current code does not work as expected.

According to StackOverflow, Disconnect does the same as Shutdown. This information could of course be outdated but calling both Disconnect and Shutdown seems redundant.

This solves the issue you mentioned?

diogotr7 commented 2 years ago

Microsoft does mention Shutdown instead of Disconnect to properly clean up the socket, did your testing show if Disconnect is necessary?

https://docs.microsoft.com/en-us/dotnet/api/system.net.sockets.socket?view=net-5.0

Faxmachinen commented 2 years ago

I have not tested it. The official documentation on Disconnect remarks:

To ensure that all data is sent and received before the socket is closed, you should call Shutdown before calling the Disconnect method.