TSDuck v3.40-4033
MPEG Transport Stream Toolkit
|
Implementation of a half-duplex line oriented telnet connection. More...
#include <tsTelnetConnection.h>
Public Types | |
using | SuperClass = TCPConnection |
Reference to the superclass. | |
Public Member Functions | |
TelnetConnection (const std::string &prompt=std::string()) | |
Constructor. | |
virtual | ~TelnetConnection () override |
Virtual destructor. | |
bool | bind (const IPSocketAddress &addr, Report &report=(ts::CerrReport::Instance())) |
Bind to a local address and port. | |
virtual bool | close (Report &report=(ts::CerrReport::Instance())) override |
Close the socket. | |
bool | closeWriter (Report &report=(ts::CerrReport::Instance())) |
Close the write direction of the connection. | |
bool | connect (const IPSocketAddress &addr, Report &report=(ts::CerrReport::Instance())) |
Connect to a remote address and port. | |
bool | debug () const |
Check if debugging is active. | |
template<class... Args> | |
void | debug (const UChar *fmt, Args &&... args) |
Report a debug message with a printf-like interface. | |
void | debug (const UChar *msg) |
Report a debug message. | |
template<class... Args> | |
void | debug (const UString &fmt, Args &&... args) |
Report a debug message with a printf-like interface. | |
void | debug (const UString &msg) |
Report a debug message. | |
Report * | delegateReport (Report *report) |
Delegate message logging to another report object. | |
bool | disconnect (Report &report=(ts::CerrReport::Instance())) |
Disconnect from remote partner. | |
template<class... Args> | |
void | error (const UChar *fmt, Args &&... args) |
Report an error message with a printf-like interface. | |
void | error (const UChar *msg) |
Report an error message. | |
template<class... Args> | |
void | error (const UString &fmt, Args &&... args) |
Report an error message with a printf-like interface. | |
void | error (const UString &msg) |
Report an error message. | |
template<class... Args> | |
void | fatal (const UChar *fmt, Args &&... args) |
Report a fatal error message with a printf-like interface. | |
void | fatal (const UChar *msg) |
Report a fatal error message. | |
template<class... Args> | |
void | fatal (const UString &fmt, Args &&... args) |
Report a fatal error message with a printf-like interface. | |
void | fatal (const UString &msg) |
Report a fatal error message. | |
IP | generation () const |
Get the IP generation with which the socket was open. | |
bool | getLocalAddress (IPSocketAddress &addr, Report &report=(ts::CerrReport::Instance())) |
Get local socket address. | |
bool | getPeer (IPSocketAddress &addr, Report &report=(ts::CerrReport::Instance())) const |
Get the connected remote peer. | |
SysSocketType | getSocket () const |
Get the underlying socket device handle (use with care). | |
bool | gotErrors () const |
Check if errors (or worse) were reported through this object. | |
template<class... Args> | |
void | info (const UChar *fmt, Args &&... args) |
Report an informational message with a printf-like interface. | |
void | info (const UChar *msg) |
Report an informational message. | |
template<class... Args> | |
void | info (const UString &fmt, Args &&... args) |
Report an informational message with a printf-like interface. | |
void | info (const UString &msg) |
Report an informational message. | |
bool | isConnected () const |
Check if the socket is connected. | |
bool | isOpen () const |
Check if socket is open. | |
template<class... Args> | |
void | log (int severity, const UChar *fmt, Args &&... args) |
Report a message with an explicit severity and a printf-like interface. | |
template<class... Args> | |
void | log (int severity, const UString &fmt, Args &&... args) |
Report a message with an explicit severity and a printf-like interface. | |
void | log (int severity, const UString &msg) |
Report a message with an explicit severity. | |
int | maxSeverity () const |
Get maximum severity level. | |
virtual bool | open (IP gen, Report &report=(ts::CerrReport::Instance())) override |
Open the socket. | |
UString | peerName () const |
Get the connected remote peer as a string. | |
void | raiseMaxSeverity (int level) |
Raise maximum severity level. | |
bool | receive (std::string &data, const AbortInterface *abort, Report &report) |
Receive character data. | |
bool | receive (UString &data, const AbortInterface *abort, Report &report) |
Receive character data. | |
bool | receive (void *buffer, size_t max_size, size_t &ret_size, const AbortInterface *abort=nullptr, Report &report=(ts::CerrReport::Instance())) |
Receive data. | |
bool | receive (void *buffer, size_t size, const AbortInterface *abort=nullptr, Report &report=(ts::CerrReport::Instance())) |
Receive data until buffer is full. | |
bool | receiveLine (std::string &line, const AbortInterface *abort, Report &report) |
Receive a line. | |
bool | receiveLine (UString &line, const AbortInterface *abort, Report &report) |
Receive a line. | |
UString | reportPrefix () const |
Get the current prefix to display. | |
void | resetErrors () |
Reset the error indicator. | |
bool | reusePort (bool reuse_port, Report &report=(ts::CerrReport::Instance())) |
Set the "reuse port" option. | |
bool | send (const std::string &str, Report &report) |
Send a string to the server. | |
bool | send (const UString &str, Report &report) |
Send a string to the server. | |
bool | send (const void *data, size_t size, Report &report=(ts::CerrReport::Instance())) |
Send data. | |
bool | sendLine (const std::string &str, Report &report) |
Send a text line to the server. | |
bool | sendLine (const UString &str, Report &report) |
Send a text line to the server. | |
bool | setKeepAlive (bool active, Report &report=(ts::CerrReport::Instance())) |
Set the "keep alive" option. | |
bool | setLingerTime (int seconds, Report &report=(ts::CerrReport::Instance())) |
Set the linger time option. | |
void | setMaxSeverity (int level) |
Set maximum severity level. | |
bool | setNoDelay (bool active, Report &report=(ts::CerrReport::Instance())) |
Set the "no delay" option. | |
bool | setNoLinger (Report &report=(ts::CerrReport::Instance())) |
Remove the linger time option. | |
bool | setReceiveBufferSize (size_t size, Report &report=(ts::CerrReport::Instance())) |
Set the receive buffer size. | |
bool | setReceiveTimeout (cn::milliseconds timeout, Report &report=(ts::CerrReport::Instance())) |
Set the receive timeout. | |
void | setReportPrefix (const UString &prefix) |
Set the prefix to display before each message. | |
bool | setSendBufferSize (size_t size, Report &report=(ts::CerrReport::Instance())) |
Set the send buffer size. | |
bool | setTTL (int ttl, Report &report=(ts::CerrReport::Instance())) |
Set the Time To Live (TTL) option. | |
template<class... Args> | |
void | severe (const UChar *fmt, Args &&... args) |
Report a severe error message with a printf-like interface. | |
void | severe (const UChar *msg) |
Report a severe error message. | |
template<class... Args> | |
void | severe (const UString &fmt, Args &&... args) |
Report a severe error message with a printf-like interface. | |
void | severe (const UString &msg) |
Report a severe error message. | |
bool | verbose () const |
Check if verbose reporting is active. | |
template<class... Args> | |
void | verbose (const UChar *fmt, Args &&... args) |
Report a verbose message with a printf-like interface. | |
void | verbose (const UChar *msg) |
Report a verbose message. | |
template<class... Args> | |
void | verbose (const UString &fmt, Args &&... args) |
Report a verbose message with a printf-like interface. | |
void | verbose (const UString &msg) |
Report a verbose message. | |
bool | waitForPrompt (const AbortInterface *abort, Report &report) |
Receive a prompt. | |
template<class... Args> | |
void | warning (const UChar *fmt, Args &&... args) |
Report a warning message with a printf-like interface. | |
void | warning (const UChar *msg) |
Report a warning error message. | |
template<class... Args> | |
void | warning (const UString &fmt, Args &&... args) |
Report a warning message with a printf-like interface. | |
void | warning (const UString &msg) |
Report a warning error message. | |
Static Public Attributes | |
static const std::string | EOL |
A telnet end-of-line sequence. | |
Protected Member Functions | |
bool | convert (IPAddress &addr, Report &report) const |
Convert an IP address to make it compatible with the socket IP generation. | |
bool | createSocket (IP gen, int type, int protocol, Report &report) |
Create the socket. | |
virtual void | declareOpened (SysSocketType sock, Report &report) override |
Set an open socket descriptor from a subclass. | |
virtual void | handleClosed (Report &report=(ts::CerrReport::Instance())) override |
This virtual method can be overriden by subclasses to be notified of close. | |
virtual void | handleConnected (Report &report=(ts::CerrReport::Instance())) |
This virtual method can be overriden by subclasses to be notified of connection. | |
virtual void | handleDisconnected (Report &report=(ts::CerrReport::Instance())) |
This virtual method can be overriden by subclasses to be notified of disconnection. | |
virtual void | handleOpened (Report &report) |
This virtual method can be overriden by subclasses to be notified of open. | |
virtual void | writeLog (int severity, const UString &msg) override |
Actual message reporting method. | |
Protected Attributes | |
std::recursive_mutex | _mutex {} |
Mutex protecting this object. | |
Implementation of a half-duplex line oriented telnet connection.
This class supports the communication with a half-duplex line oriented telnet server:
From the client point of view the interface must allow:
This class is also a subclass of Report, allowing it to be used to end log messages.
ts::TelnetConnection::TelnetConnection | ( | const std::string & | prompt = std::string() | ) |
Constructor.
[in] | prompt | Prompt string to send to the client. |
bool ts::TelnetConnection::send | ( | const std::string & | str, |
Report & | report | ||
) |
Send a string to the server.
[in] | str | The string to send to the server. |
[in,out] | report | Where to report errors. |
Send a string to the server.
[in] | str | The string to send to the server. |
[in,out] | report | Where to report errors. |
bool ts::TelnetConnection::sendLine | ( | const std::string & | str, |
Report & | report | ||
) |
Send a text line to the server.
[in] | str | The line to send to the server. |
[in,out] | report | Where to report errors. |
Send a text line to the server.
[in] | str | The line to send to the server. |
[in,out] | report | Where to report errors. |
bool ts::TelnetConnection::receive | ( | std::string & | data, |
const AbortInterface * | abort, | ||
Report & | report | ||
) |
Receive character data.
[out] | data | The received data. |
[in] | abort | If non-zero, invoked when I/O is interrupted (in case of user-interrupt, return, otherwise retry). |
[in,out] | report | Where to report errors. |
bool ts::TelnetConnection::receive | ( | UString & | data, |
const AbortInterface * | abort, | ||
Report & | report | ||
) |
Receive character data.
[out] | data | The received data. |
[in] | abort | If non-zero, invoked when I/O is interrupted (in case of user-interrupt, return, otherwise retry). |
[in,out] | report | Where to report errors. |
bool ts::TelnetConnection::receiveLine | ( | std::string & | line, |
const AbortInterface * | abort, | ||
Report & | report | ||
) |
Receive a line.
[out] | line | The received line. |
[in] | abort | If non-zero, invoked when I/O is interrupted (in case of user-interrupt, return, otherwise retry). |
[in,out] | report | Where to report errors. |
bool ts::TelnetConnection::receiveLine | ( | UString & | line, |
const AbortInterface * | abort, | ||
Report & | report | ||
) |
Receive a line.
[out] | line | The received line. |
[in] | abort | If non-zero, invoked when I/O is interrupted (in case of user-interrupt, return, otherwise retry). |
[in,out] | report | Where to report errors. |
bool ts::TelnetConnection::waitForPrompt | ( | const AbortInterface * | abort, |
Report & | report | ||
) |
Receive a prompt.
Do not wait if the prompt is empty.
[in] | abort | If non-zero, invoked when I/O is interrupted (in case of user-interrupt, return, otherwise retry). |
[in,out] | report | Where to report errors. |
|
overrideprotectedvirtual |
Actual message reporting method.
The method is called only when a message passed the severity filter. It is not necessary to recheck the maximum severity inside the method. By default, does nothing.
[in] | severity | Message severity. |
[in] | msg | Message text. |
Reimplemented from ts::Report.
|
inherited |
Connect to a remote address and port.
Use this method when acting as TCP client. Do not use on server side: the TCPConnection object is passed to TCPServer::accept() which establishes the connection.
[in] | addr | IP address and port of the server to connect. |
[in,out] | report | Where to report error. |
|
inlineinherited |
Check if the socket is connected.
|
inherited |
Get the connected remote peer.
[out] | addr | IP address and port of the remote socket. |
[in,out] | report | Where to report error. |
|
inherited |
Get the connected remote peer as a string.
|
inherited |
Close the write direction of the connection.
The application shall call this routine after sending the last message but may still want to receive messages, waiting for the peer to voluntary disconnect.
[in,out] | report | Where to report error. |
|
inherited |
Disconnect from remote partner.
[in,out] | report | Where to report error. |
|
inherited |
Send data.
[in] | data | Address of the data to send. |
[in] | size | Size in bytes of the data to send. |
[in,out] | report | Where to report error. |
|
inherited |
Receive data.
This version of receive() returns when "some" data are received into the user buffer. The actual received data may be shorter than the user buffer size.
The version is typically useful when the application cannot predict how much data will be received and must respond even if the user buffer is not full.
[out] | buffer | Address of the buffer for the received data. |
[in] | max_size | Size in bytes of the reception buffer. |
[out] | ret_size | Size in bytes of the received data. Will never be larger than max_size. |
[in] | abort | If non-zero, invoked when I/O is interrupted (in case of user-interrupt, return, otherwise retry). |
[in,out] | report | Where to report error. |
|
inherited |
Receive data until buffer is full.
This version of receive() returns only when sufficient data are received to completely fill the user buffer. The size of the actual received data is identical to the user buffer size.
The version is typically useful when the application knows that a certain amount of data is expected and must wait for them.
[out] | buffer | Address of the buffer for the received data. |
[in] | size | Size in bytes of the buffer. |
[in] | abort | If non-zero, invoked when I/O is interrupted (in case of user-interrupt, return, otherwise retry). |
[in,out] | report | Where to report error. |
|
protectedvirtualinherited |
This virtual method can be overriden by subclasses to be notified of connection.
All subclasses should explicitly invoke their superclass' handlers.
[in,out] | report | Where to report error. |
Reimplemented in ts::tlv::Connection< SAFETY >, ts::tlv::Connection< ThreadSafety::Full >, and ts::tlv::Connection< ThreadSafety::None >.
|
protectedvirtualinherited |
This virtual method can be overriden by subclasses to be notified of disconnection.
All subclasses should explicitly invoke their superclass' handlers.
[in,out] | report | Where to report error. |
|
overrideprotectedvirtualinherited |
This virtual method can be overriden by subclasses to be notified of close.
All subclasses should explicitly invoke their superclass' handlers.
[in,out] | report | Where to report error. |
Reimplemented from ts::TCPSocket.
|
inherited |
Set the Time To Live (TTL) option.
[in] | ttl | The TTL value, ie. the maximum number of "hops" between routers before an IP packet is dropped. |
[in,out] | report | Where to report error. |
|
inherited |
Remove the linger time option.
[in,out] | report | Where to report error. |
|
inherited |
Set the linger time option.
[in] | seconds | Number of seconds to wait after shuting down the socket. |
[in,out] | report | Where to report error. |
|
inherited |
Set the "keep alive" option.
[in] | active | If true, the socket periodically sends "keep alive" packets when the connection is idle. |
[in,out] | report | Where to report error. |
|
inherited |
Set the "no delay" option.
[in] | active | If true, the socket immediately sends outgoing packets. By default, a TCP socket waits a small amount of time after a send() operation to get a chance to group outgoing data from successive send() operations into one single packet. |
[in,out] | report | Where to report error. |
|
inherited |
Bind to a local address and port.
The IP address part of the socket address must one of:
The port number part of the socket address must be one of:
[in] | addr | Local socket address to bind to. |
[in,out] | report | Where to report error. |
|
overridevirtualinherited |
Open the socket.
[in] | gen | IP generation, IPv4 or IPv6. If set to IP::Any, open an IPv6 socket (IPv4 connections allowed). |
[in,out] | report | Where to report error. |
Implements ts::Socket.
|
overridevirtualinherited |
Close the socket.
[in,out] | report | Where to report error. |
Reimplemented from ts::Socket.
Reimplemented in ts::TCPServer.
|
protectedvirtualinherited |
This virtual method can be overriden by subclasses to be notified of open.
All subclasses should explicitly invoke their superclass' handlers.
[in,out] | report | Where to report error. |
|
overrideprotectedvirtualinherited |
Set an open socket descriptor from a subclass.
This method is used by a server to declare that a client socket has just become opened.
[in] | sock | New socket descriptor. |
[in,out] | report | Where to report error. |
Reimplemented from ts::Socket.
|
inlineinherited |
Check if socket is open.
|
inlineinherited |
Get the IP generation with which the socket was open.
|
inherited |
Set the send buffer size.
[in] | size | Send buffer size in bytes. |
[in,out] | report | Where to report error. |
|
inherited |
Set the receive buffer size.
[in] | size | Receive buffer size in bytes. |
[in,out] | report | Where to report error. |
|
inherited |
Set the receive timeout.
[in] | timeout | Receive timeout in milliseconds. If negative, receive timeout is not used. |
[in,out] | report | Where to report error. |
|
inherited |
Set the "reuse port" option.
[in] | reuse_port | If true, the socket is allowed to reuse a local UDP port which is already bound. |
[in,out] | report | Where to report error. |
|
inherited |
Get local socket address.
[out] | addr | Local socket address of the connection. |
[in,out] | report | Where to report error. |
|
inlineinherited |
Get the underlying socket device handle (use with care).
This method is reserved for low-level operations and should not be used by normal applications.
Convert an IP address to make it compatible with the socket IP generation.
addr | [in,out] The address to convert. | |
[in,out] | report | Where to report error. |
|
inherited |
Set maximum severity level.
Messages with higher severities are not reported.
[in] | level | Set report to that level. |
|
inherited |
Raise maximum severity level.
The severity can only be increased (more verbose, more debug), never decreased.
[in] | level | Set report at least to that level. |
|
inlineinherited |
Get maximum severity level.
|
inlineinherited |
Check if errors (or worse) were reported through this object.
Errors which were reported through delegated reports are ignored.
|
inlineinherited |
Reset the error indicator.
|
inlineinherited |
Set the prefix to display before each message.
[in] | prefix | The prefix to prepend to all messages. |
|
inlineinherited |
Get the current prefix to display.
Delegate message logging to another report object.
[in] | report | New report object to which messages are delegated. Use nullptr to remove the delegation and return to normal logging. |
|
inlineinherited |
Check if debugging is active.
|
inlineinherited |
Report a debug message.
[in] | msg | Message line. |
|
inlineinherited |
Report a debug message.
[in] | msg | Message line. |
|
inlineinherited |
Report a debug message with a printf-like interface.
[in] | fmt | Format string with embedded '%' sequences. |
[in] | args | List of arguments to substitute in the format string. |
|
inlineinherited |
Report a debug message with a printf-like interface.
[in] | fmt | Format string with embedded '%' sequences. |
[in] | args | List of arguments to substitute in the format string. |
|
inlineinherited |
Check if verbose reporting is active.
|
inlineinherited |
Report a verbose message.
[in] | msg | Message line. |
|
inlineinherited |
Report a verbose message.
[in] | msg | Message line. |
|
inlineinherited |
Report a verbose message with a printf-like interface.
[in] | fmt | Format string with embedded '%' sequences. |
[in] | args | List of arguments to substitute in the format string. |
|
inlineinherited |
Report a verbose message with a printf-like interface.
[in] | fmt | Format string with embedded '%' sequences. |
[in] | args | List of arguments to substitute in the format string. |
|
inherited |
Report a message with an explicit severity.
[in] | severity | Message severity. |
[in] | msg | Message line. |
|
inlineinherited |
Report a message with an explicit severity and a printf-like interface.
[in] | severity | Message severity. |
[in] | fmt | Format string with embedded '%' sequences. |
[in] | args | List of arguments to substitute in the format string. |
|
inlineinherited |
Report a message with an explicit severity and a printf-like interface.
[in] | severity | Message severity. |
[in] | fmt | Format string with embedded '%' sequences. |
[in] | args | List of arguments to substitute in the format string. |
|
inlineinherited |
Report a fatal error message.
[in] | msg | Message line. |
|
inlineinherited |
Report a fatal error message.
[in] | msg | Message line. |
|
inlineinherited |
Report a fatal error message with a printf-like interface.
[in] | fmt | Format string with embedded '%' sequences. |
[in] | args | List of arguments to substitute in the format string. |
|
inlineinherited |
Report a fatal error message with a printf-like interface.
[in] | fmt | Format string with embedded '%' sequences. |
[in] | args | List of arguments to substitute in the format string. |
|
inlineinherited |
Report a severe error message.
[in] | msg | Message line. |
|
inlineinherited |
Report a severe error message.
[in] | msg | Message line. |
|
inlineinherited |
Report a severe error message with a printf-like interface.
[in] | fmt | Format string with embedded '%' sequences. |
[in] | args | List of arguments to substitute in the format string. |
|
inlineinherited |
Report a severe error message with a printf-like interface.
[in] | fmt | Format string with embedded '%' sequences. |
[in] | args | List of arguments to substitute in the format string. |
|
inlineinherited |
Report an error message.
[in] | msg | Message line. |
|
inlineinherited |
Report an error message.
[in] | msg | Message line. |
|
inlineinherited |
Report an error message with a printf-like interface.
[in] | fmt | Format string with embedded '%' sequences. |
[in] | args | List of arguments to substitute in the format string. |
|
inlineinherited |
Report an error message with a printf-like interface.
[in] | fmt | Format string with embedded '%' sequences. |
[in] | args | List of arguments to substitute in the format string. |
|
inlineinherited |
Report a warning error message.
[in] | msg | Message line. |
|
inlineinherited |
Report a warning error message.
[in] | msg | Message line. |
|
inlineinherited |
Report a warning message with a printf-like interface.
[in] | fmt | Format string with embedded '%' sequences. |
[in] | args | List of arguments to substitute in the format string. |
|
inlineinherited |
Report a warning message with a printf-like interface.
[in] | fmt | Format string with embedded '%' sequences. |
[in] | args | List of arguments to substitute in the format string. |
|
inlineinherited |
Report an informational message.
[in] | msg | Message line. |
|
inlineinherited |
Report an informational message.
[in] | msg | Message line. |
|
inlineinherited |
Report an informational message with a printf-like interface.
[in] | fmt | Format string with embedded '%' sequences. |
[in] | args | List of arguments to substitute in the format string. |
|
inlineinherited |
Report an informational message with a printf-like interface.
[in] | fmt | Format string with embedded '%' sequences. |
[in] | args | List of arguments to substitute in the format string. |