| iMatix home page
| << | < | > | >>
SMT Logo SMT
Version 2.81

 

smtecho_init

#include "smtdefn.h"
int
smtecho_init (void)

Synopsis

Initialises the SMT echo agent. Returns 0 if initialised okay, -1 if there was an error. The echo agent handles the TCP ECHO protocol on port 7. It logs connections to the file smtecho.log. It sends errors to the SMTOPER agent. If you set the ip_portbase before calling this function, the echo port is shifted by that amount. A typical value for ip_portbase is 5000: the echo agent will then handle connections on port 5007.

Source Code - (smtecho.c)

{
    AGENT   *agent;                     /*  Handle for our agent             */
    THREAD  *thread;                    /*  Handle to various threads        */
#   include "smtecho.i"                 /*  Include dialog interpreter       */

    /*                      Method name      Event value     Priority        */
    /*  Shutdown event comes from Kernel                                     */
    method declare (agent, "SHUTDOWN",       shutdown_event, SMT_PRIORITY_MAX);

    /*  Reply events from socket agent                                       */
    method declare (agent, "SOCK_INPUT_OK",  ok_event,       0);
    method declare (agent, "SOCK_OUTPUT_OK", ok_event,       0);
    method declare (agent, "SOCK_READ_OK",   read_ok_event,  0);
    method declare (agent, "SOCK_WRITE_OK",  write_ok_event, 0);
    method declare (agent, "SOCK_CLOSED",    closed_event,   0);
    method declare (agent, "SOCK_ERROR",     error_event,    0);
    method declare (agent, "SOCK_TIMEOUT",   error_event,    0);

    /*  Private methods used to pass initial thread events                   */
    method declare (agent, "_MASTER",        master_event,   0);
    method declare (agent, "_CLIENT",        client_event,   0);

    /*  Ensure that operator console is running, else start it up            */
    smtoper init ();
    if ((thread = thread lookup (SMT_OPERATOR, "")) != NULL)
        operq = thread-> queue-> qid;
    else
        return (-1);

    /*  Ensure that socket agent is running, else start it up                */
    smtsock init ();
    if ((thread = thread lookup (SMT_SOCKET, "")) != NULL)
        sockq = thread-> queue-> qid;
    else
        return (-1);

    /*  Ensure that logging agent is running, and create new thread          */
    smtlog init ();
    if ((thread = thread create (SMT_LOGGING, "")) != NULL)
        logq = thread-> queue-> qid;        /*  Get logging queue id         */
    else
        return (-1);

    /*  Create initial thread to manage master port                          */
    if ((thread = thread create (AGENT_NAME, "")) != NULL)
      {
        SEND (&thread-> queue-> qid, "_MASTER", "");
        ((TCB *) thread-> tcb)-> thread_type = master_event;
        ((TCB *) thread-> tcb)-> handle      = 0;
      }
    else
        return (-1);

    /*  Signal okay to caller that we initialised okay                       */
    return (0);
}

| << | < | > | >> iMatix Copyright © 1996-99 iMatix Corporation