mirror of
https://github.com/TalAloni/SMBLibrary.git
synced 2025-07-29 20:16:07 +02:00
SMBServer v1.0.5
This commit is contained in:
parent
b75820452d
commit
bd1006cb81
400 changed files with 28062 additions and 0 deletions
35
SMBLibrary/Utilities/SocketUtils.cs
Normal file
35
SMBLibrary/Utilities/SocketUtils.cs
Normal file
|
@ -0,0 +1,35 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
using System.Text;
|
||||
|
||||
namespace Utilities
|
||||
{
|
||||
public class SocketUtils
|
||||
{
|
||||
/// <summary>
|
||||
/// Socket will be forcefully closed, all pending data will be ignored, and socket will be deallocated.
|
||||
/// </summary>
|
||||
public static void ReleaseSocket(Socket socket)
|
||||
{
|
||||
if (socket != null)
|
||||
{
|
||||
if (socket.Connected)
|
||||
{
|
||||
socket.Shutdown(SocketShutdown.Both);
|
||||
try
|
||||
{
|
||||
socket.Disconnect(false);
|
||||
}
|
||||
catch (SocketException)
|
||||
{ }
|
||||
}
|
||||
socket.Close();
|
||||
socket = null;
|
||||
GC.Collect();
|
||||
GC.WaitForPendingFinalizers();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue