Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / lldb / tools / lldb-dap / IOStream.h
blobb62502419182cd3be7bc50b663d88e9ff067f1c6
1 //===-- IOStream.h ----------------------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #ifndef LLDB_TOOLS_LLDB_DAP_IOSTREAM_H
10 #define LLDB_TOOLS_LLDB_DAP_IOSTREAM_H
12 #include "llvm/Config/llvm-config.h" // for LLVM_ON_UNIX
14 #if defined(_WIN32)
15 // We need to #define NOMINMAX in order to skip `min()` and `max()` macro
16 // definitions that conflict with other system headers.
17 // We also need to #undef GetObject (which is defined to GetObjectW) because
18 // the JSON code we use also has methods named `GetObject()` and we conflict
19 // against these.
20 #define NOMINMAX
21 #include <windows.h>
22 #else
23 typedef int SOCKET;
24 #endif
26 #include "llvm/ADT/StringRef.h"
28 #include <fstream>
29 #include <string>
31 // Windows requires different system calls for dealing with sockets and other
32 // types of files, so we can't simply have one code path that just uses read
33 // and write everywhere. So we need an abstraction in order to allow us to
34 // treat them identically.
35 namespace lldb_dap {
36 struct StreamDescriptor {
37 StreamDescriptor();
38 ~StreamDescriptor();
39 StreamDescriptor(StreamDescriptor &&other);
41 StreamDescriptor &operator=(StreamDescriptor &&other);
43 static StreamDescriptor from_socket(SOCKET s, bool close);
44 static StreamDescriptor from_file(int fd, bool close);
46 bool m_is_socket = false;
47 bool m_close = false;
48 union {
49 int m_fd;
50 SOCKET m_socket;
54 struct InputStream {
55 StreamDescriptor descriptor;
57 bool read_full(std::ofstream *log, size_t length, std::string &text);
59 bool read_line(std::ofstream *log, std::string &line);
61 bool read_expected(std::ofstream *log, llvm::StringRef expected);
64 struct OutputStream {
65 StreamDescriptor descriptor;
67 bool write_full(llvm::StringRef str);
69 } // namespace lldb_dap
71 #endif