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