FRIBParallelanalysis
1.0
FrameworkforMPIParalleldataanalysisatFRIB
|
#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 CTCLTcpServerInstance * | createInstance (Tcl_Channel connection, std::string hostname) |
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).
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.
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. |
|
virtual |
Destruction does a shutdown().
|
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.
connection | - Data connection (provided to allow some authentication handshaking if desired. |
hostname | - Name of the client's host. |
true | - Connection is allowed. |
false | - Connection should not be allowed. |
|
protectedvirtual |
Create the default server instance object type (CTCLTcpServerInstance) and return it. This can be overridden in subclasses if a different type is required.
connection | - Tcl_Channel on which data communication will take place. |
hostname | - Name of the host to which the connection will be made. |
void CTCLServer::instanceExit | ( | CTCLTcpServerInstance * | pInstance | ) |
Called by a server instance when its exiting. The server instance is removed from the book-keeping list.
pInstance | - Pointer to a CTCLTcpServerInstance to remove. |
|
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.
connection | - Tcl_Channel the client and server use to communicate. |
hostname | - Name of the client's host. |
void CTCLServer::shutdown | ( | ) |
Called to shutdown the server. All instance servers are destroyed. In so doing, they close their connections to the outside world.