CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
SlaveQueue.cc
Go to the documentation of this file.
2 
3 using namespace evf;
4 
5 SlaveQueue::SlaveQueue(unsigned int ind) :
6  queue_id_(0) {
7 
8  /* get an (existing) public message queue */
9  queue_id_ = msgget(QUEUE_ID + ind, 0);
10  if (queue_id_ == -1) {
11  XCEPT_RAISE(evf::Exception, "failed to get message queue");
12  }
13 }
14 
16 }
17 
19  int rc; /* error code retuend by system calls. */
20  rc = msgsnd(queue_id_, ptr.ptr_, ptr.msize() + 1, 0);
21  // delete ptr;
22  if (rc == -1)
23  std::cout << "snd::Slave failed to post message - error:" << strerror(
24  errno) << std::endl;
25  return rc;
26 }
27 
28 unsigned long SlaveQueue::rcv(MsgBuf &ptr) {
29  unsigned long msg_type = MSQS_MESSAGE_TYPE_SLA;
30  int rc = msgrcv(queue_id_, ptr.ptr_, ptr.msize() + 1, -msg_type, 0);
31  if (rc == -1 && errno != ENOMSG) {
32  std::string serr =
33  "rcv::Slave failed to get message from queue - error:";
34  serr += strerror(errno);
35  XCEPT_RAISE(evf::Exception, serr);
36  } else if (rc == -1 && errno == ENOMSG)
38  return msg_type;
39 }
40 
42  int rc = msgrcv(queue_id_, ptr.ptr_, ptr.msize() + 1, ptr->mtype, 0);
43  if (rc == -1 && errno != ENOMSG) {
44  return false;
45  }
46  return true;
47 }
48 
49 unsigned long SlaveQueue::rcvNonBlocking(MsgBuf &ptr) {
50  unsigned long msg_type = MSQS_MESSAGE_TYPE_SLA;
51  int rc =
52  msgrcv(queue_id_, ptr.ptr_, ptr.msize() + 1, -msg_type, IPC_NOWAIT);
53  if (rc == -1 && errno != ENOMSG) {
54  std::string serr =
55  "rcvnb::Slave failed to get message from queue - error:";
56  serr += strerror(errno);
57  XCEPT_RAISE(evf::Exception, serr);
58  } else if (rc == -1 && errno == ENOMSG)
60  return msg_type;
61 }
62 
64  unsigned long msg_type = 0;
65  int rc = msgrcv(queue_id_, ptr.ptr_, ptr.msize() + 1, msg_type, IPC_NOWAIT);
66  if (rc == -1 && errno != ENOMSG) {
67  std::string serr =
68  "rcvnb::Slave failed to get message from queue - error:";
69  serr += strerror(errno);
70  XCEPT_RAISE(evf::Exception, serr);
71  } else if (rc == -1 && errno == ENOMSG)
73  return msg_type;
74 }
75 
76 int SlaveQueue::id() const {
77  return queue_id_;
78 }
79 
size_t msize()
Definition: MsgBuf.cc:33
#define MSQS_MESSAGE_TYPE_SLA
Definition: queue_defs.h:29
#define MSGQ_MESSAGE_TYPE_RANGE
Definition: queue_defs.h:13
struct msgbuf * ptr_
Definition: MsgBuf.h:24
int id() const
Definition: SlaveQueue.cc:76
bool rcvQuiet(MsgBuf &ptr)
Definition: SlaveQueue.cc:41
unsigned long rcvNonBlocking(MsgBuf &ptr)
Definition: SlaveQueue.cc:49
int post(MsgBuf &ptr)
Definition: SlaveQueue.cc:18
#define QUEUE_ID
Definition: queue_defs.h:9
unsigned long rcvNonBlockingAny(MsgBuf &ptr)
Definition: SlaveQueue.cc:63
unsigned long rcv(MsgBuf &ptr)
Definition: SlaveQueue.cc:28
SlaveQueue(unsigned int ind)
Definition: SlaveQueue.cc:5
tuple cout
Definition: gather_cfg.py:121