38 lines · cpp
1//===-- StreamAsynchronousIO.cpp ------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9#include "lldb/Core/StreamAsynchronousIO.h"10 11#include "lldb/Core/Debugger.h"12#include "lldb/lldb-enumerations.h"13 14using namespace lldb;15using namespace lldb_private;16 17StreamAsynchronousIO::StreamAsynchronousIO(18 Debugger &debugger, StreamAsynchronousIO::ForSTDOUT for_stdout)19 : Stream(0, 4, eByteOrderBig, debugger.GetUseColor()), m_debugger(debugger),20 m_data(), m_for_stdout(for_stdout) {}21 22StreamAsynchronousIO::~StreamAsynchronousIO() {23 // Flush when we destroy to make sure we display the data.24 Flush();25}26 27void StreamAsynchronousIO::Flush() {28 if (!m_data.empty()) {29 m_debugger.PrintAsync(m_data.data(), m_data.size(), m_for_stdout);30 m_data.clear();31 }32}33 34size_t StreamAsynchronousIO::WriteImpl(const void *s, size_t length) {35 m_data.append((const char *)s, length);36 return length;37}38