public Task StopAsync()
        {
            lock (_stateLock)
            {
                switch (_connectionState)
                {
                case ConnectionState.SocketClosed:
                    return(TaskUtilities.CompletedTask);

                case ConnectionState.CreatingFrame:
                    _connectionState = ConnectionState.ToDisconnect;
                    break;

                case ConnectionState.Open:
                    _frame.Stop();
                    SocketInput.CompleteAwaiting();
                    break;
                }

                _socketClosedTcs = new TaskCompletionSource <object>();
                return(_socketClosedTcs.Task);
            }
        }