StreamAsynchronousIO.cpp revision 344779
1//===-- StreamAsynchronousIO.cpp --------------------------------*- C++ -*-===//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "lldb/Core/StreamAsynchronousIO.h"
11
12#include "lldb/Core/Debugger.h"
13#include "lldb/lldb-enumerations.h"
14
15using namespace lldb;
16using namespace lldb_private;
17
18StreamAsynchronousIO::StreamAsynchronousIO(Debugger &debugger, bool for_stdout)
19    : Stream(0, 4, eByteOrderBig), m_debugger(debugger), m_data(),
20      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 = std::string();
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