[llvm] [llvm][Support] Implement raw_socket_stream::read with optional timeout (PR #92308)
Michael Spencer via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 3 14:07:35 PDT 2024
================
@@ -124,11 +125,28 @@ class raw_socket_stream : public raw_fd_stream {
public:
raw_socket_stream(int SocketFD);
+ ~raw_socket_stream();
+
/// Create a \p raw_socket_stream connected to the UNIX domain socket at \p
/// SocketPath.
static Expected<std::unique_ptr<raw_socket_stream>>
createConnectedUnix(StringRef SocketPath);
- ~raw_socket_stream();
+
+ /// Attempt to read from the raw_socket_stream's file descriptor.
+ ///
+ /// This method can optionally either block until data is read or an error has
+ /// occurred or timeout after a specified amount of time has passed. By
+ /// default the method will block until the socket has read data or
+ /// encountered an error. If the read times out this method will return
+ /// std::errc:timed_out
+ ///
+ /// \param Ptr The start of the buffer that will hold any read data
+ /// \param Size The number of bytes to be read
+ /// \param Timeout An optional timeout duration in milliseconds
+ ///
+ llvm::Expected<ssize_t>
+ read(char *Ptr, size_t Size,
+ std::chrono::milliseconds Timeout = std::chrono::milliseconds(-1));
----------------
Bigcheese wrote:
This should use the same error handling as `raw_fd_stream::read`. It would be nice to move all of `raw_ostream` to `Expected`, but for an overload I think it's best to match the behavior.
https://github.com/llvm/llvm-project/pull/92308
More information about the llvm-commits
mailing list