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
13 // We need to #define NOMINMAX in order to skip `min()` and `max()` macro
14 // definitions that conflict with other system headers.
15 // We also need to #undef GetObject (which is defined to GetObjectW) because
16 // the JSON code we use also has methods named `GetObject()` and we conflict
24 #include "llvm/ADT/StringRef.h"
29 // Windows requires different system calls for dealing with sockets and other
30 // types of files, so we can't simply have one code path that just uses read
31 // and write everywhere. So we need an abstraction in order to allow us to
32 // treat them identically.
34 struct StreamDescriptor
{
37 StreamDescriptor(StreamDescriptor
&&other
);
39 StreamDescriptor
&operator=(StreamDescriptor
&&other
);
41 static StreamDescriptor
from_socket(SOCKET s
, bool close
);
42 static StreamDescriptor
from_file(int fd
, bool close
);
44 bool m_is_socket
= false;
53 StreamDescriptor descriptor
;
55 bool read_full(std::ofstream
*log
, size_t length
, std::string
&text
);
57 bool read_line(std::ofstream
*log
, std::string
&line
);
59 bool read_expected(std::ofstream
*log
, llvm::StringRef expected
);
63 StreamDescriptor descriptor
;
65 bool write_full(llvm::StringRef str
);
67 } // namespace lldb_dap