1 //===-- StreamBroadcast.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/lldb-private.h" 13 #include "lldb/Core/Debugger.h" 14 15 using namespace lldb; 16 using namespace lldb_private; 17 18 19 StreamAsynchronousIO::StreamAsynchronousIO (Debugger &debugger, bool for_stdout) : 20 Stream (0, 4, eByteOrderBig), 21 m_debugger (debugger), 22 m_data (), 23 m_for_stdout (for_stdout) 24 { 25 } 26 27 StreamAsynchronousIO::~StreamAsynchronousIO () 28 { 29 // Flush when we destroy to make sure we display the data 30 Flush(); 31 } 32 33 void 34 StreamAsynchronousIO::Flush () 35 { 36 if (!m_data.empty()) 37 { 38 m_debugger.PrintAsync (m_data.data(), m_data.size(), m_for_stdout); 39 m_data = std::string(); 40 } 41 } 42 43 size_t 44 StreamAsynchronousIO::Write (const void *s, size_t length) 45 { 46 m_data.append ((const char *)s, length); 47 return length; 48 } 49