Async 1.8.0
Async::Pty Class Reference

A wrapper class for using a PTY. More...

#include <AsyncPty.h>

Inheritance diagram for Async::Pty:

Public Member Functions

 Pty (const std::string &slave_link="")
 Constructor.
 
 ~Pty (void)
 Destructor.
 
void setLineBuffered (bool line_buffered)
 Turn line buffering on or off.
 
bool open (void)
 Open the PTY.
 
void close (void)
 Close the PTY if it's open.
 
bool reopen (void)
 Reopen the PTY.
 
ssize_t write (const void *buf, size_t count)
 Write data to the PTY.
 
ssize_t write (const std::string &str)
 Write a string to the PTY.
 
bool isOpen (void) const
 Check if the PTY is open or not.
 
const std::string & slavePath (void) const
 Get the path to the slave PTS device.
 

Public Attributes

sigc::signal< void, const void *, size_t > dataReceived
 Signal that is emitted when data has been received.
 

Detailed Description

A wrapper class for using a PTY.

Author
Tobias Blomberg / SM0SVX
Date
2014-06-07

This class wrap up some functionality that is nice to have when using a PTY.

The PTY is opened in raw mode.

If the slave end of the PTY is not open, the master file descriptor will be continuously polled to detect when it is opened. When the slave end of the PTY is open, an FdWatch will be used to check for activity instead of polling.

Data written to the master end will be discarded if the slave end is not open.

Examples
AsyncPtyStreamBuf_demo.cpp.

Definition at line 124 of file AsyncPty.h.

Constructor & Destructor Documentation

◆ Pty()

Async::Pty::Pty ( const std::string & slave_link = "")

Constructor.

Parameters
slave_linkPath to the slave softlink

◆ ~Pty()

Async::Pty::~Pty ( void )

Destructor.

Member Function Documentation

◆ close()

void Async::Pty::close ( void )

Close the PTY if it's open.

Close the PTY if it's open. This function is safe to call even if the PTY is not open or if it's just partly opened.

◆ isOpen()

bool Async::Pty::isOpen ( void ) const
inline

Check if the PTY is open or not.

Returns
Returns true if the PTY has been successfully opened

Definition at line 208 of file AsyncPty.h.

◆ open()

bool Async::Pty::open ( void )

Open the PTY.

Returns
Returns true on success or false on failure

Use this function to open the PTY. If the PTY is already open it will be closed first.

◆ reopen()

bool Async::Pty::reopen ( void )

Reopen the PTY.

Returns
Returns true on success or false on failure

Try to reopen the PTY. On failure an error message will be printed and the PTY will stay closed.

◆ setLineBuffered()

void Async::Pty::setLineBuffered ( bool line_buffered)
inline

Turn line buffering on or off.

Parameters
line_bufferedSet to be line buffered if true

Definition at line 142 of file AsyncPty.h.

◆ slavePath()

const std::string & Async::Pty::slavePath ( void ) const
inline

Get the path to the slave PTS device.

Returns
Returns the slave path after the PTY has been opened

Definition at line 214 of file AsyncPty.h.

◆ write() [1/2]

ssize_t Async::Pty::write ( const std::string & str)
inline

Write a string to the PTY.

Parameters
strA string to write
Returns
On success, the number of bytes written is returned (zero indicates nothing was written). On error, -1 is returned, and errno is set appropriately.

Use this function to write a string to the PTY. If the slave end of the PTY is not open, the written string will just be discarded and the string length is used as the return value.

Definition at line 199 of file AsyncPty.h.

References write().

◆ write() [2/2]

ssize_t Async::Pty::write ( const void * buf,
size_t count )

Write data to the PTY.

Parameters
bufA buffer containing the data to write
countThe number of bytes to write
Returns
On success, the number of bytes written is returned (zero indicates nothing was written). On error, -1 is returned, and errno is set appropriately.

Use this function to write data to the PTY. If the slave end of the PTY is not open, the written data will just be discarded and count is used as the return value.

Referenced by write().

Member Data Documentation

◆ dataReceived

sigc::signal<void, const void*, size_t> Async::Pty::dataReceived

Signal that is emitted when data has been received.

Parameters
bufA buffer containing the received data
countThe number of bytes in the buffer

Definition at line 221 of file AsyncPty.h.


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