class IPCObject

Provides an interface to Unix SysV style shared memory

Description

This class can be used to provide a means of accessing SysV style shared memory areas for interprocess communication. As well as allowing Ferite processes to communicate with each other, it can also be used to communicate with any other applications which use SysV style shared memory.

Example

uses "console", "ipc", "string";

object myipc;
number shmid;
number option = 1;
string data;

myipc = new IpcObject();

Console.println ("::Connecting...");
myipc.connect ("/bin/sh");

Console.println ("Choose one of the following options");

while (option != 0)
{
    Console.println ("\n0 - QUIT");
    Console.println ("1 - Write to shm");
    Console.println ("2 - Read from shm");

    option = String.toLong (Console.readln());

    Console.println("");

    switch( option )
    {
     case 1:
        Console.println ("Type something to put in the shared memory segment:");
        data = Console.readln();
        myipc.write (data);
        Console.println ("\n>>>Wrote: $data");
        break;
     case 2:
        data = myipc.read();
        Console.println (">>>Got: $data");
        break;
     case 0:
        break;
     default:
        Console.println ("Invalid Option. Please choose either 0, 1 or 2");
    }
}

myipc.disconnect();


class contents [NB. Highlighted attributes are static members]
Functions
function connect(string) - Connects to a shared memory segment
function disconnect() - Disconnects from a shared memory segment and possibly deletes it
function read() - Reads a string from the shared memory segment
function take() - Take the contents of the memory segment, this reads and then clears the shared segment
function write(string) - Writes a message string to the shared memory segment

Functions

function connect Click to go up to the list
Connects to a shared memory segment
Declaration:
    function connect( string file )
Description:
This function tries to connect to the specified shm key. If it does not exist, it will try to create it. If an error occurs, it will set the err object values and return false.
Parameters:
    Parameter #1: string file - The name of the file to attach the shm segment to.
Returns:
    true on success, false otherwise

function disconnect Click to go up to the list
Disconnects from a shared memory segment and possibly deletes it
Declaration:
    function disconnect( )
Description:
This function disconnects the object from its shared memory segment. If no other process is connected to the segment it will be deleted. If an error occurs, it will set the err object values and return false.
Returns:
    true on success, false otherwise

function read Click to go up to the list
Reads a string from the shared memory segment
Declaration:
    function read( )
Returns:
    A string containing the data which was read from the segment, empty if failure to read.

function take Click to go up to the list
Take the contents of the memory segment, this reads and then clears the shared segment
Returns:
    The contents of the segment as a string, empty on failure

function write Click to go up to the list
Writes a message string to the shared memory segment
Declaration:
    function write( string msg )
Description:
If an error occurs, it will set the err object values and return false.
Parameters:
    Parameter #1: string msg - The message string to write to the shared memory segment
Returns:
    true on success, false otherwise

Automatically generated at 12:07PM, Wednesday 25 May 2005 by feritedoc.