GNU Octave  8.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
KPty Class Reference

Provides primitives for opening & closing a pseudo TTY pair, assigning the controlling TTY, utmp registration and setting various terminal attributes. More...

#include "kpty.h"

Collaboration diagram for KPty:

Public Member Functions

 KPty ()
 Constructor. More...
 
 KPty (int masterFd, int slaveFd)
 
 ~KPty ()
 Destructor: More...
 
void close ()
 Close the pty master/slave pair. More...
 
void closeSlave ()
 Close the pty slave descriptor. More...
 
int masterFd () const
 
bool open ()
 Create a pty master/slave pair. More...
 
bool setEcho (bool echo)
 Set whether the pty should echo input. More...
 
bool setWinSize (int lines, int columns)
 Change the logical (screen) size of the pty. More...
 
int slaveFd () const
 
bool tcGetAttr (struct ::termios *ttmode) const
 Wrapper around tcgetattr(3). More...
 
bool tcSetAttr (struct ::termios *ttmode)
 Wrapper around tcsetattr(3) with mode TCSANOW. More...
 
const char * ttyName () const
 

Protected Member Functions

 KPty (KPtyPrivate *d)
 

Protected Attributes

KPtyPrivate *const d_ptr
 

Detailed Description

Provides primitives for opening & closing a pseudo TTY pair, assigning the controlling TTY, utmp registration and setting various terminal attributes.

Definition at line 35 of file kpty.h.

Constructor & Destructor Documentation

◆ KPty() [1/3]

KPty::KPty ( )

Constructor.

Definition at line 193 of file kpty.cpp.

◆ KPty() [2/3]

KPty::KPty ( int  masterFd,
int  slaveFd 
)

Definition at line 198 of file kpty.cpp.

◆ ~KPty()

KPty::~KPty ( )

Destructor:

If the pty is still open, it will be closed. Note, however, that an utmp registration is not undone.

Definition at line 209 of file kpty.cpp.

References close(), and d_ptr.

◆ KPty() [3/3]

KPty::KPty ( KPtyPrivate d)
protected

Definition at line 203 of file kpty.cpp.

References d_ptr, and KPtyPrivate::q_ptr.

Member Function Documentation

◆ close()

void KPty::close ( void  )

Close the pty master/slave pair.

Definition at line 406 of file kpty.cpp.

References closeSlave(), d, fcntl(), geteuid(), getgid(), and stat().

Referenced by ~KPty(), closeSlave(), and open().

◆ closeSlave()

void KPty::closeSlave ( )

Close the pty slave descriptor.

When creating the pty, KPty also opens the slave and keeps it open. Consequently the master will never receive an EOF notification. Usually this is the desired behavior, as a closed pty slave can be reopened any time - unlike a pipe or socket. However, in some cases pipe-alike behavior might be desired.

After this function was called, slaveFd() and setCTty() cannot be used.

Definition at line 396 of file kpty.cpp.

References close(), and d.

Referenced by close().

◆ masterFd()

int KPty::masterFd ( ) const
Returns
the file descriptor of the master pty

This function should be called only while the pty is open.

Definition at line 482 of file kpty.cpp.

References d.

Referenced by TerminalModel::TerminalModel(), and TerminalModel::sendData().

◆ open()

bool KPty::open ( )

Create a pty master/slave pair.

Returns
true if a pty pair was successfully opened

Definition at line 215 of file kpty.cpp.

References close(), d, fcntl(), geteuid(), getgid(), group::getgrnam(), getuid(), group::gid(), PATH_MAX, stat(), tcGetAttr(), tcSetAttr(), and TTY_GROUP.

Referenced by QUnixTerminalImpl::initialize().

◆ setEcho()

bool KPty::setEcho ( bool  echo)

Set whether the pty should echo input.

Echo is on by default. If the output of automatically fed (non-interactive) PTY clients needs to be parsed, disabling echo often makes it much simpler.

This function can be used only while the PTY is open.

Parameters
echotrue if input should be echoed.
Returns
true on success, false otherwise

Definition at line 463 of file kpty.cpp.

References ECHO, tcGetAttr(), and tcSetAttr().

◆ setWinSize()

bool KPty::setWinSize ( int  lines,
int  columns 
)

Change the logical (screen) size of the pty.

The default is 24 lines by 80 columns.

This function can be used only while the PTY is open.

Parameters
linesthe number of rows
columnsthe number of columns
Returns
true on success, false otherwise

Definition at line 452 of file kpty.cpp.

References d.

Referenced by TerminalModel::updateTerminalSize().

◆ slaveFd()

int KPty::slaveFd ( ) const
Returns
the file descriptor of the slave pty

This function should be called only while the pty slave is open.

Definition at line 489 of file kpty.cpp.

References d.

Referenced by QUnixTerminalImpl::connectToPty().

◆ tcGetAttr()

bool KPty::tcGetAttr ( struct ::termios *  ttmode) const

Wrapper around tcgetattr(3).

This function can be used only while the PTY is open. You will need an #include <termios.h> to do anything useful with it.

Parameters
ttmodea pointer to a termios structure. Note: when declaring ttmode, struct ::termios must be used - without the '::' some version of HP-UX thinks, this declares the struct in your class, in your method.
Returns
true on success, false otherwise

Definition at line 438 of file kpty.cpp.

References d.

Referenced by open(), and setEcho().

◆ tcSetAttr()

bool KPty::tcSetAttr ( struct ::termios *  ttmode)

Wrapper around tcsetattr(3) with mode TCSANOW.

This function can be used only while the PTY is open.

Parameters
ttmodea pointer to a termios structure.
Returns
true on success, false otherwise. Note that success means that at least one attribute could be set.

Definition at line 445 of file kpty.cpp.

References d.

Referenced by open(), and setEcho().

◆ ttyName()

const char * KPty::ttyName ( ) const
Returns
the name of the slave pty device.

This function should be called only while the pty is open.

Definition at line 475 of file kpty.cpp.

References d.

Member Data Documentation

◆ d_ptr

KPtyPrivate* const KPty::d_ptr
protected

Definition at line 162 of file kpty.h.

Referenced by KPty(), and ~KPty().


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