From:	CRDGW2::CRDGW2::MRGATE::"SMTP::CRVAX.SRI.COM::RELAY-INFO-VAX"  4-MAR-1991 05:20:20.20
To:	ARISIA::EVERHART
CC:	
Subj:	re: Help w/ Mailboxes

From:	RELAY-INFO-VAX@CRVAX.SRI.COM@SMTP@CRDGW2
To:	Everhart@Arisia@MRGATE

Received:  by crdgw1.ge.com (5.57/GE 1.88)
	 id AA09806; Mon, 4 Mar 91 04:21:48 EST
Received: From BULLDOG.CS.YALE.EDU ([130.132.1.2]) by CRVAX.SRI.COM with TCP; Sat,  2 MAR 91 08:15:52 PST
Received: from lrw.UUCP by BULLDOG.CS.YALE.EDU via UUCP; Sat, 2 Mar 91 11:10:51 EST
Message-Id: <9103021610.AA06221@BULLDOG.CS.YALE.EDU>
Received: by lrw.UUCP (DECUS UUCP w/Smail);
          Sat,  2 Mar 91 10:50:16 EDT
Date: Sat,  2 Mar 91 10:50:16 EDT
From: Jerry Leichter <leichter@LRW.COM>
To: INFO-VAX@KL.SRI.COM
Subject: re: Help w/ Mailboxes

	I've asked this before, and got no response, so I'll try again.

	I'm a fairly experienced programmer, but completely new to Vaxen and
	VMS.   I would like any information, or _any_ example source code on
	how to program mail boxes.

	If you have any time to explain, or any source code kicking about,
	please mail them.  I *don't mind* if I get mail from 300 people...

	Reasons-I'm-posting-here-so-please-don't-flame-me-Ehud:
		1] _No_ access to TFM.
		2] _No_ VMS people here; or none that know anything about
			mailboxes.
		3] I've tried other people
		4] I'm desperate.

If it's THAT important, the FM only costs a few tens of dollars.

However:  Here's a simple program that logs messages written to a mailbox.
It's intended to be used for producing logging traces of multiple parallel
processes.  The processes that write to the mailbox simply open LOGGING_MBX:
as a file.

Ignore the parts that don't seem to have anything to do with logging - this
is part of a larger system.  I haven't sent the (many, mostly irrelevant)
include files; I think all you need to know is that common.h #include's
<descrip.h>, and that CHANNEL is a typedef for short.

You've set up an impossible position for yourself.  If this program example
isn't enough - sorry, you are not likely to get anything useful from asking
on the net.
							-- Jerry

/*
 * Logger process
 */
#include "L:common.h"
#define MAXMSG 150
#define ERRLIM 100

globalvalue BOOLEAN     Listener = FALSE;

main(argc,argv)
int argc;
char *argv[];
{	$DESCRIPTOR(lognam,"LOGGING_MBX");
	CHANNEL chan;
	int count_exp = 1;			/* Expected procs	*/
	int count_in = 0;			/* Actual started procs	*/
	int count_out = 0;			/* Actual ended procs	*/
	int errlim = ERRLIM;
	FILE *mbx;
	char msg[MAXMSG+10];

	argc = getredirection(argc,argv);
	if (argc > 1)
		count_exp = atoi(argv[1]);

	TEST(SYS$CREMBX(0,			/* prmflg - temporary	*/
		&chan,				/* chan			*/
		MAXMSG,				/* maxmsg		*/
		max(3*(count_exp+2)*MAXMSG,10000),
						/* bufquo		*/
		0xFF0F,				/* promsk - owner only	*/
		0,				/* acmode		*/
		&lognam));			/* lognam		*/

	if (NULL == (mbx = fopen("LOGGING_MBX:","r")))
		BUGCHECK("Can't open logger mailbox");

	while (count_out < count_exp && errlim > 0)
	{	if (fgets(msg,sizeof(msg),mbx) == NULL)
		{	if (ferror(mbx))
			{	strcpy(msg,"### Error ###\n");
				--errlim;
			}
			else	strcpy(msg,"###  EOF  ###\n");
			clearerr(mbx);
		}

		if (msg[0] == '+')
		{	count_in++;
			if (count_in > count_exp)
			{	printf(
				    "### Exceeding expected processes ###\n");
				count_exp = count_in;
			}
		}
		else if (msg[0] == '-')
		{	count_out++;
		}

		fputs(msg,stdout);
	}

	printf("### Done, %d errors ###\n",ERRLIM - errlim);
}

