Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-03 08:20:35

0001 
0002 #include <msgqueue.h>
0003 
0004 msgqueue::msgqueue (  char * token, const int id, 
0005          int &status, const int inew )
0006 {
0007 
0008   int ishmflg;
0009 
0010   tokenid = ftok ( token, id);
0011   wasnew = inew;
0012   if (inew)
0013     {
0014       ishmflg =  0666 | IPC_CREAT;
0015     }
0016   else
0017     {
0018       ishmflg =  0666;
0019     }
0020   msgid = msgget(tokenid,ishmflg);
0021 
0022   if (msgid < 0) 
0023     {
0024       status = msgid;
0025       return;
0026     }
0027 
0028   status = 0;
0029 }
0030  
0031 msgqueue::~msgqueue()
0032 {
0033   if (wasnew)
0034     {
0035 
0036 #if defined(SunOS) || defined(Linux)
0037       struct msqid_ds msgb;
0038       msgctl (msgid, IPC_RMID,&msgb);
0039 
0040 #else
0041       msgctl (msgid, IPC_RMID);
0042 
0043 #endif
0044 
0045     }
0046 }
0047 
0048 int msgqueue::receive( struct msgbuf *structure, int size)
0049 {
0050   return msgrcv(msgid, structure, size,  0, 0);
0051 }
0052 
0053 int msgqueue::receive_nowait( struct msgbuf* structure, int size)
0054 {
0055   return msgrcv(msgid, structure, size,  0, IPC_NOWAIT);
0056 }
0057 
0058 int msgqueue::send( struct msgbuf * structure, int size)
0059 {
0060   return msgsnd(msgid, structure, size,  0);
0061 }
0062 
0063 int msgqueue::wait_for_ping()
0064 {
0065   int i[2];
0066   return msgrcv(msgid, (struct msgbuf *) i, 8,  0, 0);
0067 }
0068 
0069 int msgqueue::send_ping()
0070 {
0071   int i[2];
0072   i[0]= 1;
0073   i[1]= 0;
0074 
0075   return msgsnd(msgid, (struct msgbuf *) i , 8,  0);
0076 }
0077 
0078 
0079 
0080 
0081 
0082