public virtual void Dispose(bool flush)
{
if (m_Socket == null || m_Disposing)
{
return;
}
m_Disposing = true;
if (flush)
{
flush = Flush();
}
try
{
m_Socket.Shutdown(SocketShutdown.Both);
}
catch (SocketException ex)
{
TraceException(ex);
}
try
{
m_Socket.Close();
}
catch (SocketException ex)
{
TraceException(ex);
}
if (m_RecvBuffer != null)
{
m_ReceiveBufferPool.ReleaseBuffer(m_RecvBuffer);
}
m_Socket = null;
m_Buffer = null;
m_RecvBuffer = null;
#if NewAsyncSockets
m_ReceiveEventArgs = null;
m_SendEventArgs = null;
#else
m_OnReceive = null;
m_OnSend = null;
#endif
m_Running = false;
m_Disposed.Enqueue(this);
if (/*!flush &&*/ !m_SendQueue.IsEmpty)
{
lock (m_SendQueue)
m_SendQueue.Clear();
}
}