]> CyberLeo.Net >> Repos - FreeBSD/releng/10.2.git/blob - contrib/llvm/tools/lldb/source/Core/StreamAsynchronousIO.cpp
- Copy stable/10@285827 to releng/10.2 in preparation for 10.2-RC1
[FreeBSD/releng/10.2.git] / contrib / llvm / tools / lldb / source / Core / StreamAsynchronousIO.cpp
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 <stdio.h>
11
12 #include "lldb/lldb-private.h"
13 #include "lldb/Core/Broadcaster.h"
14 #include "lldb/Core/Event.h"
15 #include "lldb/Core/StreamAsynchronousIO.h"
16
17 using namespace lldb;
18 using namespace lldb_private;
19
20
21 StreamAsynchronousIO::StreamAsynchronousIO (Broadcaster &broadcaster, uint32_t broadcast_event_type) :
22     Stream (0, 4, eByteOrderBig),
23     m_broadcaster (broadcaster),
24     m_broadcast_event_type (broadcast_event_type),
25     m_accumulated_data ()
26 {
27 }
28
29 StreamAsynchronousIO::~StreamAsynchronousIO ()
30 {
31     // Flush when we destroy to make sure we display the data
32     Flush();
33 }
34
35 void
36 StreamAsynchronousIO::Flush ()
37 {
38     if (!m_accumulated_data.empty())
39     {
40         std::unique_ptr<EventDataBytes> data_bytes_ap (new EventDataBytes);
41         // Let's swap the bytes to avoid LARGE string copies.
42         data_bytes_ap->SwapBytes (m_accumulated_data);
43         EventSP new_event_sp (new Event (m_broadcast_event_type, data_bytes_ap.release()));
44         m_broadcaster.BroadcastEvent (new_event_sp);
45     }
46 }
47
48 size_t
49 StreamAsynchronousIO::Write (const void *s, size_t length)
50 {
51     m_accumulated_data.append ((const char *)s, length);
52     return length;
53 }