StreamAsynchronousIO.cpp revision 288943
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 15using namespace lldb; 16using namespace lldb_private; 17 18 19StreamAsynchronousIO::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 27StreamAsynchronousIO::~StreamAsynchronousIO () 28{ 29 // Flush when we destroy to make sure we display the data 30 Flush(); 31} 32 33void 34StreamAsynchronousIO::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::move(std::string()); 40 } 41} 42 43size_t 44StreamAsynchronousIO::Write (const void *s, size_t length) 45{ 46 m_data.append ((const char *)s, length); 47 return length; 48} 49