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

 

smtsock_init

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

Synopsis

Initialises the SMT socket agent. Returns 0 if initialised okay, -1 if there was an error. The socket agent manages all sockets (TCP and UPD) used by an SMT application. Creates an unnamed thread automatically: send events to that thread. Initialises the sflsock socket interface automatically. Supports these public methods:
READ Read a specified amount of input data (use SMT_SOCK_READ).
WRITE Write a specified amount of output data (use SMT_SOCK_WRITE).
READR Read input data, repeatedly (use SMT_SOCK_READ).
READH As for READ, but for blocks > 64k (use SMT_SOCK_READH).
WRITEH As for WRITE, but for blocks > 64k (use SMT_SOCK_WRITEH).
READRH As for READR, but for blocks > 64k (use SMT_SOCK_READH).
INPUT Wait for any input ready on socket (use SMT_SOCK_INPUT).
INPUTR Wait for any input, repeatedly (use SMT_SOCK_INPUT).
OUTPUT Wait for any output ready on socket (use SMT_SOCK_OUTPUT).
CONNECT Make socket connection to host & port (use SMT_SOCK_CONNECT).
FLUSH Delete all requests for specified socket (use SMT_SOCK_FLUSH).
Sends errors to the SMTOPER agent; see doc for reply events.

Source Code - (smtsock.c)

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

    /*  We give this agent a low priority, so that it will only run after    */
    /*  all other threads.  This is important, since it blocks on select().  */
    agent-> priority = SMT_PRIORITY_LOW;

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

    /*  Public methods supported by this agent                               */
    method declare (agent, "READ",          read_event,      0);
    method declare (agent, "READR",         readr_event,     0);
    method declare (agent, "READH",         readh_event,     0);
    method declare (agent, "READRH",        readrh_event,    0);
    method declare (agent, "WRITE",         write_event,     0);
    method declare (agent, "WRITEH",        writeh_event,    0);
    method declare (agent, "INPUT",         input_event,     0);
    method declare (agent, "INPUTR",        inputr_event,    0);
    method declare (agent, "OUTPUT",        output_event,    0);
    method declare (agent, "CONNECT",       connect_event,   0);
    method declare (agent, "FLUSH",         flush_event,     0);

    /*  Private method used to cycle on select() call                        */
    method declare (agent, "_TIMEOUT",      timeout_event,   0);

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

    /*  Initialise the socket interface and register sock_term()             */
    if (sock_init () == 0)
        smt atexit ((function) sock_term);
    else
      {
        sendfmt (&operq, "ERROR",
                 "smtsock: could not initialise socket interface");
        sendfmt (&operq, "ERROR",
                 "smtsock: %s", connect_errlist [connect_error ()]);
        return (-1);
      }

    ip_nonblock = TRUE;                  /*  Want nonblocking sockets        */

    /*  Create initial, unnamed thread                                       */
    thread create (AGENT_NAME, "");

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

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