1 //===-- SelectHelper.h ------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef liblldb_SelectHelper_h_
11 #define liblldb_SelectHelper_h_
13 #include "lldb/Utility/Status.h" // for Status
14 #include "lldb/lldb-types.h" // for socket_t
16 #include "llvm/ADT/DenseMap.h"
17 #include "llvm/ADT/Optional.h"
23 // Defaults to infinite wait for select unless you call SetTimeout()
26 // Call SetTimeout() before calling SelectHelper::Select() to set the timeout
27 // based on the current time + the timeout. This allows multiple calls to
28 // SelectHelper::Select() without having to worry about the absolute timeout
29 // as this class manages to set the relative timeout correctly.
30 void SetTimeout(const std::chrono::microseconds &timeout);
32 // Call the FDSet*() functions before calling SelectHelper::Select() to set
33 // the file descriptors that we will watch for when calling select. This will
34 // cause FD_SET() to be called prior to calling select using the "fd"
36 void FDSetRead(lldb::socket_t fd);
37 void FDSetWrite(lldb::socket_t fd);
38 void FDSetError(lldb::socket_t fd);
40 // Call the FDIsSet*() functions after calling SelectHelper::Select() to
41 // check which file descriptors are ready for read/write/error. This will
42 // contain the result of FD_ISSET after calling select for a given file
44 bool FDIsSetRead(lldb::socket_t fd) const;
45 bool FDIsSetWrite(lldb::socket_t fd) const;
46 bool FDIsSetError(lldb::socket_t fd) const;
48 // Call the system's select() to wait for descriptors using timeout provided
49 // in a call the SelectHelper::SetTimeout(), or infinite wait if no timeout
51 lldb_private::Status Select();
56 : read_set(false), write_set(false), error_set(false),
57 read_is_set(false), write_is_set(false), error_is_set(false) {}
59 void PrepareForSelect() {
65 bool read_set : 1, write_set : 1, error_set : 1, read_is_set : 1,
66 write_is_set : 1, error_is_set : 1;
68 llvm::DenseMap<lldb::socket_t, FDInfo> m_fd_map;
69 llvm::Optional<std::chrono::steady_clock::time_point> m_end_time;
72 #endif // liblldb_SelectHelper_h_