/*****************************************************************************
* COPYRIGHT (C) 1994 by GTE Government Systems Corporation.  All rights      *
* reserved.  No part of this material may be used, photocopied, reproduced,  *
* or committed to magnetic, electronic or any other form of media without    *
* the prior written consent of GTE Government Systems Corporation.           *
*****************************************************************************/

/*    ClearCase Header updated automatically

      $Header:   filename    version    date    $

      $Edit History: $

      End ClearCase Header                           */

#ifndef mbox_h
#define mbox_h
#if defined(USE_UDP) || defined(USE_TCP)
#include "sys_in.h"
#endif
#ifdef USE_CA
#ifndef   ca_h
#include "ca.h"
#endif
#endif
#ifndef   str_h
#include "str.h"
#endif
#ifndef O_RDWR
#include "sys_fcntl.h"
#endif

#define Mbox struct ems_mbox
Mbox {
	int  type;	/* How is it implemented? */
	Str  name;	/* The mailbox's name, minus affixes */
	int  file;	/* File handle, if it's a file */
	Str  path;	/* The mailbox's pathname, if it's a file */
	int  shmid;	/* Shared-mem id, if it's a shm segment */
	int  mode;	/* Access (any of the *_FLAGS defined below) */
	int  flag;	/* Assorted 1-bit flags */
	Mbox*next;	/* Global list of Mboxes */
#if defined(USE_UDP) || defined(USE_TCP)
	SKIN ipadr;	/* The IP address and port for the other end */
#endif
#ifdef USE_CA
	CAadr caadr;	/* The CA address for the other end */
#endif
};
extern Mbox *mboxlist;	/* All the mboxes that have been allocated */

#define MBOXLEN 17	/* Longest valid Mbox name */
/*
* Here are the known mbox types:
*/
#define MBOX_FIFO 1	/* Named pipe */
#define MBOX_TCP  2	/* TCP stream socket (not implemented yet) */
#define MBOX_UDP  3	/* UCP datagram socket (not implemented yet) */
#define MBOX_SHM  4	/* Shared-memory segment (not implemented yet) */
#define MBOX_TTY  5	/* Serial port */
#define MBOX_HIGH 5	/* Must equal the highest valid mbox type code */
/*
*/
#define MBOX_R   0x01	/* Readable */
#define MBOX_W   0x02	/* Writable */
#define MBOX_E   0x04	/* Error checking */
#define MBOX_RWE 0x07	/* All of the above */
/*
*/
extern int   callfd;	/* File number used for call */
/*
* Here are the permissions that we need to build mbox fifo files:
*/
#define O_PERMS  0622
#define MK_FLAGS (S_IFIFO  | O_PERMS)
#define RD_FLAGS (O_RDONLY | O_NONBLOCK)
#define WR_FLAGS (O_WRONLY | O_NONBLOCK)
#define RW_FLAGS (O_RDWR   | O_NONBLOCK)

#endif
