コード例 #1
0
ファイル: crutch.cpp プロジェクト: Neomeng/hiphop-php
void Crutch::init() {
  char filename[64];
  strcpy(filename, "/tmp/hphp_crutch_XXXXXX");
  int fd = mkstemp(filename);
  if (!fd) {
    throw FatalErrorException("unable to create a temporary file for crutch");
  }
  close(fd);

  m_queue = f_msg_get_queue(f_ftok(filename, "a"));
  if (m_queue.get() == NULL) {
    throw FatalErrorException("unable to create a message queue for crutch");
  }

  int pid = fork();
  if (pid == 0) {
    const char *argv[] = {"/usr/local/bin/hphp/crutch.php", filename, NULL};
    execvp(argv[0], const_cast<char**>(argv));
    _exit(-1); // something wrong
  }

  m_php = pid;
  Variant type, ret;
  if (!f_msg_receive(m_queue, 2, ref(type), MSG_MAX_SIZE, ref(ret)) ||
      !same(ret, "CRUTCH")) {
    terminate();
    throw FatalErrorException("unable to hear startup signal from crutch");
  }
}
コード例 #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);
}