Indy 9
|
TSlaveThread = class(TIdThread)
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.
property Connection: TIdTCPClient;
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.
property Executed: Boolean;
constructor Create(Slave: TIdTunnelSlave); reintroduce;
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:
Create relies in the inherited Create constructor to initialize the thread in a suspended state.
destructor Destroy; override;
Destroy relies on the inherited Destroy method to complete destruction of the thread instance.
procedure Execute; override;
procedure Run; override;
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.