1dda28197Spatrick //===-- StreamAsynchronousIO.cpp ------------------------------------------===//
2061da546Spatrick //
3061da546Spatrick // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4061da546Spatrick // See https://llvm.org/LICENSE.txt for license information.
5061da546Spatrick // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6061da546Spatrick //
7061da546Spatrick //===----------------------------------------------------------------------===//
8061da546Spatrick
9061da546Spatrick #include "lldb/Core/StreamAsynchronousIO.h"
10061da546Spatrick
11061da546Spatrick #include "lldb/Core/Debugger.h"
12061da546Spatrick #include "lldb/lldb-enumerations.h"
13061da546Spatrick
14061da546Spatrick using namespace lldb;
15061da546Spatrick using namespace lldb_private;
16061da546Spatrick
StreamAsynchronousIO(Debugger & debugger,bool for_stdout,bool colors)17*f6aab3d8Srobert StreamAsynchronousIO::StreamAsynchronousIO(Debugger &debugger, bool for_stdout,
18*f6aab3d8Srobert bool colors)
19*f6aab3d8Srobert : Stream(0, 4, eByteOrderBig, colors), m_debugger(debugger), m_data(),
20061da546Spatrick m_for_stdout(for_stdout) {}
21061da546Spatrick
~StreamAsynchronousIO()22061da546Spatrick StreamAsynchronousIO::~StreamAsynchronousIO() {
23061da546Spatrick // Flush when we destroy to make sure we display the data
24061da546Spatrick Flush();
25061da546Spatrick }
26061da546Spatrick
Flush()27061da546Spatrick void StreamAsynchronousIO::Flush() {
28061da546Spatrick if (!m_data.empty()) {
29061da546Spatrick m_debugger.PrintAsync(m_data.data(), m_data.size(), m_for_stdout);
30061da546Spatrick m_data = std::string();
31061da546Spatrick }
32061da546Spatrick }
33061da546Spatrick
WriteImpl(const void * s,size_t length)34061da546Spatrick size_t StreamAsynchronousIO::WriteImpl(const void *s, size_t length) {
35061da546Spatrick m_data.append((const char *)s, length);
36061da546Spatrick return length;
37061da546Spatrick }
38