libssh 0.12.0
The SSH library
Loading...
Searching...
No Matches
ssh::Channel Class Reference

the ssh::Channel class describes the state of an SSH channel. More...

#include <libsshpp.hpp>

Public Member Functions

 Channel (Session &ssh_session)
Channel * acceptX11 (int timeout_ms)
 accept an incoming X11 connection
void_throwable changePtySize (int cols, int rows)
 change the size of a pseudoterminal
void_throwable close ()
 closes a channel
int getExitStatus ()
void_throwable getExitState (uint32_t &pexit_code, char **pexit_signal, int &pcore_dumped)
Session & getSession ()
bool isClosed ()
 returns true if channel is in closed state
bool isEof ()
 returns true if channel is in EOF state
bool isOpen ()
 returns true if channel is in open state
int openForward (const char *remotehost, int remoteport, const char *sourcehost, int localport=0)
 Open a TCP forward channel.
void_throwable openSession ()
int poll (bool is_stderr=false)
 Poll the channel for available data.
int read (void *dest, size_t count)
 Read data from the channel (blocking).
int read (void *dest, size_t count, int timeout)
 Read data from the channel with a timeout.
int read (void *dest, size_t count, bool is_stderr=false, int timeout=-1)
 Read data from the channel with optional stderr selection and timeout.
int readNonblocking (void *dest, size_t count, bool is_stderr=false)
 Read data from the channel without blocking.
void_throwable requestEnv (const char *name, const char *value)
void_throwable requestExec (const char *cmd)
void_throwable requestPty (const char *term=NULL, int cols=0, int rows=0, const unsigned char *modes=NULL, size_t modes_len=0)
void_throwable requestShell ()
void_throwable requestSendSignal (const char *signum)
void_throwable requestSubsystem (const char *subsystem)
int requestX11 (bool single_connection, const char *protocol, const char *cookie, int screen_number)
 Request X11 forwarding for this channel.
void_throwable sendEof ()
int write (const void *data, size_t len, bool is_stderr=false)
 Writes on a channel.
ssh_session getCSession ()
ssh_channel getCChannel ()

Protected Attributes

Session * session
ssh_channel channel

Friends

class Session

Detailed Description

the ssh::Channel class describes the state of an SSH channel.

See also
ssh_channel

Member Function Documentation

◆ acceptX11()

Channel * ssh::Channel::acceptX11 ( int timeout_ms)
inline

accept an incoming X11 connection

Parameters
[in]timeout_mstimeout for waiting, in ms
Returns
new Channel pointer on the X11 connection
NULL in case of error
Warning
you have to delete this pointer after use
See also
ssh_channel_accept_x11
Channel::requestX11

◆ changePtySize()

void_throwable ssh::Channel::changePtySize ( int cols,
int rows )
inline

change the size of a pseudoterminal

Parameters
[in]colsnumber of columns
[in]rowsnumber of rows
Exceptions
SshExceptionon error
See also
ssh_channel_change_pty_size

◆ close()

void_throwable ssh::Channel::close ( )
inline

closes a channel

Exceptions
SshExceptionon error
See also
ssh_channel_close

◆ isClosed()

bool ssh::Channel::isClosed ( )
inline

returns true if channel is in closed state

See also
ssh_channel_is_closed

◆ isEof()

bool ssh::Channel::isEof ( )
inline

returns true if channel is in EOF state

See also
ssh_channel_is_eof

◆ isOpen()

bool ssh::Channel::isOpen ( )
inline

returns true if channel is in open state

See also
ssh_channel_is_open

◆ openForward()

int ssh::Channel::openForward ( const char * remotehost,
int remoteport,
const char * sourcehost,
int localport = 0 )
inline

Open a TCP forward channel.

