Sophie

Sophie

distrib > Mandriva > 8.2 > i586 > media > contrib > by-pkgid > 211238da6d926d1ca4390483bb29f586 > files > 47

coda-doc-5.2.0-4mdk.noarch.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<HTML>
<HEAD>
 <META NAME="GENERATOR" CONTENT="SGML-Tools 1.0.9">
 <TITLE> RPC2 User Guide and Reference Manual: The IOMGR Package</TITLE>
 <LINK HREF="rpc2_manual-11.html" REL=next>
 <LINK HREF="rpc2_manual-9.html" REL=previous>
 <LINK HREF="rpc2_manual.html#toc10" REL=contents>
</HEAD>
<BODY>
<A HREF="rpc2_manual-11.html">Next</A>
<A HREF="rpc2_manual-9.html">Previous</A>
<A HREF="rpc2_manual.html#toc10">Contents</A>
<HR>
<H2><A NAME="s10">10. The IOMGR Package</A></H2>

<P>
<A NAME="IOMGRPrimitives"></A> <P>The IOMGR package allows light-weight processes to wait on various Unix
events.  IOMGR_Select allows a light-weight process to wait on the same
set of events that the Unix <CODE>select</CODE> call waits on.  The parameters to
these routines are the same.  IOMGR_Select puts the caller to sleep
until no user processes are active.  At this time the IOMGR process, which
runs at the lowest priority, wakes up and coaleses all of the select request
together.  It then performs a single <CODE>select</CODE> and wakes up all processes
affected by the result.
<P>The IOMGR_Signal call allows a light-weight process to wait on delivery
of a Unix signal.  The IOMGR installs a signal handler to catch all
deliveries of the Unix signal.  This signal handler posts information about
the signal delivery to a global data structure.  The next time that the
IOMGR process runs, it delivers the signal to any waiting light-weight
processes.
<P>
<H2><A NAME="ss10.1">10.1 Key Design Choices</A>
</H2>

<P>
<UL>
<LI>The meanings of the parameters to IOMGR_Select, both before and after
the call, should be identical to those of the Unix <CODE>select</CODE>;
</LI>
<LI>A blocking select should only be done if no other processes are runnable.</LI>
</UL>
<P>
<H2><A NAME="ss10.2">10.2 A Simple Example</A>
</H2>

<P>
<BLOCKQUOTE><CODE>
 
<PRE>
void rpc2_SocketListener ()
{
    int ReadfdMask, WritefdMask, ExceptfdMask, rc;
    struct timeval *tvp;

    while (TRUE) {
        . . .
        ExceptfdMask = ReadfdMask = (1 &lt;&lt; rpc2_RequestSocket);
        WritefdMask = 0;
        rc = IOMGR_Select (8*sizeof(int), &amp;ReadfdMask, &amp;WritefdMask, &amp;ExceptfdMask, tvp);

        switch (rc) {
            case 0:     /* timeout */
                    continue;   /* main while loop */
                    
            case -1:    /* error */
                    SystemError ("IOMGR_Select");
                    exit (-1);
                    
            case 1:     /* packet on rpc2_RequestSocket */
                    . . . process packet . . .
                    break;

            default:    /* should never occur */
        }
    }
}
</PRE>
</CODE></BLOCKQUOTE>
<P>
<H2><A NAME="ss10.3">10.3 IOMGR Primitives</A>
</H2>

<P>
<P>
<H3>IOMGR_Initialize -- Initialize the IOMGR package </H3>

<P>
<H3>Call:</H3>

<P><EM> void IOMGR_Initialize(</EM>  <EM>)</EM>
<H3>Parameters:</H3>

<P><EM> None. </EM>
<H3>Completion Codes:</H3>

<P>
<DL>
<DT><B>LWP_SUCCESS</B><DD><P>All went well,
<DT><B>LWP_ENOMEM</B><DD><P>Not enough free space to create the IOMGR
process,
<DT><B>-1</B><DD><P>Something went wrong with other init calls,
</DL>
<H3>Description:</H3>

<P>This call will initialize the IOMGR package.  Its main task is
to create the IOMGR process, which runs at priority 0, the
lowest priority.  The remainder of the processes must be
running at priority 1 or greater for the IOMGR package to
function correctly.
)
<P>
<H3>IOMGR_Finalize -- Clean up after IOMGR package </H3>

<P>
<H3>Call:</H3>

<P><EM> void IOMGR_Finalize(</EM> , <EM>)</EM>
<H3>Parameters:</H3>

<P><EM> None. </EM>
<H3>Completion Codes:</H3>

<P>
<DL>
<DT><B>LWP_SUCCESS</B><DD><P>Package finalized okay,
</DL>
<H3>Description:</H3>

