FRIBParallelanalysis  1.0
FrameworkforMPIParalleldataanalysisatFRIB
Public Member Functions | Protected Member Functions | List of all members
CTCLServer Class Reference

#include <CTCLServer.h>

Public Member Functions

 CTCLServer (CTCLInterpreter *pInterp, int port)
 
virtual ~CTCLServer ()
 
void instanceExit (CTCLTcpServerInstance *pInstance)
 
void shutdown ()
 

Protected Member Functions

void onConnection (Tcl_Channel connection, std::string host)
 
virtual bool allowConnection (Tcl_Channel connection, std::string hostname)
 
virtual CTCLTcpServerInstancecreateInstance (Tcl_Channel connection, std::string hostname)
 

Detailed Description

This class is a Tcp/ip listener. It is part of the TclPlus class library because when a connection arrives, a CTCLServerInstance object is created that accepts readable events on the client channel assembles them into commands and executes them in our interpreter. This effectively allows any event driven interpreter to incorporate a Tcl server as a component.

Hooks exist for an authentication mechanism via the allowConnection virtual method. By default, this returns true only if the connecting host is localhost or 127.0.0.1, the IP address equivalent. System designers should think very carefully about how authentication should work as allowing connections by unscrupulous people allows them via the Tcl exec command, to do anything the server user could do. Consider, for example a client sending the command: "exec bash -c rm -rf ~" It may be wisest to run the Tcl Server in a slave interpreter that is appropriately constrained (a safe interpreter).

Constructor & Destructor Documentation

◆ CTCLServer()

CTCLServer::CTCLServer ( CTCLInterpreter pInterp,
int  port 
)

Construct the module and set up the listener. The listener is set up using Tcl_OpenTcpServer errors are reported as a CErrnoException using Tcl_GetErrno to get and set the errno variable.

Parameters
interp- Interpreter to which commands will be submitted.
port- Tcp/Ip port on which to listen. If this is not a privileged program this should generally be larger than 1023.

◆ ~CTCLServer()

CTCLServer::~CTCLServer ( )
virtual

Destruction does a shutdown().

Member Function Documentation

◆ allowConnection()

bool CTCLServer::allowConnection ( Tcl_Channel  connection,
std::string  hostname 
)
protectedvirtual

Determines if the connection is allowed. The default behavior is to require that the hostname be either the string "localhost" or "127.0.0.1" both of which indicate a local connection.

This can be overridden to implement a security policy for connections.

Parameters
connection- Data connection (provided to allow some authentication handshaking if desired.
hostname- Name of the client's host.
Returns
bool
Return values
true- Connection is allowed.
false- Connection should not be allowed.

◆ createInstance()

CTCLTcpServerInstance * CTCLServer::createInstance ( Tcl_Channel  connection,
std::string  hostname 
)
protectedvirtual

Create the default server instance object type (CTCLTcpServerInstance) and return it. This can be overridden in subclasses if a different type is required.

Parameters
connection- Tcl_Channel on which data communication will take place.
hostname- Name of the host to which the connection will be made.
Returns
CTCLTcpServerInstance*

◆ instanceExit()

void CTCLServer::instanceExit ( CTCLTcpServerInstance pInstance)

Called by a server instance when its exiting. The server instance is removed from the book-keeping list.

Parameters
pInstance- Pointer to a CTCLTcpServerInstance to remove.

◆ onConnection()

void CTCLServer::onConnection ( Tcl_Channel  connection,
std::string  host 
)
protected

This is called on a connection. In order to support creating subclasses of CTCLTcpServerInstance, we will actually create the server with the virtual member createInstance, so this class can be subclassed, and that member overriden. (strategy pattern). The pointer to the resulting object is isnerted in the m_seerverInstnaces list.

Parameters
connection- Tcl_Channel the client and server use to communicate.
hostname- Name of the client's host.

◆ shutdown()

void CTCLServer::shutdown ( )

Called to shutdown the server. All instance servers are destroyed. In so doing, they close their connections to the outside world.


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