Parameters
[in]remotehostRemote host to connect to.
[in]remoteportRemote port to connect to.
[in]sourcehostSource address to report (can be NULL depending on server policy).
[in]localportLocal port to report (0 lets the server pick if applicable).
Returns
SSH_OK (0) on success.
SSH_ERROR on error (no-exception builds).
Exceptions
SshExceptionon error (exception-enabled builds).
See also
ssh_channel_open_forward

◆ poll()

int ssh::Channel::poll ( bool is_stderr = false)
inline

Poll the channel for available data.

Parameters
[in]is_stderrIf true, poll stderr stream; otherwise stdout.
Returns
Number of bytes available to read (>= 0).
SSH_ERROR on error (no-exception builds).
Exceptions
SshExceptionon error (exception-enabled builds).
See also
ssh_channel_poll

◆ read() [1/3]

int ssh::Channel::read ( void * dest,
size_t count )
inline

Read data from the channel (blocking).

Parameters
[out]destDestination buffer.
[in]countMaximum number of bytes to read.
Returns
Number of bytes read (>= 0). A return of 0 indicates EOF/no data.
SSH_ERROR on error (no-exception builds).
Exceptions
SshExceptionon error (exception-enabled builds).
See also
ssh_channel_read_timeout

◆ read() [2/3]

int ssh::Channel::read ( void * dest,
size_t count,
bool is_stderr = false,
int timeout = -1 )
inline

Read data from the channel with optional stderr selection and timeout.

Parameters
[out]destDestination buffer.
[in]countMaximum number of bytes to read.
[in]is_stderrIf true, read from the stderr stream; otherwise read from stdout.
[in]timeoutTimeout in milliseconds. A negative value means infinite timeout.
Returns
Number of bytes read (>= 0). A return value of 0 indicates EOF.
SSH_ERROR on error (no-exception builds).
Exceptions
SshExceptionon error (exception-enabled builds).
See also
ssh_channel_read_timeout

◆ read() [3/3]

int ssh::Channel::read ( void * dest,
size_t count,
int timeout )
inline

Read data from the channel with a timeout.

Parameters
[out]destDestination buffer.
[in]countMaximum number of bytes to read.
[in]timeoutTimeout in milliseconds. A negative value means infinite timeout.
Returns
Number of bytes read (>= 0). A return value of 0 indicates EOF.
SSH_ERROR on error (no-exception builds).
Exceptions
SshExceptionon error (exception-enabled builds).
See also
ssh_channel_read_timeout

◆ readNonblocking()

int ssh::Channel::readNonblocking ( void * dest,
size_t count,
bool is_stderr = false )
inline

Read data from the channel without blocking.

Parameters
[out]destDestination buffer.
[in]countMaximum number of bytes to read.
[in]is_stderrIf true, read from the stderr stream; otherwise read from stdout.
Returns
Number of bytes read (>= 0). A return of 0 may indicate no data.
SSH_ERROR on error (no-exception builds).
Exceptions
SshExceptionon error (exception-enabled builds).
See also
ssh_channel_read_nonblocking

◆ requestX11()

int ssh::Channel::requestX11 ( bool single_connection,
const char * protocol,
const char * cookie,
int screen_number )
inline

Request X11 forwarding for this channel.

Parameters
[in]single_connectionIf true, allow only a single X11 connection for this channel; further X11 connections are refused after the first is accepted.
[in]protocolX11 authentication protocol.
[in]cookieX11 authentication cookie.
[in]screen_numberX11 screen number.
Returns
SSH_OK on success.
SSH_ERROR on error (no-exception builds).

◆ write()

int ssh::Channel::write ( const void * data,
size_t len,
bool is_stderr = false )
inline

Writes on a channel.

Parameters
[in]datadata to write.
[in]lennumber of bytes to write.
[in]is_stderrwrite should be done on the stderr channel (server only)
Returns
number of bytes written
Exceptions
SshExceptionin case of error
See also
ssh_channel_write
ssh_channel_write_stderr

The documentation for this class was generated from the following file:
  • /home/asn/workspace/prj/oss/libssh/asn-docs/include/libssh/libsshpp.hpp