<P>This call cleans up when the IOMGR package is no longer
needed.  It releases all storage and destroys the IOMGR
process.
<P>
<H3>--  </H3>

<P>
<H3>Call:</H3>

<P><EM>  (</EM>  <EM>)</EM>
<H3>Parameters:</H3>

<P>
<DL>
<P>
</DL>
<H3>Completion Codes:</H3>

<P>
<DL>
<P>
</DL>
<H3>Description:</H3>

<P>
<P>
<H3>IOMGR_Select -- Perform an LWP select operation </H3>

<P>
<H3>Call:</H3>

<P><EM>  IOMGR_Select(</EM> @w&lt;<B>in</B> int fds&gt;, @w&lt;<B>in out</B> int *readfds&gt;, @w&lt;<B>in out</B> *writefds&gt;, <EM>)</EM>
<H3>Parameters:</H3>

<P>
<DL>
<DT><B>fds</B><DD><P>Maximum number of bits to consider in masks,
<DT><B>readfds</B><DD><P>Mask of file descriptors that process wants notification of
when ready to be read,
<DT><B>writefds</B><DD><P>Mask of file descriptors that process wants notification of
when ready to be written,
<DT><B>exceptfds</B><DD><P>Mask of file descriptors that process wants notification of
when exceptional condition occurs,
<DT><B>timeout</B><DD><P>Timeout for use on this selectrip>
</DL>
<H3>Completion Codes:</H3>

<P>
<H3>Description:</H3>

<P>This function performs an LWP version of Unix <B>select</B>.  The
parameters have the same meanings as the Unix call.  However,
the return value will only be -1 (an error occurred), 0 (a timeout occurred),
or 1 (some number of file descriptors are ready).  If this is
a polling select, it is done and IOMGR_;Select returns to
the user with the results.  Otherwise, the calling process is
put to sleep.  If at some point, the IOMGR process is the only
runnable process, it will awaken and collect all select
requests.  It will then perform a single select and awaken
those processes the appropriate processes -- this will cause
return from the affected IOMGR_;selects.
<P>
<P>
<H3>IOMGR_Signal -- Convert Unix signals to LWP signals </H3>

<P>
<H3>Call:</H3>

<P><EM>  IOMGR_Signal(</EM> @w&lt;<B>in</B> int signo&gt;, @w&lt;<B>in</B> char *event&gt;, <EM>)</EM>
<H3>Parameters:</H3>

<P>
<DL>
<DT><B>signo</B><DD><P>The unix signal number, as defined in signal.h,
<DT><B>event</B><DD><P>The light-weight process event that should be signaled whenever
<EM>signo</EM> is delivered
</DL>
<H3>Completion Codes:</H3>

<P>
<DL>
<DT><B>LWP_;SUCCESS</B><DD><P>No problems.,
<DT><B>LWP_;EBADSIG</B><DD><P><EM>signo</EM> was out of range,
<DT><B>LWP_;EBADEVENT</B><DD><P><EM>event</EM> was zero,
</DL>
<H3>Description:</H3>

<P>This function associates an LWP signal with a Unix signal.
When the Unix signal <EM>signo</EM> is delivered to the
process, the IOMGR process will deliver an LWP signal to the
event <EM>event</EM> via LWP_;NoYieldSignal,
waking any light-weight processes waiting
on that event.  Multiple deliveries of the signal may be
coalesed into one LWP wakeup.  The call to LWP_;NoYieldSignal
will happen synchronously.  It is safe for an LWP to check for
some condition and then go to sleep waiting for a Unix signal
without having to worry about delivery of the signal happening
between the check and the call to LWP_;WaitProcess.
<P>
<H3>IOMGR_;CancelSignal -- Cancel association between Unix signal and LWP event </H3>

<P>
<H3>Call:</H3>

<P><EM>  IOMGR_;CancelSignal(</EM> @w&lt;<B>in</B> int signo&gt;, <EM>)</EM>
<H3>Parameters:</H3>

<P>
<DL>
<DT><B>signo</B><DD><P>The Unix signal that should no longer be converted.
</DL>
<H3>Completion Codes:</H3>

<P>
<DL>
<DT><B>LWP_;SUCCESS</B><DD><P>The association was cancelled,
<DT><B>LWP_;EBADSIG</B><DD><P><EM>signo</EM> is out of range or
LWP_Signal has not been called on it,
</DL>
<H3>Description:</H3>

<P>This function cancels the association of a Unix signal and an
LWP event.  After calling this function, the Unix signal
<EM>signo</EM> will be handled however it was handled before the
corresponding call to LWP_Signal.
<P>
<P>
<P>
<HR>
<A HREF="rpc2_manual-11.html">Next</A>
<A HREF="rpc2_manual-9.html">Previous</A>
<A HREF="rpc2_manual.html#toc10">Contents</A>
</BODY>
</HTML>