예제 #1
0
void Crutch::terminate() {
  if (m_queue.get()) {
    f_msg_remove_queue(m_queue);
    m_queue.reset();
  }
  if (m_php) {
    kill(m_php, SIGKILL); // not needed normally but be safe
    int status = -1;
    wait(&status);
    m_php = 0;
  }
}
예제 #2
0
bool TestExtIpc::test_message_queue() {
  char filename[64];
  strcpy(filename, "/tmp/XXXXXX");
  close(mkstemp(filename));

  int64 token = f_ftok(filename, "a");
  Object queue = f_msg_get_queue(token);
  VERIFY(queue.get());

  int pid = fork();
  if (pid == 0) {
    Object q = f_msg_get_queue(token);
    assert(q.get());
    assert(f_msg_send(q, 2, "start"));
    Variant type, msg;
    assert(f_msg_receive(q, 1, ref(type), 100, ref(msg)));
    assert(f_msg_send(q, 2, msg)); // echo
    _exit(-1);
  }

  Variant type, msg;
  VERIFY(f_msg_receive(queue, 2, ref(type), 100, ref(msg)));
  VERIFY(same(msg, "start"));

  VERIFY(f_msg_send(queue, 1, "ok"));
  VERIFY(f_msg_receive(queue, 2, ref(type), 100, ref(msg)));
  VERIFY(same(msg, "ok"));

  Array ret = f_msg_stat_queue(queue);
  VS(ret["msg_qnum"], 0);
  f_msg_set_queue(queue, CREATE_MAP1("msg_perm.mode", 0666));

  f_msg_remove_queue(queue);
  int status = -1;
  wait(&status);
  return Count(true);
}