1cfca06d7SDimitry Andric //===-- StreamAsynchronousIO.cpp ------------------------------------------===//
2f034231aSEd Maste //
35f29bb8aSDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
45f29bb8aSDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
55f29bb8aSDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6f034231aSEd Maste //
7f034231aSEd Maste //===----------------------------------------------------------------------===//
8f034231aSEd Maste
95e95aa85SEd Maste #include "lldb/Core/StreamAsynchronousIO.h"
10f034231aSEd Maste
115e95aa85SEd Maste #include "lldb/Core/Debugger.h"
1294994d37SDimitry Andric #include "lldb/lldb-enumerations.h"
13f034231aSEd Maste
14f034231aSEd Maste using namespace lldb;
15f034231aSEd Maste using namespace lldb_private;
16f034231aSEd Maste
StreamAsynchronousIO(Debugger & debugger,bool for_stdout,bool colors)17145449b1SDimitry Andric StreamAsynchronousIO::StreamAsynchronousIO(Debugger &debugger, bool for_stdout,
18145449b1SDimitry Andric bool colors)
19145449b1SDimitry Andric : Stream(0, 4, eByteOrderBig, colors), m_debugger(debugger), m_data(),
2014f1b3e8SDimitry Andric m_for_stdout(for_stdout) {}
21f034231aSEd Maste
~StreamAsynchronousIO()2214f1b3e8SDimitry Andric StreamAsynchronousIO::~StreamAsynchronousIO() {
23866dcdacSEd Maste // Flush when we destroy to make sure we display the data
24866dcdacSEd Maste Flush();
25f034231aSEd Maste }
26f034231aSEd Maste
Flush()2714f1b3e8SDimitry Andric void StreamAsynchronousIO::Flush() {
2814f1b3e8SDimitry Andric if (!m_data.empty()) {
295e95aa85SEd Maste m_debugger.PrintAsync(m_data.data(), m_data.size(), m_for_stdout);
30e81d9d49SDimitry Andric m_data = std::string();
31f034231aSEd Maste }
32f034231aSEd Maste }
33f034231aSEd Maste
WriteImpl(const void * s,size_t length)3494994d37SDimitry Andric size_t StreamAsynchronousIO::WriteImpl(const void *s, size_t length) {
355e95aa85SEd Maste m_data.append((const char *)s, length);
36f034231aSEd Maste return length;
37f034231aSEd Maste }
38