1435933ddSDimitry Andric //===-- StreamAsynchronousIO.cpp --------------------------------*- C++ -*-===//
2ac7ddfbfSEd Maste //
3ac7ddfbfSEd Maste //                     The LLVM Compiler Infrastructure
4ac7ddfbfSEd Maste //
5ac7ddfbfSEd Maste // This file is distributed under the University of Illinois Open Source
6ac7ddfbfSEd Maste // License. See LICENSE.TXT for details.
7ac7ddfbfSEd Maste //
8ac7ddfbfSEd Maste //===----------------------------------------------------------------------===//
9ac7ddfbfSEd Maste 
101c3bbb01SEd Maste #include "lldb/Core/StreamAsynchronousIO.h"
11ac7ddfbfSEd Maste 
121c3bbb01SEd Maste #include "lldb/Core/Debugger.h"
13*b5893f02SDimitry Andric #include "lldb/lldb-enumerations.h"
14ac7ddfbfSEd Maste 
15ac7ddfbfSEd Maste using namespace lldb;
16ac7ddfbfSEd Maste using namespace lldb_private;
17ac7ddfbfSEd Maste 
StreamAsynchronousIO(Debugger & debugger,bool for_stdout)18435933ddSDimitry Andric StreamAsynchronousIO::StreamAsynchronousIO(Debugger &debugger, bool for_stdout)
19435933ddSDimitry Andric     : Stream(0, 4, eByteOrderBig), m_debugger(debugger), m_data(),
20435933ddSDimitry Andric       m_for_stdout(for_stdout) {}
21ac7ddfbfSEd Maste 
~StreamAsynchronousIO()22435933ddSDimitry Andric StreamAsynchronousIO::~StreamAsynchronousIO() {
2312b93ac6SEd Maste   // Flush when we destroy to make sure we display the data
2412b93ac6SEd Maste   Flush();
25ac7ddfbfSEd Maste }
26ac7ddfbfSEd Maste 
Flush()27435933ddSDimitry Andric void StreamAsynchronousIO::Flush() {
28435933ddSDimitry Andric   if (!m_data.empty()) {
291c3bbb01SEd Maste     m_debugger.PrintAsync(m_data.data(), m_data.size(), m_for_stdout);
309f2f44ceSEd Maste     m_data = std::string();
31ac7ddfbfSEd Maste   }
32ac7ddfbfSEd Maste }
33ac7ddfbfSEd Maste 
WriteImpl(const void * s,size_t length)34*b5893f02SDimitry Andric size_t StreamAsynchronousIO::WriteImpl(const void *s, size_t length) {
351c3bbb01SEd Maste   m_data.append((const char *)s, length);
36ac7ddfbfSEd Maste   return length;
37ac7ddfbfSEd Maste }
38