Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
uuid::telnet::TelnetStream Class Reference

Stream wrapper that performs telnet protocol handling, option negotiation and output buffering. More...

#include <uuid/telnet.h>

Inheritance diagram for uuid::telnet::TelnetStream:
Inheritance graph
[legend]
Collaboration diagram for uuid::telnet::TelnetStream:
Collaboration graph
[legend]

Public Member Functions

 TelnetStream (WiFiClient &client)
 Create a new telnet stream wrapper. More...
 
void start ()
 Perform initial negotiation. More...
 
int available () override
 Check for available input. More...
 
int read () override
 Read one byte from the available input. More...
 
int peek () override
 Read one byte from the available input without advancing to the next one. More...
 
size_t write (uint8_t data) override
 Write one byte to the output stream. More...
 
size_t write (const uint8_t *buffer, size_t size) override
 Write an array of bytes to the output stream. More...
 
void flush () override
 Does nothing. More...
 

Private Member Functions

 TelnetStream (const TelnetStream &)=delete
 
TelnetStreamoperator= (const TelnetStream &)=delete
 
int raw_available ()
 Directly check for available input. More...
 
int raw_read ()
 Read one byte directly from the available input. More...
 
void buffer_flush ()
 Flush output stream buffer. More...
 
size_t raw_write (unsigned char data)
 Write one byte directly to the output stream. More...
 
size_t raw_write (const std::vector< unsigned char > &data)
 Write a vector of bytes directly to the output stream. More...
 
size_t raw_write (const uint8_t *buffer, size_t size)
 Write an array of bytes directly to the output stream. More...
 

Private Attributes

WiFiClient & client_
 
unsigned char previous_raw_in_ = 0
 
bool sub_negotiation_ = false
 
unsigned char previous_in_ = 0
 
unsigned char previous_out_ = 0
 
int peek_ = -1
 
std::vector< char > output_buffer_
 

Static Private Attributes

static constexpr const unsigned char NUL = 0
 
static constexpr const unsigned char BEL = 7
 
static constexpr const unsigned char BS = 8
 
static constexpr const unsigned char HT = 9
 
static constexpr const unsigned char LF = 10
 
static constexpr const unsigned char VT = 11
 
static constexpr const unsigned char FF = 12
 
static constexpr const unsigned char CR = 13
 
static constexpr const unsigned char SE = 240
 
static constexpr const unsigned char NOP = 241
 
static constexpr const unsigned char DM = 242
 
static constexpr const unsigned char BRK = 243
 
static constexpr const unsigned char IP = 244
 
static constexpr const unsigned char AO = 245
 
static constexpr const unsigned char AYT = 246
 
static constexpr const unsigned char EC = 247
 
static constexpr const unsigned char EL = 248
 
static constexpr const unsigned char GA = 249
 
static constexpr const unsigned char SB = 250
 
static constexpr const unsigned char WILL = 251
 
static constexpr const unsigned char WONT = 252
 
static constexpr const unsigned char DO = 253
 
static constexpr const unsigned char DONT = 254
 
static constexpr const unsigned char IAC = 255
 
static constexpr const unsigned char OPT_BINARY = 0
 
static constexpr const unsigned char OPT_ECHO = 1
 
static constexpr const unsigned char OPT_SGA = 3
 
static constexpr const size_t BUFFER_SIZE = 536
 

Detailed Description

Stream wrapper that performs telnet protocol handling, option negotiation and output buffering.

Since
0.1.0

Definition at line 54 of file telnet.h.

Constructor & Destructor Documentation

◆ TelnetStream()

uuid::telnet::TelnetStream::TelnetStream ( WiFiClient &  client)
explicit

Create a new telnet stream wrapper.

Parameters
[in]clientClient connection.
Since
0.1.0

Definition at line 31 of file stream.cpp.

Member Function Documentation

◆ available()

int uuid::telnet::TelnetStream::available ( )
override

Check for available input.

Returns
The number of bytes available to read.
Since
0.1.0

Definition at line 47 of file stream.cpp.

◆ buffer_flush()

void uuid::telnet::TelnetStream::buffer_flush ( )
private

Flush output stream buffer.

Disconnect the client if the socket buffer is full.

Since
0.1.0

Definition at line 299 of file stream.cpp.

◆ flush()

void uuid::telnet::TelnetStream::flush ( )
override

Does nothing.

This is a pure virtual function in Arduino's Stream class, which makes no sense because that class is for input and this is an output function. Later versions move it to Print as an empty virtual function so this is here for backward compatibility.

Since
0.1.0

Definition at line 284 of file stream.cpp.

◆ peek()

int uuid::telnet::TelnetStream::peek ( )
override

Read one byte from the available input without advancing to the next one.

Returns
An unsigned char if input is available, otherwise -1.
Since
0.1.0

Definition at line 221 of file stream.cpp.

◆ raw_available()

int uuid::telnet::TelnetStream::raw_available ( )
private

Directly check for available input.

Returns
The number of bytes available to read.
Since
0.1.0

Definition at line 291 of file stream.cpp.

