private void CloseSocket()
{
if (_socket == null)
return;
lock (_socketLock)
{
if (_socket == null)
return;
// closing a socket actually disposes the socket, so we can safely dereference
// the field to avoid entering the lock again later
_socket.Dispose();
_socket = null;
}
}