Home

GEONius.com
23-Dec-2015
E-mail

mist_util - MEDS Interprocess Stream Utilities

The MIST utilities provide a high-level mechanism for exchanging messages over the network between a MEDS task and a TPCE process. The MIST package is layered on top of the lower-level TCP_UTIL functions. Network connections can be established between clients and servers and MEDS streams are built on these connections.

A MEDS message is composed of a fixed-length message header followed by the variable-length message text; one of the fields in the header specifies the length of the text. The MIST functions are used to read a message (both header and text) from the stream and to write a message to the stream.

The following program implements a simple MEDS server that receives commands from its client and returns status messages to the client:

    #include  <stdio.h>				-- Standard I/O definitions.
    #include  "tcp_util.h"			-- TCP/IP networking utilities.
    #include  "mist_util.h"			-- MIST definitions.

    int  main (int argc, char *argv[])
    {
        MedStream  stream ;
        MSGHDR  *commandHeader, statusHeader ;
        TcpEndpoint  client, server ;
        void  *commandText, *statusText ;

        tcpListen (argv[1], 99, &server) ;	-- Create listening endpoint.

        for ( ; ; ) {				-- Answer next client.
            tcpAnswer (server, -1.0, &client) ;
            mistCreate (client, NULL, &stream) ;
            for ( ; ; ) {			-- Service connected client.
                if (mistRead (stream, -1.0, &commandHeader, &commandText))
                    break ;
                ... process command text ...
                ... construct status message ...
                mistWrite (stream, -1.0, &statusHeader, statusText) ;
            }
            mistDestroy (stream) ;		-- Lost client.
        }

    }

The server's name is specified as the first argument on the command line (i.e., argv[1]). If a client connection is broken, the server loops back to wait for another client.

The client program below sends commands to the MEDS server and reads the status messages that are returned:

    #include  <stdio.h>				-- Standard I/O definitions.
    #include  "tcp_util.h"			-- TCP/IP networking utilities.
    #include  "mist_util.h"			-- MIST definitions.

    int  main (int argc, char *argv[])
    {
        MedStream  stream ;
        MSGHDR  commandHeader, *statusHeader ;
        TcpEndpoint  connection ;
        void  *commandText, *statusText ;
						-- Call server.
        tcpCall (argv[1], -1.0, -1.0, &connection) ;
        mistCreate (connection, NULL, &stream) ;
        for ( ; ; ) {				-- Communicate with server.
            ... construct command message ...
            mistWrite (stream, -1.0, &commandHeader, commandText) ;
            if (mistRead (stream, -1.0, &statusHeader, &statusText))
                break ;
            ... process status message ...
        }
        mistDestroy (stream) ;			-- Lost server.

    }

Both mistRead() and mistWrite() take a timeout argument that allows the application to limit the amount of time these routines wait to perform their respective functions.


Public Procedures

mistCreate() - creates a MEDS network stream.
mistDestroy() - deletes a MEDS network stream.
mistFd() - returns a MEDS stream's socket number.
mistIsReadable() - checks if input is waiting to be read from a stream.
mistIsUp() - checks if a MEDS stream is up.
mistIsWriteable() - checks if data can be written to a stream.
mistRead() - reads the next message from a MEDS stream.
mistWrite() - writes a message to a MEDS stream.

Source Files

mist_util.c
mist_util.h

Alex Measday  /  E-mail