Beispiel #1
0
int main(int argc, char *argv[]) {
  init_server_name();
  start_mongoose(argc, argv);
  printf("%s started on port(s) %s with web root [%s]\n",
         server_name, mg_get_option(ctx, "listening_ports"),
         mg_get_option(ctx, "document_root"));
  while (exit_flag == 0 && !mg_get_stop_flag(ctx)) {
    mg_sleep(100);
  }
  printf("Exiting on signal %d/%d, waiting for all threads to finish...",
        exit_flag, mg_get_stop_flag(ctx));
  fflush(stdout);
  mg_stop(ctx);
  printf(" done.\n");

  return EXIT_SUCCESS;
}
Beispiel #2
0
int tier2_message::wait_for_response(interthread_communicator *listen_comm)
{
    assert(requester != m_receiver);
    //interthread_communicator *comm = m_owner->get_interthread_communicator(m_receiver, requester);  -- m_owner is in limbo, hence untrustworthy!
    assert(listen_comm);
    assert(listen_comm->receiver() == requester);

    if (!listen_comm)
        return -1;

    // check the message queue of the requester to see if the expected message already was returned before we called this!
    if (requester->does_own(this))
    {
        switch(this->state())
        {
        case MSG_INITIALIZED:
        case EXEC_COMMAND:
        case WAIT_FOR_TRANSMIT:
        case COMMENCE_TRANSMIT:
        case READY_TO_RECEIVE_RESPONSE:
        case RESPONSE_PENDING:
            break;

        case RESPONSE_COMPLETE:
        case TASK_COMPLETED:
        default:
            // our message has already been answered / completed / aborted ... it's concluded anyway.
            return 0;
        }
    }

    while (mg_get_stop_flag(mg_get_context(listen_comm->receiver_socket())) == 0)
    {
        // make me wait for a message to arrive...
        interthread_communicator::msg_pending_mode_t msg_mode = interthread_communicator::NO_MSG;

        tier2_message *msg = listen_comm->pop_one_message(msg_mode);

        // if the popped message is our response (and not some book-keeping sort of thing), we know we're done.
        if (!msg)
        {
            return -1;
        }
        if (msg == this)
        {
            return 0;
        }
    }
    return -1;
}
Beispiel #3
0
int main(void) {
  struct mg_context *ctx;
  const char *options[] = {"listening_ports", LISTENING_PORT, NULL};
  const struct mg_user_class_t ucb = {
    NULL,      // Arbitrary user-defined data
    callback   // User-defined callback function
  };

  ctx = mg_start(&ucb, options);
  while (!mg_get_stop_flag(ctx)) {
    mg_sleep(100);
  }
  mg_stop(ctx);
  return 0;
}