19 #include "uuid/telnet.h"
22 #ifdef ARDUINO_ARCH_ESP8266
23 # include <ESP8266WiFi.h>
34 #include <uuid/common.h>
37 #ifndef UUID_TELNET_HAVE_WIFICLIENT_REMOTE
38 # if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
39 # define UUID_TELNET_HAVE_WIFICLIENT_REMOTE 1
41 # define UUID_TELNET_HAVE_WIFICLIENT_REMOTE 0
45 #ifndef UUID_TELNET_HAVE_WIFICLIENT_NODELAY
46 # if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
47 # define UUID_TELNET_HAVE_WIFICLIENT_NODELAY 1
49 # define UUID_TELNET_HAVE_WIFICLIENT_NODELAY 0
53 #ifndef UUID_TELNET_HAVE_WIFICLIENT_KEEPALIVE
54 # if defined(ARDUINO_ARCH_ESP8266)
55 # define UUID_TELNET_HAVE_WIFICLIENT_KEEPALIVE 1
57 # define UUID_TELNET_HAVE_WIFICLIENT_KEEPALIVE 0
65 static const char __pstr__logger_name[] __attribute__((__aligned__(PSTR_ALIGN))) PROGMEM =
"telnet";
80 [commands, context, flags] (Stream &stream, const IPAddress &addr __attribute__((unused)), uint16_t port __attribute__((unused))) -> std::shared_ptr<
uuid::console::Shell> {
81 return std::make_shared<uuid::console::Shell>(stream, commands, context, flags);
92 : server_(port), shell_factory_(shell_factory) {
155 WiFiClient client =
server_.available();
158 #if UUID_TELNET_HAVE_WIFICLIENT_REMOTE
161 logger_.
info(F(
"New connection rejected (connection limit reached)"));
163 client.println(F(
"Maximum connection limit reached."));
166 #if UUID_TELNET_HAVE_WIFICLIENT_REMOTE
170 #if !(UUID_TELNET_HAVE_WIFICLIENT_REMOTE)
178 : client_(std::move(client)), stream_(client_) {
179 #if UUID_TELNET_HAVE_WIFICLIENT_REMOTE
187 #if UUID_TELNET_HAVE_WIFICLIENT_NODELAY
191 #if UUID_TELNET_HAVE_WIFICLIENT_KEEPALIVE
196 if (write_timeout > 0) {
197 client_.setTimeout(write_timeout);
203 std::shared_ptr<uuid::console::Shell> shell = shell_factory(
stream_,
addr_,
port_);
211 if (!shell_.expired()) {
212 if (!client_.connected()) {
213 auto shell = shell_.lock();
221 #if UUID_TELNET_HAVE_WIFICLIENT_REMOTE
231 auto shell = shell_.lock();
unsigned long initial_idle_timeout() const
Get the initial idle timeout for new connections.
Logger instance used to make log messages.
TelnetService(std::shared_ptr< uuid::console::Commands > commands, unsigned int context=0, unsigned int flags=0)
Create a new telnet service listening on the default port.
static uuid::log::Logger logger_
void close_all()
Close all connections.
void stop()
Stop listening for connections.
void start()
Start listening for connections on the configured port.
unsigned long initial_idle_timeout_
unsigned long default_write_timeout() const
Get the default socket write timeout for new connections.
void info(const char *format,...) const
Log a message at level Level::INFO.
size_t maximum_connections_
Provides access to a console shell as a telnet server.
std::list< Connection > connections_
size_t maximum_connections() const
Get the maximum number of concurrent open connections.
std::string printable_to_string(const Printable &printable)
Create a std::string from a Printable object.
unsigned long write_timeout_
std::function< std::shared_ptr< uuid::console::Shell >(Stream &stream, const IPAddress &addr, uint16_t port)> shell_factory_function
Function to handle the creation of a shell.
bool stop()
Stop the shell.
shell_factory_function shell_factory_
void start()
Perform startup process for this shell.
unsigned long idle_timeout() const
Get the idle timeout.
std::weak_ptr< uuid::console::Shell > shell_
void start()
Perform initial negotiation.
Connection(shell_factory_function &shell_factory, WiFiClient &&client, unsigned long idle_timeout, unsigned long write_timeout)
Create a telnet connection shell.
void loop()
Accept new connections.
bool loop()
Stop the shell if the client is not connected.