1696bd635SAlexander Shaposhnikov //===-- StreamAsynchronousIO.cpp --------------------------------*- C++ -*-===// 2969ed3d1SCaroline Tice // 3*2946cd70SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4*2946cd70SChandler Carruth // See https://llvm.org/LICENSE.txt for license information. 5*2946cd70SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6969ed3d1SCaroline Tice // 7969ed3d1SCaroline Tice //===----------------------------------------------------------------------===// 8969ed3d1SCaroline Tice 94446487dSPavel Labath #include "lldb/Core/StreamAsynchronousIO.h" 10969ed3d1SCaroline Tice 114446487dSPavel Labath #include "lldb/Core/Debugger.h" 12672d2c12SJonas Devlieghere #include "lldb/lldb-enumerations.h" 13969ed3d1SCaroline Tice 14969ed3d1SCaroline Tice using namespace lldb; 15969ed3d1SCaroline Tice using namespace lldb_private; 16969ed3d1SCaroline Tice 17b9c1b51eSKate Stone StreamAsynchronousIO::StreamAsynchronousIO(Debugger &debugger, bool for_stdout) 18b9c1b51eSKate Stone : Stream(0, 4, eByteOrderBig), m_debugger(debugger), m_data(), 19b9c1b51eSKate Stone m_for_stdout(for_stdout) {} 20969ed3d1SCaroline Tice 21b9c1b51eSKate Stone StreamAsynchronousIO::~StreamAsynchronousIO() { 2244d93782SGreg Clayton // Flush when we destroy to make sure we display the data 2344d93782SGreg Clayton Flush(); 24969ed3d1SCaroline Tice } 25969ed3d1SCaroline Tice 26b9c1b51eSKate Stone void StreamAsynchronousIO::Flush() { 27b9c1b51eSKate Stone if (!m_data.empty()) { 284446487dSPavel Labath m_debugger.PrintAsync(m_data.data(), m_data.size(), m_for_stdout); 293a29f8b9SPavel Labath m_data = std::string(); 30969ed3d1SCaroline Tice } 31969ed3d1SCaroline Tice } 32969ed3d1SCaroline Tice 3392b16738SRaphael Isemann size_t StreamAsynchronousIO::WriteImpl(const void *s, size_t length) { 344446487dSPavel Labath m_data.append((const char *)s, length); 35969ed3d1SCaroline Tice return length; 36969ed3d1SCaroline Tice } 37