Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:42:57

0001 //===-- Connection.h --------------------------------------------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef LLDB_UTILITY_CONNECTION_H
0010 #define LLDB_UTILITY_CONNECTION_H
0011 
0012 #include "lldb/lldb-defines.h"
0013 #include "lldb/lldb-enumerations.h"
0014 #include "lldb/lldb-forward.h"
0015 
0016 #include "llvm/ADT/StringRef.h"
0017 
0018 #include <ratio>
0019 #include <string>
0020 
0021 #include <cstddef>
0022 
0023 namespace lldb_private {
0024 class Status;
0025 template <typename Ratio> class Timeout;
0026 }
0027 
0028 namespace lldb_private {
0029 
0030 /// \class Connection Connection.h "lldb/Utility/Connection.h"
0031 /// A communication connection class.
0032 ///
0033 /// A class that implements that actual communication functions for
0034 /// connecting/disconnecting, reading/writing, and waiting for bytes to become
0035 /// available from a two way communication connection.
0036 ///
0037 /// This class is designed to only do very simple communication functions.
0038 /// Instances can be instantiated and given to a Communication class to
0039 /// perform communications where clients can listen for broadcasts, and
0040 /// perform other higher level communications.
0041 class Connection {
0042 public:
0043   /// Default constructor
0044   Connection() = default;
0045 
0046   /// Virtual destructor since this class gets subclassed and handed to a
0047   /// Communication object.
0048   virtual ~Connection();
0049 
0050   /// Connect using the connect string \a url.
0051   ///
0052   /// \param[in] url
0053   ///     A string that contains all information needed by the
0054   ///     subclass to connect to another client.
0055   ///
0056   /// \param[out] error_ptr
0057   ///     A pointer to an error object that should be given an
0058   ///     appropriate error value if this method returns false. This
0059   ///     value can be NULL if the error value should be ignored.
0060   ///
0061   /// \return
0062   ///     \b True if the connect succeeded, \b false otherwise. The
0063   ///     internal error object should be filled in with an
0064   ///     appropriate value based on the result of this function.
0065   ///
0066   /// \see Status& Communication::GetError ();
0067   virtual lldb::ConnectionStatus Connect(llvm::StringRef url,
0068                                          Status *error_ptr) = 0;
0069 
0070   /// Disconnect the communications connection if one is currently connected.
0071   ///
0072   /// \param[out] error_ptr
0073   ///     A pointer to an error object that should be given an
0074   ///     appropriate error value if this method returns false. This
0075   ///     value can be NULL if the error value should be ignored.
0076   ///
0077   /// \return
0078   ///     \b True if the disconnect succeeded, \b false otherwise. The
0079   ///     internal error object should be filled in with an
0080   ///     appropriate value based on the result of this function.
0081   ///
0082   /// \see Status& Communication::GetError ();
0083   virtual lldb::ConnectionStatus Disconnect(Status *error_ptr) = 0;
0084 
0085   /// Check if the connection is valid.
0086   ///
0087   /// \return
0088   ///     \b True if this object is currently connected, \b false
0089   ///     otherwise.
0090   virtual bool IsConnected() const = 0;
0091 
0092   /// The read function that attempts to read from the connection.
0093   ///
0094   /// \param[in] dst
0095   ///     A destination buffer that must be at least \a dst_len bytes
0096   ///     long.
0097   ///
0098   /// \param[in] dst_len
0099   ///     The number of bytes to attempt to read, and also the max
0100   ///     number of bytes that can be placed into \a dst.
0101   ///
0102   /// \param[in] timeout
0103   ///     The number of microseconds to wait for the data.
0104   ///
0105   /// \param[out] status
0106   ///     On return, indicates whether the call was successful or terminated
0107   ///     due to some error condition.
0108   ///
0109   /// \param[out] error_ptr
0110   ///     A pointer to an error object that should be given an
0111   ///     appropriate error value if this method returns zero. This
0112   ///     value can be NULL if the error value should be ignored.
0113   ///
0114   /// \return
0115   ///     The number of bytes actually read.
0116   ///
0117   /// \see size_t Communication::Read (void *, size_t, uint32_t);
0118   virtual size_t Read(void *dst, size_t dst_len,
0119                       const Timeout<std::micro> &timeout,
0120                       lldb::ConnectionStatus &status, Status *error_ptr) = 0;
0121 
0122   /// The actual write function that attempts to write to the communications
0123   /// protocol.
0124   ///
0125   /// Subclasses must override this function.
0126   ///
0127   /// \param[in] dst
0128   ///     A destination buffer that must be at least \a dst_len bytes
0129   ///     long.
0130   ///
0131   /// \param[in] dst_len
0132   ///     The number of bytes to attempt to write, and also the
0133   ///     number of bytes are currently available in \a dst.
0134   ///
0135   /// \param[out] error_ptr
0136   ///     A pointer to an error object that should be given an
0137   ///     appropriate error value if this method returns zero. This
0138   ///     value can be NULL if the error value should be ignored.
0139   ///
0140   /// \return
0141   ///     The number of bytes actually Written.
0142   virtual size_t Write(const void *dst, size_t dst_len,
0143                        lldb::ConnectionStatus &status, Status *error_ptr) = 0;
0144 
0145   /// Returns a URI that describes this connection object
0146   ///
0147   /// Subclasses may override this function.
0148   ///
0149   /// \return
0150   ///     Returns URI or an empty string if disconnecteds
0151   virtual std::string GetURI() = 0;
0152 
0153   /// Interrupts an ongoing Read() operation.
0154   ///
0155   /// If there is an ongoing read operation in another thread, this operation
0156   /// return with status == eConnectionStatusInterrupted. Note that if there
0157   /// data waiting to be read and an interrupt request is issued, the Read()
0158   /// function will return the data immediately without processing the
0159   /// interrupt request (which will remain queued for the next Read()
0160   /// operation).
0161   ///
0162   /// \return
0163   ///     Returns true is the interrupt request was successful.
0164   virtual bool InterruptRead() = 0;
0165 
0166   /// Returns the underlying IOObject used by the Connection.
0167   ///
0168   /// The IOObject can be used to wait for data to become available on the
0169   /// connection. If the Connection does not use IOObjects (and hence does not
0170   /// support waiting) this function should return a null pointer.
0171   ///
0172   /// \return
0173   ///     The underlying IOObject used for reading.
0174   virtual lldb::IOObjectSP GetReadObject() { return lldb::IOObjectSP(); };
0175 
0176 private:
0177   // For Connection only
0178   Connection(const Connection &) = delete;
0179   const Connection &operator=(const Connection &) = delete;
0180 };
0181 
0182 } // namespace lldb_private
0183 
0184 #endif // LLDB_UTILITY_CONNECTION_H