Indy 9
TSlaveThread
Hierarchy, Properties, Methods, Events, See Also, Unit: IdTunnelSlave
Implements a listening thread for communication with the tunnel master server.
TSlaveThread = class(TIdThread)
Unit
IdTunnelSlave
Description
TSlaveThread is a TIdThread descendant that implements a listening thread for the TIdTunnelSlave server.

TSlaveThread overrides the BeforeRun, AfterRun, Run, and Execute virtual methods, inherited from TIdPeerThread, that provide the Indy thread execution framework.

TSlaveThread keeps a reference, in SlaveParent, to the TIdTunnelSlave that owns the listening thread. SlaveParent provides the server context for accessing properties and method of the TIdTunnelSlave from the listening thread.

TSlaveThread keeps a reference to the TIdTCPClient connection that represents the tunnelled link to the TIdTunnelServer. The tunnel connection is established in the constructor for TSlaveThread, closed in Run, and Disconnected in the destructor.

When the TSlaveThread is executed in Run, it insures that the tunnel connection to the TIdTunnelMaster is active and ready to accept read and write operations. If an exception occurs, the connection is closed and the thread will terminate. If the exception is not EIdSocketError or EIdSocketClosed, the exception will be raised for the application.

TSlaveThread arbitrates data transformation for messages from the tunnel master server, as well as session connection and disconnection for client messages.


TSlaveThread.Connection
TSlaveThread
Represents the client connection to the tunnel master server.
property Connection: TIdTCPClient;
Description
Connection is a read-only TIdTCPClient property that represents the client connection to a tunnel master server for the TIdTunnelSlave services by the thread.

Connection is used to gain access to the read buffer for the TCP connection while the slave thread is executing, and passes the read buffer as data for the Receiver.


TSlaveThread.Executed
TSlaveThread, See Also
Indicates that the thread has been Run using the Indy thread framework.
property Executed: Boolean;
Description
Executed is a Boolean property that indicates the thread has been Run using the Indy thread framework. Executed is updated from Execute at the completion of the Run method.

TSlaveThread.Create
TSlaveThread
Constructor for the object instance.
constructor Create(Slave: TIdTunnelSlave); reintroduce;
Parameters
Slave: TIdTunnelSlave
The TIdTunnelSlave serviced by the thread.
Description
Create is the reintroduced constructor for the object instance. Create initializes object properties that depend on the Slave parameter, including:

SlaveParent contains a reference to the Slave parameter. Connection is the internal TIdTCPClient for Slave. OnTerminate is assigned the event handler for the OnTunnelThreadTerminate event of Slave.

In addition, other thread properties are initialized to their default values, including:

  • FreeOnTerminate - False

  • Executed - False

  • StopMode - smTerminate

Create relies in the inherited Create constructor to initialize the thread in a suspended state.


TSlaveThread.Destroy
TSlaveThread
Frees the thread instance.
destructor Destroy; override;
Description
Destroy is the destructor for the thread instance. Destroy insures that Connection is disconnected and Receiver is freed prior to exiting from the method. Destroy also releases the critical section used to protect access to the Executed property.

Destroy relies on the inherited Destroy method to complete destruction of the thread instance.


TSlaveThread.Execute
TSlaveThread, See Also
Starts running the thread.
procedure Execute; override;
Description
Execute is a procedure used to activate execution of the Indy thread in the thread framework. Execute relies on the inherited Execute method to signal that the thread should Run.

Execute updates the Executed property prior to completion of the method.


TSlaveThread.Run
TSlaveThread
Provides the main thread of execution for the Indy thread framework.
procedure Run; override;
Description
Run is a procedure that provides the main thread of execution for the Indy thread framework. Run ensures that the client Connection is valid and ready to perform read operations.

Run captures incoming messages from the client connection and provide the data to Receiver for interpretation. Run remains active until the thread is terminated. When a new message is detected, Run verifies that the CRC for the message matched the CRC value in the encapsulation header. When the CRC values do not match, Run will raise an EIdException exception.

Run also allows the Slaveparent to perform data transformation using Receiver. If an error occurs during data transformation, Run will raise an EIdException exception.

Finally, Run performs the action specified in the message type header in Receiver. This action can include closing the client connection due to an error in either the data or the session, or allowing the client to receive the result of the tunnel transformation.


Created with Doc-O-Matic 2 donated to Project JEDI. Commercial license available from the Doc-O-Matic site.