Repository: microsoft/terminal
File: src/host/VtIo.cpp (C++)

Code before:
            writer.Submit();
        }

        {
            // Allow the input thread to momentarily gain the console lock.
            auto& gci = ServiceLocator::LocateGlobals().getConsoleInformation();
            const auto suspension = gci.SuspendLock();
            _deviceAttributes = _pVtInputThread->WaitUntilDA1(3000);
        }
    }

    if (_pPtySignalInputThread)
    {
        // Let the signal thread know that the console is connected.
        //
        // By this point, the pseudo window should have already been created, by
        // ConsoleInputThreadProcWin32. That thread has a message pump, which is
        // needed to ensure that DPI change messages to the owning terminal
        // window don't end up hanging because the pty didn't also process it.
        _pPtySignalInputThread->ConnectConsole();
    }

    if (_state != State::Starting)
    {
        // Here's where we _could_ call CloseConsoleProcessState(), but this function
        // only gets get called once when the first client connects and CONSOLE_INITIALIZED
        // is not set yet. The process list may already contain that first client,
        // but since it hasn't finished connecting yet, it won't react to a CTRL_CLOSE_EVENT.
        // Instead, we return an error here which will abort the connection setup.
        return E_FAIL;
    }

    _state = State::Running;
    return S_OK;
}

void VtIo::SetDeviceAttributes(const til::enumset<DeviceAttribute, uint64_t> attributes) noexcept
{
    _deviceAttributes = attributes;
}

til::enumset<DeviceAttribute, uint64_t> VtIo::GetDeviceAttributes() const noexcept
{
    return _deviceAttributes;
}

// Method Description:
// - Create our pseudo window. This is exclusively called by
//   ConsoleInputThreadProcWin32 on the console input thread.
//    * It needs to be called on that thread, before any other calls to
//      LocatePseudoWindow, to make sure that the input thread is the HWND's

Review comment (suggestion):
```suggestion
        // only gets called once when the first client connects and CONSOLE_INITIALIZED
```

Code after:
            writer.Submit();
        }

        {
            // Allow the input thread to momentarily gain the console lock.
            auto& gci = ServiceLocator::LocateGlobals().getConsoleInformation();
            const auto suspension = gci.SuspendLock();
            _deviceAttributes = _pVtInputThread->WaitUntilDA1(3000);
        }
    }

    if (_pPtySignalInputThread)
    {
        // Let the signal thread know that the console is connected.
        //
        // By this point, the pseudo window should have already been created, by
        // ConsoleInputThreadProcWin32. That thread has a message pump, which is
        // needed to ensure that DPI change messages to the owning terminal
        // window don't end up hanging because the pty didn't also process it.
        _pPtySignalInputThread->ConnectConsole();
    }

    if (_state != State::Starting)
    {
        // Here's where we _could_ call CloseConsoleProcessState(), but this function
        // only gets called once when the first client connects and CONSOLE_INITIALIZED
        // is not set yet. The process list may already contain that first client,
        // but since it hasn't finished connecting yet, it won't react to a CTRL_CLOSE_EVENT.
        // Instead, we return an error here which will abort the connection setup.
        return E_FAIL;
    }

    _state = State::Running;
    return S_OK;
}

void VtIo::SetDeviceAttributes(const til::enumset<DeviceAttribute, uint64_t> attributes) noexcept
{
    _deviceAttributes = attributes;
}

til::enumset<DeviceAttribute, uint64_t> VtIo::GetDeviceAttributes() const noexcept
{
    return _deviceAttributes;
}

// Method Description:
// - Create our pseudo window. This is exclusively called by
//   ConsoleInputThreadProcWin32 on the console input thread.
//    * It needs to be called on that thread, before any other calls to
//      LocatePseudoWindow, to make sure that the input thread is the HWND's