|
@ -25,6 +25,56 @@ Updated to use WiFiServer and support reverse connections by Niek van der Maas < |
|
|
#include "board.h"
|
|
|
#include "board.h"
|
|
|
#include "ws.h"
|
|
|
#include "ws.h"
|
|
|
|
|
|
|
|
|
|
|
|
#if TELNET_SERVER == TELNET_SERVER_ASYNC
|
|
|
|
|
|
|
|
|
|
|
|
#include <ESPAsyncTCP.h>
|
|
|
|
|
|
|
|
|
|
|
|
struct AsyncBufferedClient { |
|
|
|
|
|
public: |
|
|
|
|
|
constexpr static const size_t BUFFERS_MAX = 5; |
|
|
|
|
|
using buffer_t = std::vector<uint8_t>; |
|
|
|
|
|
|
|
|
|
|
|
AsyncBufferedClient(AsyncClient* client); |
|
|
|
|
|
|
|
|
|
|
|
size_t write(char c); |
|
|
|
|
|
size_t write(const char* data, size_t size=0); |
|
|
|
|
|
|
|
|
|
|
|
void flush(); |
|
|
|
|
|
size_t available(); |
|
|
|
|
|
|
|
|
|
|
|
bool connect(const char *host, uint16_t port); |
|
|
|
|
|
void close(bool now = false); |
|
|
|
|
|
bool connected(); |
|
|
|
|
|
|
|
|
|
|
|
private: |
|
|
|
|
|
void _addBuffer(); |
|
|
|
|
|
|
|
|
|
|
|
static void _trySend(AsyncBufferedClient* client); |
|
|
|
|
|
static void _s_onAck(void* client_ptr, AsyncClient*, size_t, uint32_t); |
|
|
|
|
|
static void _s_onPoll(void* client_ptr, AsyncClient* client); |
|
|
|
|
|
|
|
|
|
|
|
std::unique_ptr<AsyncClient> _client; |
|
|
|
|
|
std::list<buffer_t> _buffers; |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
using TTelnetServer = AsyncServer; |
|
|
|
|
|
|
|
|
|
|
|
#if TELNET_SERVER_ASYNC_BUFFERED
|
|
|
|
|
|
using TTelnetClient = AsyncBufferedClient; |
|
|
|
|
|
#else
|
|
|
|
|
|
using TTelnetClient = AsyncClient; |
|
|
|
|
|
#endif // TELNET_SERVER_ASYNC_BUFFERED
|
|
|
|
|
|
|
|
|
|
|
|
#elif TELNET_SERVER == TELNET_SERVER_WIFISERVER
|
|
|
|
|
|
|
|
|
|
|
|
using TTelnetServer = WiFiServer; |
|
|
|
|
|
using TTelnetClient = WiFiClient; |
|
|
|
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
#error "TELNET_SERVER value was not properly set"
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TTelnetServer _telnetServer(TELNET_PORT); |
|
|
TTelnetServer _telnetServer(TELNET_PORT); |
|
|
std::unique_ptr<TTelnetClient> _telnetClients[TELNET_MAX_CLIENTS]; |
|
|
std::unique_ptr<TTelnetClient> _telnetClients[TELNET_MAX_CLIENTS]; |
|
|
|
|
|
|
|
|