]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - source/Core/StreamAsynchronousIO.cpp
Vendor import of lldb trunk r290819:
[FreeBSD/FreeBSD.git] / source / Core / StreamAsynchronousIO.cpp
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-private.h"
14
15 using namespace lldb;
16 using namespace lldb_private;
17
18 StreamAsynchronousIO::StreamAsynchronousIO(Debugger &debugger, bool for_stdout)
19     : Stream(0, 4, eByteOrderBig), m_debugger(debugger), m_data(),
20       m_for_stdout(for_stdout) {}
21
22 StreamAsynchronousIO::~StreamAsynchronousIO() {
23   // Flush when we destroy to make sure we display the data
24   Flush();
25 }
26
27 void 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
34 size_t StreamAsynchronousIO::Write(const void *s, size_t length) {
35   m_data.append((const char *)s, length);
36   return length;
37 }