<commit_before>#include "listenertelnetsocket.h"

#include <QCryptographicHash>
#include <QtEndian>
#include <QJsonDocument>

#include "connectionmanager.h"
#include "listenerserver.h"
#include "objectmanager.h"

//#define DEBUG_LISTENER

#define TELNET_TELOPT_GMCP (0xc9)

ListenerTelnetSocket::ListenerTelnetSocket( QObject *pParent, QTcpSocket *pSocket ) :
	ListenerSocket( pParent ), mSocket( pSocket ), mCursorPosition( 0 ), mTelnet( nullptr ), mLineMode( Connection::EDIT )
{
	mDataReceived    = false;
	mWebSocketHeader = false;
	mWebSocketActive = false;

	mLastChar  = 0;
	mLocalEcho = false;

	qDebug() << "Connection established from" << mSocket->peerAddress();

	mConnectionId = ConnectionManager::instance()->doConnect( reinterpret_cast<ListenerServer *>( parent() )->objectid() );

	Connection		*CON = ConnectionManager::instance()->connection( mConnectionId );

	connect( this, &ListenerTelnetSocket::textOutput, CON, &Connection::dataInput );
	connect( CON, &Connection::textOutput, this, &ListenerTelnetSocket::textInput );

	connect( CON, &Connection::taskOutput, ObjectManager::instance(), &ObjectManager::doTask );

	connect( CON, &Connection::lineModeChanged, this, &ListenerTelnetSocket::setLineMode );
	connect( this, &ListenerTelnetSocket::lineModeSupported, CON, &Connection::setLineModeSupport );

	connect( mSocket, &QTcpSocket::disconnected, this, &ListenerTelnetSocket::disconnected );
	connect( mSocket, &QTcpSocket::readyRead, this, &ListenerTelnetSocket::readyRead );

	connect( CON, &Connection::gmcpOutput, this, &ListenerTelnetSocket::sendGMCP );

	connect( &mTimer, &QTimer::timeout, this, &ListenerTelnetSocket::inputTimeout );

	mTimer.singleShot( 1000, this, SLOT(inputTimeout()) );

	mTelnet = telnet_init( mOptions.constData(), &ListenerTelnetSocket::telnetEventHandlerStatic, 0, this );
}

bool ListenerTelnetSocket::echo() const
{
	return( mLocalEcho );
}

void ListenerTelnetSocket::sendData( const QByteArray &pData )
{
#if defined( DEBUG_LISTENER )
	qDebug() << "ListenerTelnetSocket::sendData" << pData;
#endif

	telnet_send( mTelnet, pData.constData(), pData.size() );
}
<commit_msg>Reduced initial telnet delay<commit_after>#include "listenertelnetsocket.h"

#include <QCryptographicHash>
#include <QtEndian>
#include <QJsonDocument>

#include "connectionmanager.h"
#include "listenerserver.h"
#include "objectmanager.h"

//#define DEBUG_LISTENER

#define TELNET_TELOPT_GMCP (0xc9)

ListenerTelnetSocket::ListenerTelnetSocket( QObject *pParent, QTcpSocket *pSocket ) :
	ListenerSocket( pParent ), mSocket( pSocket ), mCursorPosition( 0 ), mTelnet( nullptr ), mLineMode( Connection::EDIT )
{
	mDataReceived    = false;
	mWebSocketHeader = false;
	mWebSocketActive = false;

	mLastChar  = 0;
	mLocalEcho = false;

	qDebug() << "Connection established from" << mSocket->peerAddress();

	mConnectionId = ConnectionManager::instance()->doConnect( reinterpret_cast<ListenerServer *>( parent() )->objectid() );

	Connection		*CON = ConnectionManager::instance()->connection( mConnectionId );

	connect( this, &ListenerTelnetSocket::textOutput, CON, &Connection::dataInput );
	connect( CON, &Connection::textOutput, this, &ListenerTelnetSocket::textInput );

	connect( CON, &Connection::taskOutput, ObjectManager::instance(), &ObjectManager::doTask );

	connect( CON, &Connection::lineModeChanged, this, &ListenerTelnetSocket::setLineMode );
	connect( this, &ListenerTelnetSocket::lineModeSupported, CON, &Connection::setLineModeSupport );

	connect( mSocket, &QTcpSocket::disconnected, this, &ListenerTelnetSocket::disconnected );
	connect( mSocket, &QTcpSocket::readyRead, this, &ListenerTelnetSocket::readyRead );

	connect( CON, &Connection::gmcpOutput, this, &ListenerTelnetSocket::sendGMCP );

	connect( &mTimer, &QTimer::timeout, this, &ListenerTelnetSocket::inputTimeout );

	mTimer.singleShot( 500, this, SLOT(inputTimeout()) );

	mTelnet = telnet_init( mOptions.constData(), &ListenerTelnetSocket::telnetEventHandlerStatic, 0, this );
}

bool ListenerTelnetSocket::echo() const
{
	return( mLocalEcho );
}

void ListenerTelnetSocket::sendData( const QByteArray &pData )
{
#if defined( DEBUG_LISTENER )
	qDebug() << "ListenerTelnetSocket::sendData" << pData;
#endif

	telnet_send( mTelnet, pData.constData(), pData.size() );
}

{'fraction_non_alphanumeric': 0.13704396632366697, 'fraction_numerical': 0.003975678203928906, 'mean_word_length': 7.873443983402489, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7538871', 'n_tokens_mistral': 1417, 'n_tokens_neox': 1325, 'n_words': 271}