KPty

Search for usage in LXR

#include <kpty.h>

Inheritance diagram for KPty:

Public Member Functions

 KPty ()
 
 KPty (const KPty &)=delete
 
 ~KPty ()
 
void close ()
 
void closeSlave ()
 
void login (const char *user=nullptr, const char *remotehost=nullptr)
 
void logout ()
 
int masterFd () const
 
bool open ()
 
bool open (int fd)
 
bool openSlave ()
 
KPtyoperator= (const KPty &)=delete
 
void setCTty ()
 
bool setEcho (bool echo)
 
bool setWinSize (int lines, int columns)
 
int slaveFd () const
 
bool tcGetAttr (struct::termios *ttmode) const
 
bool tcSetAttr (struct::termios *ttmode)
 
const char * ttyName () const
 

Protected Member Functions

 KPty (KPtyPrivate *d)
 

Protected Attributes

std::unique_ptr< 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 24 of file kpty.h.

Constructor & Destructor Documentation

KPty::KPty ( )

Constructor.

Definition at line 168 of file kpty.cpp.

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 179 of file kpty.cpp.

KPty::KPty ( KPtyPrivate *  d)
protected

Definition at line 173 of file kpty.cpp.

Member Function Documentation

void KPty::close ( )

Close the pty master/slave pair.

Definition at line 396 of file kpty.cpp.

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 365 of file kpty.cpp.

void KPty::login ( const char *  user = nullptr,
const char *  remotehost = nullptr 
)

Creates an utmp entry for the tty.

This function must be called after calling setCTty and making this pty the stdin.

Parameters
userthe user to be logged on
remotehostthe host from which the login is coming. This is not the local host. For remote logins it should be the hostname of the client. For local logins from inside an X session it should be the name of the X display. Otherwise it should be empty.

Definition at line 443 of file kpty.cpp.

void KPty::logout ( )

Removes the utmp entry for this tty.

Definition at line 532 of file kpty.cpp.

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 657 of file kpty.cpp.

bool KPty::open ( )

Create a pty master/slave pair.

Returns
true if a pty pair was successfully opened

Definition at line 184 of file kpty.cpp.

bool KPty::open ( int  fd)

Open using an existing pty master.

Parameters
fdan open pty master file descriptor. The ownership of the fd remains with the caller; it will not be automatically closed at any point.
Returns
true if a pty pair was successfully opened

Definition at line 324 of file kpty.cpp.

bool KPty::openSlave ( )

Open the pty slave descriptor.

This undoes the effect of closeSlave().

Returns
true if the pty slave was successfully opened

Definition at line 376 of file kpty.cpp.

void KPty::setCTty ( )

Creates a new session and process group and makes this pty the controlling tty.

Definition at line 425 of file kpty.cpp.

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 636 of file kpty.cpp.

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 625 of file kpty.cpp.

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 664 of file kpty.cpp.

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 611 of file kpty.cpp.

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 618 of file kpty.cpp.

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 650 of file kpty.cpp.

Member Data Documentation

std::unique_ptr<KPtyPrivate> const KPty::d_ptr
protected

Definition at line 195 of file kpty.h.


The documentation for this class was generated from the following files:
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Fri Apr 16 2021 22:52:34 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.