Async 1.5.0
Public Member Functions | Public Attributes | List of all members
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="")
 Default constructor.
 
 ~Pty (void)
 Destructor.
 
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.
 
bool isOpen (void) const
 Check if the PTY is open or not.
 

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 = "")

Default constructor.

◆ ~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 181 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.

◆ write()

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.

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 188 of file AsyncPty.h.


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