cs_error_t CorosyncCpg::init() {
  if (ready) {
    return CS_OK;
  }
  cpg_callbacks_t callbacks;
  ::memset(&callbacks, 0, sizeof(callbacks));
  callbacks.cpg_deliver_fn = &globalDeliver;
  callbacks.cpg_confchg_fn = &globalConfigChange;

  //    QPID_LOG(notice, "Initializing CPG");
  cs_error_t err = cpg_initialize(&handle, &callbacks);
  int retries = 6; // @todo: make this configurable.
  while (err == CS_ERR_TRY_AGAIN && --retries) {
    LOG(WARNING)<< "cpg initialize retry " << retries;
    std::chrono::microseconds dura(5);
    std::this_thread::sleep_for(dura);
    err = cpg_initialize(&handle, &callbacks);
  }
  if (err != CS_OK) {
    LOG(ERROR)<< "cpg_initialize error, caused by " << error2str(err);
    return err;
  }
  if (CS_OK != cpg_context_set(handle, this)) {
    LOG(ERROR)<< "Cannot set CPG context";
    return err;
  }

  ready = true;
  return CS_OK;
}
示例#2
0
static void context_test (int sock)
{
	char response[100];
	char *cmp;

	cpg_context_set (cpg_handle, response);
	cpg_context_get (cpg_handle, (void**)&cmp);
	if (response != cmp) {
		snprintf (response, 100, "%s", FAIL_STR);
	}
	else {
		snprintf (response, 100, "%s", OK_STR);
	}
	send (sock, response, strlen (response), 0);
}
示例#3
0
int main (void)
{
    cpg_handle_t handle[INSTANCES];
    cs_error_t res;
    void *context[INSTANCES];
    int i, j;
    void *ctx;

    signal (SIGINT, sigintr_handler);
    for (i = 0; i < INSTANCES; i++) {
        res = cpg_initialize (&handle[i], &callbacks);
        if (res != CS_OK) {
            printf ("FAIL %d\n", res);
            exit (-1);
        }
    }

    for (j = 0; j < ITERATIONS; j++) {
        for (i = 0; i < INSTANCES; i++) {
            context[i] = malloc (20);
            res = cpg_context_set (handle[i], context[i]);
            if (res != CS_OK) {
                printf ("FAIL %d\n", res);
                exit (-1);
            }
        }

        for (i = 0; i < INSTANCES; i++) {
            res = cpg_context_get (handle[i], &ctx);
            if (res != CS_OK) {
                printf ("FAIL %d\n", res);
                exit (-1);
            }
            if (ctx != context[i]) {
                printf ("FAIL\n");
                exit (-1);
            }
            free (ctx);
        }
    }

    for (i = 0; i < INSTANCES; i++) {
        cpg_finalize (handle[i]);
    }

    printf ("PASS\n");
    return (0);
}
示例#4
0
static void context_test (int sock)
{
	char response[100];
	char *cmp;
	ssize_t rc;
	size_t send_len;

	cpg_context_set (cpg_handle, response);
	cpg_context_get (cpg_handle, (void**)&cmp);
	if (response != cmp) {
		snprintf (response, 100, "%s", FAIL_STR);
	}
	else {
		snprintf (response, 100, "%s", OK_STR);
	}
	send_len = strlen (response);
	rc = send (sock, response, send_len, 0);
	assert(rc == send_len);
}