home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / C / Applications / Portable Patmos / usr / include / sys / msg.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-08  |  4.8 KB  |  176 lines  |  [TEXT/R*ch]

  1. /*
  2.  * SVID compatible msg.h file
  3.  *
  4.  * Author:  Daniel Boulet
  5.  *
  6.  * Copyright 1993 Daniel Boulet and RTMX Inc.
  7.  *
  8.  * This system call was implemented by Daniel Boulet under contract from RTMX.
  9.  *
  10.  * Redistribution and use in source forms, with and without modification,
  11.  * are permitted provided that this entire comment appears intact.
  12.  *
  13.  * Redistribution in binary form may occur without any restrictions.
  14.  * Obviously, it would be nice if you gave credit where credit is due
  15.  * but requiring it would be too onerous.
  16.  *
  17.  * This software is provided ``AS IS'' without any warranties of any kind.
  18.  */
  19.  
  20. #ifndef _MSG_H_
  21. #define _MSG_H_
  22.  
  23. #ifdef KERNEL
  24. #include "ipc.h"
  25. #else
  26. #include <sys/ipc.h>
  27. #endif
  28.  
  29. /*
  30.  * The MSG_NOERROR identifier value, the msqid_ds struct and the msg struct
  31.  * are as defined by the SV API Intel 386 Processor Supplement.
  32.  */
  33.  
  34. #define MSG_NOERROR    010000        /* don't complain about too long msgs */
  35.  
  36. struct msqid_ds {
  37.     struct ipc_perm     msg_perm;    /* msg queue permission bits */
  38.     struct msg        *msg_first;    /* first message in the queue */
  39.     struct msg        *msg_last;    /* last message in the queue */
  40.     u_long         msg_cbytes;    /* number of bytes in use on the queue */
  41.     u_long         msg_qnum;    /* number of msgs in the queue */
  42.     u_long         msg_qbytes;    /* max # of bytes on the queue */
  43.     pid_t         msg_lspid;    /* pid of last msgsnd() */
  44.     pid_t         msg_lrpid;    /* pid of last msgrcv() */
  45.     time_t         msg_stime;    /* time of last msgsnd() */
  46.     long         msg_pad1;
  47.     time_t         msg_rtime;    /* time of last msgrcv() */
  48.     long         msg_pad2;
  49.     time_t         msg_ctime;    /* time of last msgctl() */
  50.     long         msg_pad3;
  51.     long         msg_pad4[4];
  52. };
  53.  
  54. struct msg {
  55.     struct msg        *msg_next;    /* next msg in the chain */
  56.     long        msg_type;    /* type of this message */
  57.                         /* >0 -> type of this message */
  58.                         /* 0 -> free header */
  59.     ushort        msg_ts;        /* size of this message */
  60.     short        msg_spot;    /* location of start of msg in buffer */
  61. };
  62.  
  63. /*
  64.  * Structure describing a message.  The SVID doesn't suggest any
  65.  * particular name for this structure.  There is a reference in the
  66.  * msgop man page that reads "The structure mymsg is an example of what
  67.  * this user defined buffer might look like, and includes the following
  68.  * members:".  This sentence is followed by two lines equivalent
  69.  * to the mtype and mtext field declarations below.  It isn't clear
  70.  * if "mymsg" refers to the naem of the structure type or the name of an
  71.  * instance of the structure...
  72.  */
  73.  
  74. struct mymsg {
  75.     long        mtype;        /* message type (+ve integer) */
  76.     char        mtext[1];    /* message body */
  77. };
  78.  
  79. /*
  80.  * Based on the configuration parameters described in an SVR2 (yes, two)
  81.  * config(1m) man page.
  82.  *
  83.  * Each message is broken up and stored in segments that are msgssz bytes
  84.  * long.  For efficiency reasons, this should be a power of two.  Also,
  85.  * it doesn't make sense if it is less than 8 or greater than about 256.
  86.  * Consequently, msginit in kern/sysv_msg.c checks that msgssz is a power of
  87.  * two between 8 and 1024 inclusive (and panic's if it isn't).
  88.  */
  89.  
  90. struct msginfo {
  91.     int        msgmax,        /* max chars in a message */
  92.         msgmni,        /* max message queue identifiers */
  93.         msgmnb,        /* max chars in a queue */
  94.         msgtql,        /* max messages in system */
  95.         msgssz,        /* size of a message segment (see notes above) */
  96.         msgseg;        /* number of message segments */
  97. };
  98. struct msginfo    msginfo;
  99.  
  100. #ifdef KERNEL
  101.  
  102. #ifndef MSGSSZ
  103. #define MSGSSZ    8        /* Each segment must be 2^N long */
  104. #endif
  105.  
  106. #ifndef MSGSEG
  107. #define MSGSEG    2048        /* must be less than 32767 */
  108. #endif
  109.  
  110. #undef MSGMAX            /* ALWAYS compute MGSMAX! */
  111. #define MSGMAX    (MSGSSZ*MSGSEG)
  112.  
  113. #ifndef MSGMNB
  114. #define MSGMNB    2048        /* max # of bytes in a queue */
  115. #endif
  116.  
  117. #ifndef MSGMNI
  118. #define MSGMNI    40
  119. #endif
  120.  
  121. #ifndef MSGTQL
  122. #define MSGTQL    40
  123. #endif
  124.  
  125. /*
  126.  * macros to convert between msqid_ds's and msqid's.
  127.  * (specific to this implementation)
  128.  */
  129.  
  130. #define MSQID(ix,ds)    ((ix) & 0xffff | (((ds).msg_perm.seq << 16) & 0xffff0000))
  131. #define MSQID_IX(id)    ((id) & 0xffff)
  132. #define MSQID_SEQ(id)    (((id) >> 16) & 0xffff)
  133. #endif
  134.  
  135. /*
  136.  * The rest of this file is specific to this particular implementation.
  137.  */
  138.  
  139. #ifdef KERNEL
  140.  
  141. /*
  142.  * Stuff allocated in machdep.h
  143.  */
  144.  
  145. struct msgmap {
  146.     short next;            /* next segment in buffer */
  147.                     /* -1 -> available */
  148.                     /* 0..(MSGSEG-1) -> index of next segment */
  149. };
  150.  
  151. char *msgpool;            /* MSGMAX byte long msg buffer pool */
  152. struct msgmap *msgmaps;        /* MSGSEG msgmap structures */
  153. struct msg *msghdrs;        /* MSGTQL msg headers */
  154. struct msqid_ds *msqids;    /* MSGMNI msqid_ds struct's */
  155.  
  156. #define MSG_LOCKED    01000    /* Is this msqid_ds locked? */
  157.  
  158. #endif
  159.  
  160. #ifndef KERNEL
  161. #include <sys/cdefs.h>
  162.  
  163. __BEGIN_DECLS
  164.  
  165. int msgsys __P((int, ...));
  166.  
  167. int msgctl __P((int, int, struct msqid_ds *));
  168. int msgget __P((key_t, int));
  169. int msgsnd __P((int, void *, size_t, int));
  170. int msgrcv __P((int, void*, size_t, long, int));
  171.  
  172. __END_DECLS
  173.  
  174. #endif
  175. #endif /* !_MSG_H_ */
  176.