KanoopCommonQt 2.1.1
Kanoop foundational Qt utility library
Loading...
Searching...
No Matches
TcpServerClientObject Class Referenceabstract

Manages the lifetime of a single accepted TCP (or SSL/TLS) client socket. More...

#include <tcpserverclientobject.h>

+ Inheritance diagram for TcpServerClientObject:
+ Collaboration diagram for TcpServerClientObject:

Public Member Functions

virtual ~TcpServerClientObject ()
 Destructor — disconnects and cleans up the socket.
 
void writeData (const QByteArray &data)
 Send data to the connected client.
 
- Public Member Functions inherited from AbstractThreadClass
 AbstractThreadClass (const Log::LogCategory &category=Log::LogCategory(), QObject *parent=nullptr)
 Construct with an optional log category and parent.
 
 AbstractThreadClass (const QString &category, QObject *parent=nullptr)
 Construct with a category name string and optional parent.
 
virtual ~AbstractThreadClass ()
 Destructor — stops the thread if still running.
 
virtual bool start (const TimeSpan &timeout=TimeSpan::zero())
 Start the worker thread and optionally wait for it to signal readiness.
 
virtual bool stop (const TimeSpan &timeout=TimeSpan::zero())
 Request the worker thread to stop and optionally wait for it to finish.
 
virtual void abort ()
 Immediately interrupt the worker thread (sets the stopping flag).
 
bool waitForCompletion (const TimeSpan &timeout=TimeSpan::zero())
 Block until the worker thread finishes or the timeout elapses.
 
bool isRunning () const
 Test whether the worker thread is currently running.
 
bool isStopping () const
 Test whether stop() has been called and the thread is winding down.
 
bool success () const
 Return whether the last run completed successfully.
 
QString completionMessage () const
 Return the completion message set by finishAndStop().
 
void setBlockingStart (bool value)
 Control whether start() blocks until the thread signals readiness.
 
- Public Member Functions inherited from LoggingBaseClass
 LoggingBaseClass (const Log::LogCategory &category=Log::LogCategory())
 Construct with an optional log category.
 
 LoggingBaseClass (const QString &category)
 Construct with a category name string.
 
Log::LogCategory logCategory () const
 Return the base log category.
 

Protected Member Functions

 TcpServerClientObject (TcpServer *server, qintptr fd, bool useSsl=false)
 Construct a client object for an accepted connection.
 
virtual void clientStarted ()
 Called on the client thread immediately after the connection is established.
 
virtual void clientFinished ()
 Called on the client thread just before the connection is torn down.
 
virtual void receivedData (const QByteArray &data)=0
 Called whenever data arrives from the client.
 
QTcpSocket * socket () const
 Return the underlying socket for this client.
 
TcpServerserver () const
 Return the owning TcpServer.
 
- Protected Member Functions inherited from AbstractThreadClass
bool waitForStart (const TimeSpan &timeout)
 Block until the thread has entered threadStarted() or the timeout elapses.
 
void finishAndStop (bool success, const QString &message=QString())
 Signal that the worker has finished, recording success and a message.
 
void writeLine (const QString &line)
 Write a line to the standard output stream.
 
void writeErrorLine (const QString &line)
 Write a line to the standard error stream.
 
- Protected Member Functions inherited from LoggingBaseClass
Log::LogCategory LVL0 () const
 Return the base (level 0) log category.
 
Log::LogCategory LVL1 () const
 Return the level-1 sub-category.
 
Log::LogCategory LVL2 () const
 Return the level-2 sub-category.
 
Log::LogCategory LVL3 () const
 Return the level-3 sub-category.
 
void logText (const char *file, int lineNumber, Log::LogLevel level, const QString &text) const
 Write a text message to the system logger using the base category.
 
void logText (const char *file, int lineNumber, Log::LogLevel level, const Log::LogCategory &category, const QString &text) const
 Write a text message to the system logger using an explicit category.
 
void logHex (const char *file, int lineNumber, Log::LogLevel level, const QByteArray &data, const QString &tag=QString()) const
 Write a hex dump to the system logger.
 
void logHex (const char *file, int lineNumber, Log::LogLevel level, const Log::LogCategory &category, const QByteArray &data, const QString &tag=QString()) const
 Write a hex dump to the system logger using an explicit category.
 
void addLogConsumer (LogConsumer *consumer)
 Register an external log consumer to receive entries from this class.
 
void removeLogConsumer (LogConsumer *consumer)
 Remove a previously added log consumer.
 

Additional Inherited Members

- Signals inherited from AbstractThreadClass
void started ()
 Emitted when the worker thread has started.
 
void finished ()
 Emitted when the worker thread has finished.
 

Detailed Description

Manages the lifetime of a single accepted TCP (or SSL/TLS) client socket.

Each accepted connection is wrapped in a TcpServerClientObject running in its own thread. Subclasses must implement receivedData() to process incoming bytes, and may override clientStarted() and clientFinished() for lifecycle hooks.

Definition at line 21 of file tcpserverclientobject.h.

Constructor & Destructor Documentation

◆ TcpServerClientObject()

TcpServerClientObject::TcpServerClientObject ( TcpServer server,
qintptr  fd,
bool  useSsl = false 
)
protected

Construct a client object for an accepted connection.

Parameters
serverOwning TcpServer
fdNative socket file descriptor for the accepted connection
useSslWhether to negotiate SSL/TLS on this socket

Member Function Documentation

◆ clientFinished()

virtual void TcpServerClientObject::clientFinished ( )
inlineprotectedvirtual

Called on the client thread just before the connection is torn down.

Definition at line 47 of file tcpserverclientobject.h.

◆ clientStarted()

virtual void TcpServerClientObject::clientStarted ( )
inlineprotectedvirtual

Called on the client thread immediately after the connection is established.

Definition at line 44 of file tcpserverclientobject.h.

◆ receivedData()

virtual void TcpServerClientObject::receivedData ( const QByteArray &  data)
protectedpure virtual

Called whenever data arrives from the client.

Parameters
dataReceived bytes

◆ server()

TcpServer * TcpServerClientObject::server ( ) const
inlineprotected

Return the owning TcpServer.

Returns
Pointer to the parent TcpServer

Definition at line 65 of file tcpserverclientobject.h.

◆ socket()

QTcpSocket * TcpServerClientObject::socket ( ) const
inlineprotected

Return the underlying socket for this client.

Returns
Pointer to the QTcpSocket (may also be a QSslSocket in SSL mode)

Definition at line 59 of file tcpserverclientobject.h.

◆ writeData()

void TcpServerClientObject::writeData ( const QByteArray &  data)

Send data to the connected client.

Parameters
dataBytes to transmit

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