◆ raw_read()

int uuid::telnet::TelnetStream::raw_read ( )
private

Read one byte directly from the available input.

Returns
An unsigned char if input is available, otherwise -1.
Since
0.1.0

Definition at line 295 of file stream.cpp.

◆ raw_write() [1/3]

size_t uuid::telnet::TelnetStream::raw_write ( unsigned char  data)
private

Write one byte directly to the output stream.

Disconnect the client if the socket buffer is full.

Parameters
[in]dataData to be output.
Returns
The number of bytes that were output.
Since
0.1.0

Definition at line 310 of file stream.cpp.

◆ raw_write() [2/3]

size_t uuid::telnet::TelnetStream::raw_write ( const std::vector< unsigned char > &  data)
private

Write a vector of bytes directly to the output stream.

Disconnect the client if the socket buffer is full.

Parameters
[in]dataData to be output.
Returns
The number of bytes that were output.
Since
0.1.0

Definition at line 320 of file stream.cpp.

◆ raw_write() [3/3]

size_t uuid::telnet::TelnetStream::raw_write ( const uint8_t *  buffer,
size_t  size 
)
private

Write an array of bytes directly to the output stream.

Disconnect the client if the socket buffer is full.

Parameters
[in]bufferBuffer to be output.
[in]sizeLength of the buffer.
Returns
The number of bytes that were output.
Since
0.1.0

Definition at line 324 of file stream.cpp.

◆ read()

int uuid::telnet::TelnetStream::read ( )
override

Read one byte from the available input.

Returns
An unsigned char if input is available, otherwise -1.
Since
0.1.0

Definition at line 55 of file stream.cpp.

◆ start()

void uuid::telnet::TelnetStream::start ( )

Perform initial negotiation.

Since
0.1.0

Definition at line 36 of file stream.cpp.

◆ write() [1/2]

size_t uuid::telnet::TelnetStream::write ( uint8_t  data)
override

Write one byte to the output stream.

Disconnect the client if the socket buffer is full.

Parameters
[in]dataData to be output.
Returns
The number of bytes that were output.
Since
0.1.0

Definition at line 234 of file stream.cpp.

◆ write() [2/2]

size_t uuid::telnet::TelnetStream::write ( const uint8_t *  buffer,
size_t  size 
)
override

Write an array of bytes to the output stream.

Disconnect the client if the socket buffer is full.

Parameters
[in]bufferBuffer to be output.
[in]sizeLength of the buffer.
Returns
The number of bytes that were output.
Since
0.1.0

Definition at line 258 of file stream.cpp.

Member Data Documentation

◆ AO

constexpr const unsigned char uuid::telnet::TelnetStream::AO = 245
staticprivate

Abort Output function.

Since
0.1.0

Definition at line 141 of file telnet.h.

◆ AYT

constexpr const unsigned char uuid::telnet::TelnetStream::AYT = 246
staticprivate

Are You There function.

Since
0.1.0

Definition at line 142 of file telnet.h.

◆ BEL

constexpr const unsigned char uuid::telnet::TelnetStream::BEL = 7
staticprivate

Produces an audible or visible signal.

Since
0.1.0

Definition at line 129 of file telnet.h.

◆ BRK

constexpr const unsigned char uuid::telnet::TelnetStream::BRK = 243
staticprivate

NVT character BRK.

Since
0.1.0

Definition at line 139 of file telnet.h.

◆ BS

constexpr const unsigned char uuid::telnet::TelnetStream::BS = 8
staticprivate

Moves the print head one character position towards the left margin.

Since
0.1.0

Definition at line 130 of file telnet.h.

◆ BUFFER_SIZE

constexpr const size_t uuid::telnet::TelnetStream::BUFFER_SIZE = 536
staticprivate

Output buffer size.

Since
0.1.0

Definition at line 157 of file telnet.h.

◆ client_

WiFiClient& uuid::telnet::TelnetStream::client_
private

Client connection.

Since
0.1.0

Definition at line 216 of file telnet.h.

◆ CR

constexpr const unsigned char uuid::telnet::TelnetStream::CR = 13
staticprivate

Carriage Return.

Since
0.1.0

Definition at line 135 of file telnet.h.

◆ DM

constexpr const unsigned char uuid::telnet::TelnetStream::DM = 242
staticprivate

The data stream portion of a Synch.

Since
0.1.0

Definition at line 138 of file telnet.h.

◆ DO

constexpr const unsigned char uuid::telnet::TelnetStream::DO = 253
staticprivate

Indicates the request that the other party perform, or confirmation that you are expecting the other party to perform, the indicated option.

Since
0.1.0

Definition at line 149 of file telnet.h.

◆ DONT

constexpr const unsigned char uuid::telnet::TelnetStream::DONT = 254
staticprivate

Indicates the demand that the other party stop performing, or confirmation that you are no longer expecting the other party to perform, the indicated option.

Since
0.1.0

Definition at line 150 of file telnet.h.

◆ EC

constexpr const unsigned char uuid::telnet::TelnetStream::EC = 247
staticprivate

Erase Character function.

