Skip to content

Commit

Permalink
chunk: add sealed flag
Browse files Browse the repository at this point in the history
For some reason
  • Loading branch information
felipec committed Mar 19, 2023
1 parent 8ad932d commit c0a93be
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
8 changes: 8 additions & 0 deletions src/chunk.hh
Expand Up @@ -54,6 +54,7 @@ private:
static constexpr const unsigned k_overlap_size = 1u;

enum class Flags : uint8_t {
eSEALED = 1u << 0,
eEOS = 1u << 1,
eCHAINED = 1u << 2,
};
Expand Down Expand Up @@ -173,6 +174,13 @@ public:
// Prune recycled chunks
static void prune(unsigned int max_size = k_max_free_chunks) noexcept;

// Returns: whether the chunk is sealed, i.e. must not be used
// to write more data into
inline constexpr bool sealed() const noexcept { return m_flags & (uint8_t)Flags::eSEALED; }

// Seal the chunk
inline void set_sealed() noexcept { m_flags |= (uint8_t)Flags::eSEALED; }

// Returns: whether the chunk is an EOS (end-of-stream)
inline constexpr bool eos() const noexcept { return m_flags & (uint8_t)Flags::eEOS; }

Expand Down
9 changes: 6 additions & 3 deletions src/vte.cc
Expand Up @@ -3920,8 +3920,9 @@ Terminal::pty_io_read(int const fd,
chunk = m_incoming_queue.back().get();

do {
/* No chunk or at least ¾ full? Get a new chunk */
/* No chunk, chunk sealed or at least ¾ full? Get a new chunk */
if (!chunk ||
chunk->sealed() ||
chunk->capacity_writing() < chunk->capacity() / 4) {
m_incoming_queue.push(vte::base::Chunk::get(chunk));
chunk = m_incoming_queue.back().get();
Expand Down Expand Up @@ -4093,8 +4094,10 @@ Terminal::pty_io_read(int const fd,
if (eos) {
_vte_debug_print(VTE_DEBUG_IO, "got PTY EOF\n");

if (chunk)
if (chunk) {
chunk->sealed();
chunk->set_eos();
}

queue_eof();

Expand All @@ -4120,7 +4123,7 @@ Terminal::feed(std::string_view const& data,
vte::base::Chunk* chunk = nullptr;
if (!m_incoming_queue.empty()) {
auto& achunk = m_incoming_queue.back();
if (length < achunk->capacity_writing())
if (length < achunk->capacity_writing() && !achunk->sealed())
chunk = achunk.get();
}
if (chunk == nullptr) {
Expand Down

0 comments on commit c0a93be

Please sign in to comment.