1314564Sdim//===-- StreamAsynchronousIO.cpp --------------------------------*- C++ -*-===//
2254721Semaste//
3353358Sdim// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4353358Sdim// See https://llvm.org/LICENSE.txt for license information.
5353358Sdim// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6254721Semaste//
7254721Semaste//===----------------------------------------------------------------------===//
8254721Semaste
9288943Sdim#include "lldb/Core/StreamAsynchronousIO.h"
10254721Semaste
11314564Sdim#include "lldb/Core/Debugger.h"
12344779Sdim#include "lldb/lldb-enumerations.h"
13254721Semaste
14254721Semasteusing namespace lldb;
15254721Semasteusing namespace lldb_private;
16254721Semaste
17314564SdimStreamAsynchronousIO::StreamAsynchronousIO(Debugger &debugger, bool for_stdout)
18314564Sdim    : Stream(0, 4, eByteOrderBig), m_debugger(debugger), m_data(),
19314564Sdim      m_for_stdout(for_stdout) {}
20254721Semaste
21314564SdimStreamAsynchronousIO::~StreamAsynchronousIO() {
22314564Sdim  // Flush when we destroy to make sure we display the data
23314564Sdim  Flush();
24254721Semaste}
25254721Semaste
26314564Sdimvoid StreamAsynchronousIO::Flush() {
27314564Sdim  if (!m_data.empty()) {
28314564Sdim    m_debugger.PrintAsync(m_data.data(), m_data.size(), m_for_stdout);
29314564Sdim    m_data = std::string();
30314564Sdim  }
31254721Semaste}
32254721Semaste
33344779Sdimsize_t StreamAsynchronousIO::WriteImpl(const void *s, size_t length) {
34314564Sdim  m_data.append((const char *)s, length);
35314564Sdim  return length;
36254721Semaste}
37