MWMAINLOOP
Section: MidWay Programmer's Manual (3C)
Updated: DATE
Index
Return to Main Contents
NAME
mwMainLoop - Main loop in a MidWay server
SYNOPSIS
#include <MidWay.h>
int mwMainLoop(int flags);
DESCRIPTION
This is called by a server after it has attached it self to the domain with
mattach()
and provided all its service routines with
mwprovide().
mwMainLoop()
essentially calls
mwservicerequest()
indefinitely.
If
MWSIGRST
is not set it will return on a signal, with return code -EINTR.
Programmers may feel the need roll their own mwMainLoop, especially if you want to
incorporate a MidWay server in a program that has a main loop else where. Thats
pretty much OK, just be careful. An example mwMainLoop is shown below, taken from
MidWay/src/lib/mwserver.c.
You may also look in the code for
mwserver(1)
(MidWay/src/mwserver) for a more complex example.
After
mwMainLoop()
exits you are
required
to call
mwdetach().
Failure to do so will leave IPC resources undeleted, and the info tables in shared memory
will still hold information about this server, and some service calls may fail
since they may still be addressed to this server.
When
mwMainLoop()
returns the status if the server is set to "(suspended)".
RETURN VALUES
The return value is always a negative errno, giving the reason why the loop aborted.
ERRORS
- EINTR
-
A signal was delivered to the program
while in msgrcv.
If you want to know which one, or to watch signals during execution of service routines,
install a signal handler.
- ENOTCONN
-
Either
mwattach()
has not yet been called, or it failed, or
mwdetach()
has been called.
- ESHUTDOWN
-
The MidWay daemon
mwd(1)
has sent us an instruction to exit. We are required to do so.
- ENOENT
-
No calls to
mwprovide()
has been made or
in the last service request a
mwunprovide()
was called on the last service this server provided. To continue
mwMainLoop()
would be futile since the only "service" we can perform is a
shutdown instruction from
mwd(1).
If you wanted to suspend a service in such a way it can be resumed from
mwadm(1),
use
mw******().(Futurefunctionality.)
WARNINGS
EXAMPLES
An (almost) minimum implementation of mwMainLoop().
int mwMainLoop(int flags)
{
int rc, counter = 0;
while(1) {
counter++;
mwlog(MWLOG_DEBUG, "std MailLoop begining for the %d time.",
counter);
rc = mwservicerequest(flags);
if ( (rc == -EINTR) && (flags & MWSIGRSRT)) continue;
if (rc < 0) return rc;
};
};
BUGS
SEE ALSO
mwprovide(3C),
mwunprovide(3C),
mwattach(3C),
mwdetach(3C),
mwservicerequest(3C),
mwd(1),
mwserver(1)
STANDARDS
NONE
Index
- NAME
-
- SYNOPSIS
-
- DESCRIPTION
-
- RETURN VALUES
-
- ERRORS
-
- WARNINGS
-
- EXAMPLES
-
- BUGS
-
- SEE ALSO
-
- STANDARDS
-
This document was created by
man2html,
using the manual pages.
Time: 11:18:49 GMT, October 24, 2000