#ifndef REMOTING_HOST_LINUX_FD_STRING_WRITER_H_
#define REMOTING_HOST_LINUX_FD_STRING_WRITER_H_
#include <memory>
#include <string>
#include "base/files/file_descriptor_watcher_posix.h"
#include "base/files/scoped_file.h"
#include "base/functional/callback_forward.h"
#include "base/types/expected.h"
#include "remoting/host/base/loggable.h"
namespace remoting {
class FdStringWriter {
public:
using Callback = base::OnceCallback<void(base::expected<void, Loggable>)>;
FdStringWriter() = delete;
FdStringWriter(const FdStringWriter&) = delete;
FdStringWriter& operator=(const FdStringWriter&) = delete;
~FdStringWriter();
static std::unique_ptr<FdStringWriter> Write(std::string data,
base::ScopedFD fd,
Callback callback);
private:
FdStringWriter(std::string data, base::ScopedFD fd, Callback callback);
void OnFdWritable();
base::ScopedFD fd_;
Callback callback_;
std::unique_ptr<base::FileDescriptorWatcher::Controller> fd_watcher_;
std::string write_data_;
std::string_view write_remaining_;
};
}
#endif