1 //===-- IOStream.h ----------------------------------------------*- C++ -*-===//
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
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
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
26 #include "llvm/ADT/StringRef.h"
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.
36 struct 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;
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
);
65 StreamDescriptor descriptor
;
67 bool write_full(llvm::StringRef str
);
69 } // namespace lldb_dap