Since
0.1.0

Definition at line 143 of file telnet.h.

◆ EL

constexpr const unsigned char uuid::telnet::TelnetStream::EL = 248
staticprivate

Erase Line function.

Since
0.1.0

Definition at line 144 of file telnet.h.

◆ FF

constexpr const unsigned char uuid::telnet::TelnetStream::FF = 12
staticprivate

Moves the printer to the top of the next page, keeping the same horizontal position.

Since
0.1.0

Definition at line 134 of file telnet.h.

◆ GA

constexpr const unsigned char uuid::telnet::TelnetStream::GA = 249
staticprivate

Go Ahead signal.

Since
0.1.0

Definition at line 145 of file telnet.h.

◆ HT

constexpr const unsigned char uuid::telnet::TelnetStream::HT = 9
staticprivate

Moves the printer to the next horizontal tab stop.

Since
0.1.0

Definition at line 131 of file telnet.h.

◆ IAC

constexpr const unsigned char uuid::telnet::TelnetStream::IAC = 255
staticprivate

Interpret As Command escape character.

Since
0.1.0

Definition at line 151 of file telnet.h.

◆ IP

constexpr const unsigned char uuid::telnet::TelnetStream::IP = 244
staticprivate

Interrupt Process function.

Since
0.1.0

Definition at line 140 of file telnet.h.

◆ LF

constexpr const unsigned char uuid::telnet::TelnetStream::LF = 10
staticprivate

Line Feed.

Since
0.1.0

Definition at line 132 of file telnet.h.

◆ NOP

constexpr const unsigned char uuid::telnet::TelnetStream::NOP = 241
staticprivate

No operation.

Since
0.1.0

Definition at line 137 of file telnet.h.

◆ NUL

constexpr const unsigned char uuid::telnet::TelnetStream::NUL = 0
staticprivate

No operation.

Since
0.1.0

Definition at line 128 of file telnet.h.

◆ OPT_BINARY

constexpr const unsigned char uuid::telnet::TelnetStream::OPT_BINARY = 0
staticprivate

Binary (8-bit) transmission mode. (RFC 856).

Since
0.1.0

Definition at line 153 of file telnet.h.

◆ OPT_ECHO

constexpr const unsigned char uuid::telnet::TelnetStream::OPT_ECHO = 1
staticprivate

Remote Echo (RFC 857).

Since
0.1.0

Definition at line 154 of file telnet.h.

◆ OPT_SGA

constexpr const unsigned char uuid::telnet::TelnetStream::OPT_SGA = 3
staticprivate

Suppress Go Ahead (RFC 858).

Since
0.1.0

Definition at line 155 of file telnet.h.

◆ output_buffer_

std::vector<char> uuid::telnet::TelnetStream::output_buffer_
private

Buffer data to be output until a read function is called.

Since
0.1.0

Definition at line 222 of file telnet.h.

◆ peek_

int uuid::telnet::TelnetStream::peek_ = -1
private

Previously read data cached by peek().

Since
0.1.0

Definition at line 221 of file telnet.h.

◆ previous_in_

unsigned char uuid::telnet::TelnetStream::previous_in_ = 0
private

Previous character that was received. Used to detect CR NUL.

Since
0.1.0

Definition at line 219 of file telnet.h.

◆ previous_out_

unsigned char uuid::telnet::TelnetStream::previous_out_ = 0
private

Previous character that was sent. Used to insert NUL after CR without LF.

Since
0.1.0

Definition at line 220 of file telnet.h.

◆ previous_raw_in_

unsigned char uuid::telnet::TelnetStream::previous_raw_in_ = 0
private

Previous raw character that was received. Used to detect commands.

Since
0.1.0

Definition at line 217 of file telnet.h.

◆ SB

constexpr const unsigned char uuid::telnet::TelnetStream::SB = 250
staticprivate

Sub-negotiation of the indicated option.

Since
0.1.0

Definition at line 146 of file telnet.h.

◆ SE

constexpr const unsigned char uuid::telnet::TelnetStream::SE = 240
staticprivate

End of sub-negotiation parameters.

Since
0.1.0

Definition at line 136 of file telnet.h.

◆ sub_negotiation_

bool uuid::telnet::TelnetStream::sub_negotiation_ = false
private

Sub-negotiation mode.

Since
0.1.0

Definition at line 218 of file telnet.h.

◆ VT

constexpr const unsigned char uuid::telnet::TelnetStream::VT = 11
staticprivate

Moves the printer to the next vertical tab stop.

Since
0.1.0

Definition at line 133 of file telnet.h.

◆ WILL

constexpr const unsigned char uuid::telnet::TelnetStream::WILL = 251
staticprivate

Indicates the desire to begin performing, or confirmation that you are now performing, the indicated option.

Since
0.1.0

Definition at line 147 of file telnet.h.

◆ WONT

constexpr const unsigned char uuid::telnet::TelnetStream::WONT = 252
staticprivate

Indicates the refusal to perform, or continue performing, the indicated option.

Since
0.1.0

Definition at line 148 of file telnet.h.


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