Skip to content

Commit

Permalink
[vtpty] Pty: change read's timeout parameter to be explicitly optional
Browse files Browse the repository at this point in the history
  • Loading branch information
christianparpart committed Sep 26, 2023
1 parent 7c0d353 commit b885a9b
Show file tree
Hide file tree
Showing 11 changed files with 23 additions and 18 deletions.
12 changes: 8 additions & 4 deletions src/vtbackend/Terminal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,14 @@ void Terminal::setLastMarkRangeOffset(LineOffset value) noexcept

Pty::ReadResult Terminal::readFromPty()
{
auto const timeout = _renderBuffer.state == RenderBufferState::WaitingForRefresh && !_screenDirty
? chrono::seconds(4)
//: _refreshInterval : chrono::seconds(0)
: chrono::seconds(30);
auto const timeout =
#if defined(LIBTERMINAL_PASSIVE_RENDER_BUFFER_UPDATE)
(_renderBuffer.state == RenderBufferState::WaitingForRefresh && !_screenDirty)
? std::optional { _refreshInterval.value }
: std::chrono::milliseconds(0);
#else
std::optional<std::chrono::milliseconds> { std::nullopt };
#endif

// Request a new Buffer Object if the current one cannot sufficiently
// store a single text line.
Expand Down
2 changes: 1 addition & 1 deletion src/vtpty/ConPty.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ void ConPty::close()
}

Pty::ReadResult ConPty::read(crispy::buffer_object<char>& buffer,
std::chrono::milliseconds timeout,
std::optional<std::chrono::milliseconds> timeout,
size_t size)
{
// TODO: wait for timeout time at most AND got woken up upon wakeupReader() invokcation.
Expand Down
2 changes: 1 addition & 1 deletion src/vtpty/ConPty.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class ConPty: public Pty
[[nodiscard]] bool isClosed() const noexcept override;

[[nodiscard]] ReadResult read(crispy::buffer_object<char>& storage,
std::chrono::milliseconds timeout,
std::optional<std::chrono::milliseconds> timeout,
size_t size) override;
void wakeupReader() override;
int write(std::string_view data) override;
Expand Down
2 changes: 1 addition & 1 deletion src/vtpty/MockPty.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ PtySlave& MockPty::slave() noexcept
}

Pty::ReadResult MockPty::read(crispy::buffer_object<char>& storage,
std::chrono::milliseconds /*timeout*/,
std::optional<std::chrono::milliseconds> /*timeout*/,
size_t size)
{
auto const n = min(size, min(_outputBuffer.size() - _outputReadOffset, storage.bytesAvailable()));
Expand Down
2 changes: 1 addition & 1 deletion src/vtpty/MockPty.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class MockPty: public Pty

PtySlave& slave() noexcept override;
[[nodiscard]] ReadResult read(crispy::buffer_object<char>& storage,
std::chrono::milliseconds timeout,
std::optional<std::chrono::milliseconds> timeout,
size_t size) override;
void wakeupReader() override;
int write(std::string_view data) override;
Expand Down
2 changes: 1 addition & 1 deletion src/vtpty/MockViewPty.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ PtySlave& MockViewPty::slave() noexcept
}

optional<tuple<string_view, bool>> MockViewPty::read(crispy::buffer_object<char>& storage,
std::chrono::milliseconds /*timeout*/,
std::optional<std::chrono::milliseconds> /*timeout*/,
size_t size)
{
auto const n = min(min(_outputBuffer.size(), storage.bytesAvailable()), size);
Expand Down
7 changes: 4 additions & 3 deletions src/vtpty/MockViewPty.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ class MockViewPty: public Pty
void setReadData(std::string_view data);

PtySlave& slave() noexcept override;
[[nodiscard]] std::optional<std::tuple<std::string_view, bool>> read(crispy::buffer_object<char>& storage,
std::chrono::milliseconds timeout,
size_t size) override;
[[nodiscard]] std::optional<std::tuple<std::string_view, bool>> read(
crispy::buffer_object<char>& storage,
std::optional<std::chrono::milliseconds> timeout,
size_t size) override;
void wakeupReader() override;
int write(std::string_view data) override;
[[nodiscard]] PageSize pageSize() const noexcept override;
Expand Down
2 changes: 1 addition & 1 deletion src/vtpty/Process.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class [[nodiscard]] Process: public Pty
[[nodiscard]] PtySlave& slave() noexcept override { return pty().slave(); }
void close() override { pty().close(); }
[[nodiscard]] bool isClosed() const noexcept override { return pty().isClosed(); }
[[nodiscard]] ReadResult read(crispy::buffer_object<char>& storage, std::chrono::milliseconds timeout, size_t n) override { return pty().read(storage, timeout, n); }
[[nodiscard]] ReadResult read(crispy::buffer_object<char>& storage, std::optional<std::chrono::milliseconds> timeout, size_t n) override { return pty().read(storage, timeout, n); }
void wakeupReader() override { return pty().wakeupReader(); }
[[nodiscard]] int write(std::string_view data) override { return pty().write(data); }
[[nodiscard]] PageSize pageSize() const noexcept override { return pty().pageSize(); }
Expand Down
2 changes: 1 addition & 1 deletion src/vtpty/Pty.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class Pty
/// indicates whether or not this data was coming through
/// the stdout-fastpipe.
[[nodiscard]] virtual ReadResult read(crispy::buffer_object<char>& storage,
std::chrono::milliseconds timeout,
std::optional<std::chrono::milliseconds> timeout,
size_t size) = 0;

/// Inerrupts the read() operation on this PTY if a read() is currently in progress.
Expand Down
6 changes: 3 additions & 3 deletions src/vtpty/UnixPty.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ optional<string_view> UnixPty::readSome(int fd, char* target, size_t n) noexcept
}

Pty::ReadResult UnixPty::read(crispy::buffer_object<char>& storage,
std::chrono::milliseconds timeout,
std::optional<std::chrono::milliseconds> timeout,
size_t size)
{
if (auto const fd = _readSelector.wait_one(timeout); fd.has_value())
Expand All @@ -267,8 +267,8 @@ Pty::ReadResult UnixPty::read(crispy::buffer_object<char>& storage,
if (auto x = readSome(*fd, storage.hotEnd(), min(size, storage.bytesAvailable())))
return { tuple { x.value(), *fd == _stdoutFastPipe.reader() } };
}

errno = EAGAIN;
else
errno = EAGAIN;
return nullopt;
}

Expand Down
2 changes: 1 addition & 1 deletion src/vtpty/UnixPty.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class UnixPty final: public Pty
[[nodiscard]] bool isClosed() const noexcept override;
void wakeupReader() noexcept override;
[[nodiscard]] ReadResult read(crispy::buffer_object<char>& storage,
std::chrono::milliseconds timeout,
std::optional<std::chrono::milliseconds> timeout,
size_t size) override;
int write(std::string_view data) override;
[[nodiscard]] PageSize pageSize() const noexcept override;
Expand Down

0 comments on commit b885a9b

Please sign in to comment.