Dobby  3.0
Dobby “Docker based Thingy” is a tool for managing and running OCI containers using crun
Public Member Functions | Private Attributes | List of all members
DobbyBufferStream Class Reference

Stream that just redirects all the input to an internal memory buffer. More...

#include <DobbyStream.h>

Inheritance diagram for DobbyBufferStream:
Inheritance graph
[legend]
Collaboration diagram for DobbyBufferStream:
Collaboration graph
[legend]

Public Member Functions

 DobbyBufferStream (ssize_t limit=-1)
 Constructs the buffer using an memfd. More...
 
int dupWriteFD (int newFd, bool closeExec) const override
 Returns a dup'd file descriptor for the write side of the stream. More...
 
std::vector< char > getBuffer () const
 Reads all the data in the buffer. More...
 
int getMemFd () const
 

Private Attributes

int mMemFd
 

Detailed Description

Stream that just redirects all the input to an internal memory buffer.

This is useful for capturing the stderr output, or other small bits of text output from a command line tool.

Note
This object is not very efficient and should only be used for small amounts of text data.

Constructor & Destructor Documentation

◆ DobbyBufferStream()

DobbyBufferStream::DobbyBufferStream ( ssize_t  limit = -1)
explicit

Constructs the buffer using an memfd.

Parameters
[in]limitThe maximum number of bytes that can be written into the buffer.

Member Function Documentation

◆ dupWriteFD()

int DobbyBufferStream::dupWriteFD ( int  newFd,
bool  closeExec 
) const
overridevirtual

Returns a dup'd file descriptor for the write side of the stream.

If the file descriptor newfd was previously open, it is silently closed before being reused. If newFd is -1 then the lowest-numbered unused file descriptor number is used.

Parameters
[in]newFdThe number to give the new dup'd file descriptor.
[in]closeExecIf true the O_CLOEXEC flag is set on the new fd
Returns
the new file descriptor, on error -1.

Implements IDobbyStream.

◆ getBuffer()

std::vector< char > DobbyBufferStream::getBuffer ( ) const

Reads all the data in the buffer.

This doesn't do a flush or anything, this just returns everything written into the buffer.


The documentation for this class was generated from the following files: