当前位置: 首页>>代码示例>>C++>>正文


C++ GRPC_POLLSET_MU函数代码示例

本文整理汇总了C++中GRPC_POLLSET_MU函数的典型用法代码示例。如果您正苦于以下问题:C++ GRPC_POLLSET_MU函数的具体用法?C++ GRPC_POLLSET_MU怎么用?C++ GRPC_POLLSET_MU使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了GRPC_POLLSET_MU函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: pollset_kick_locked

static void pollset_kick_locked(grpc_fd_watcher *watcher) {
  gpr_mu_lock(GRPC_POLLSET_MU(watcher->pollset));
  GPR_ASSERT(watcher->worker);
  grpc_pollset_kick_ext(watcher->pollset, watcher->worker,
                        GRPC_POLLSET_REEVALUATE_POLLING_ON_WAKEUP);
  gpr_mu_unlock(GRPC_POLLSET_MU(watcher->pollset));
}
开发者ID:peipeiguo,项目名称:grpc,代码行数:7,代码来源:fd_posix.c

示例2: grpc_pollset_init

char *grpc_test_fetch_oauth2_token_with_credentials(
    grpc_call_credentials *creds) {
  oauth2_request request;
  grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
  grpc_closure do_nothing_closure;
  grpc_auth_metadata_context null_ctx = {"", "", NULL, NULL};

  grpc_pollset_init(&request.pollset);
  request.is_done = 0;

  grpc_closure_init(&do_nothing_closure, do_nothing, NULL);

  grpc_call_credentials_get_request_metadata(&exec_ctx, creds, &request.pollset,
                                             null_ctx, on_oauth2_response,
                                             &request);

  grpc_exec_ctx_finish(&exec_ctx);

  gpr_mu_lock(GRPC_POLLSET_MU(&request.pollset));
  while (!request.is_done) {
    grpc_pollset_worker *worker = NULL;
    grpc_pollset_work(&exec_ctx, &request.pollset, &worker,
                      gpr_now(GPR_CLOCK_MONOTONIC),
                      gpr_inf_future(GPR_CLOCK_MONOTONIC));
  }
  gpr_mu_unlock(GRPC_POLLSET_MU(&request.pollset));

  grpc_pollset_shutdown(&exec_ctx, &request.pollset, &do_nothing_closure);
  grpc_exec_ctx_finish(&exec_ctx);
  grpc_pollset_destroy(&request.pollset);
  return request.token;
}
开发者ID:sanatgersappa,项目名称:grpc,代码行数:32,代码来源:oauth2_utils.c

示例3: test_get

static void test_get(int port) {
  grpc_httpcli_request req;
  char *host;
  grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;

  g_done = 0;
  gpr_log(GPR_INFO, "test_get");

  gpr_asprintf(&host, "localhost:%d", port);
  gpr_log(GPR_INFO, "requesting from %s", host);

  memset(&req, 0, sizeof(req));
  req.host = host;
  req.path = "/get";
  req.handshaker = &grpc_httpcli_plaintext;

  grpc_httpcli_get(&exec_ctx, &g_context, &g_pollset, &req, n_seconds_time(15),
                   on_finish, (void *)42);
  gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset));
  while (!g_done) {
    grpc_pollset_worker worker;
    grpc_pollset_work(&exec_ctx, &g_pollset, &worker,
                      gpr_now(GPR_CLOCK_MONOTONIC), n_seconds_time(20));
    gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset));
    grpc_exec_ctx_finish(&exec_ctx);
    gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset));
  }
  gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset));
  gpr_free(host);
}
开发者ID:xianglinghui,项目名称:grpc,代码行数:30,代码来源:httpcli_test.c

示例4: test_post

static void test_post(int port) {
  grpc_httpcli_request req;
  char *host;
  grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;

  g_done = 0;
  gpr_log(GPR_INFO, "test_post");

  gpr_asprintf(&host, "localhost:%d", port);
  gpr_log(GPR_INFO, "posting to %s", host);

  memset(&req, 0, sizeof(req));
  req.host = host;
  req.ssl_host_override = "foo.test.google.fr";
  req.path = "/post";
  req.handshaker = &grpc_httpcli_ssl;

  grpc_httpcli_post(&exec_ctx, &g_context, &g_pollset, &req, "hello", 5,
                    n_seconds_time(15), on_finish, (void *)42);
  gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset));
  while (!g_done) {
    grpc_pollset_worker *worker = NULL;
    grpc_pollset_work(&exec_ctx, &g_pollset, &worker,
                      gpr_now(GPR_CLOCK_MONOTONIC), n_seconds_time(20));
    gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset));
    grpc_exec_ctx_finish(&exec_ctx);
    gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset));
  }
  gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset));
  gpr_free(host);
}
开发者ID:sanatgersappa,项目名称:grpc,代码行数:31,代码来源:httpscli_test.c

示例5: read_and_write_test_read_handler

static void read_and_write_test_read_handler(void *data, gpr_slice *slices,
        size_t nslices,
        grpc_endpoint_cb_status error) {
    struct read_and_write_test_state *state = data;
    GPR_ASSERT(error != GRPC_ENDPOINT_CB_ERROR);
    if (error == GRPC_ENDPOINT_CB_SHUTDOWN) {
        gpr_log(GPR_INFO, "Read handler shutdown");
        gpr_mu_lock(GRPC_POLLSET_MU(g_pollset));
        state->read_done = 1;
        grpc_pollset_kick(g_pollset);
        gpr_mu_unlock(GRPC_POLLSET_MU(g_pollset));
        return;
    }

    state->bytes_read +=
        count_and_unref_slices(slices, nslices, &state->current_read_data);
    if (state->bytes_read == state->target_bytes) {
        gpr_log(GPR_INFO, "Read handler done");
        gpr_mu_lock(GRPC_POLLSET_MU(g_pollset));
        state->read_done = 1;
        grpc_pollset_kick(g_pollset);
        gpr_mu_unlock(GRPC_POLLSET_MU(g_pollset));
    } else {
        grpc_endpoint_notify_on_read(state->read_ep,
                                     read_and_write_test_read_handler, data);
    }
}
开发者ID:rootusr,项目名称:grpc,代码行数:27,代码来源:endpoint_tests.c

示例6: drain_socket_blocking

void drain_socket_blocking(int fd, size_t num_bytes, size_t read_size) {
  unsigned char *buf = malloc(read_size);
  ssize_t bytes_read;
  size_t bytes_left = num_bytes;
  int flags;
  int current = 0;
  int i;

  flags = fcntl(fd, F_GETFL, 0);
  GPR_ASSERT(fcntl(fd, F_SETFL, flags & ~O_NONBLOCK) == 0);

  for (;;) {
    grpc_pollset_worker worker;
    gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset));
    grpc_pollset_work(&g_pollset, &worker, gpr_now(GPR_CLOCK_MONOTONIC),
                      GRPC_TIMEOUT_MILLIS_TO_DEADLINE(10));
    gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset));
    do {
      bytes_read =
          read(fd, buf, bytes_left > read_size ? read_size : bytes_left);
    } while (bytes_read < 0 && errno == EINTR);
    GPR_ASSERT(bytes_read >= 0);
    for (i = 0; i < bytes_read; ++i) {
      GPR_ASSERT(buf[i] == current);
      current = (current + 1) % 256;
    }
    bytes_left -= bytes_read;
    if (bytes_left == 0) break;
  }
  flags = fcntl(fd, F_GETFL, 0);
  GPR_ASSERT(fcntl(fd, F_SETFL, flags | O_NONBLOCK) == 0);

  gpr_free(buf);
}
开发者ID:larsonmpdx,项目名称:grpc,代码行数:34,代码来源:tcp_posix_test.c

示例7: grpc_cq_end_op

/* Queue a GRPC_OP_COMPLETED operation */
void grpc_cq_end_op(grpc_completion_queue *cc, void *tag, int success,
                    void (*done)(void *done_arg, grpc_cq_completion *storage),
                    void *done_arg, grpc_cq_completion *storage) {
  int shutdown;

  storage->tag = tag;
  storage->done = done;
  storage->done_arg = done_arg;
  storage->next =
      ((gpr_uintptr)&cc->completed_head) | ((gpr_uintptr)(success != 0));

  gpr_mu_lock(GRPC_POLLSET_MU(&cc->pollset));
  shutdown = gpr_unref(&cc->pending_events);
  if (!shutdown) {
    cc->completed_tail->next =
        ((gpr_uintptr)storage) | (1u & (gpr_uintptr)cc->completed_tail->next);
    cc->completed_tail = storage;
    grpc_pollset_kick(&cc->pollset);
    gpr_mu_unlock(GRPC_POLLSET_MU(&cc->pollset));
  } else {
    cc->completed_tail->next =
        ((gpr_uintptr)storage) | (1u & (gpr_uintptr)cc->completed_tail->next);
    cc->completed_tail = storage;
    GPR_ASSERT(!cc->shutdown);
    GPR_ASSERT(cc->shutdown_called);
    cc->shutdown = 1;
    gpr_mu_unlock(GRPC_POLLSET_MU(&cc->pollset));
    grpc_pollset_shutdown(&cc->pollset, on_pollset_destroy_done, cc);
  }
}
开发者ID:rootusr,项目名称:grpc,代码行数:31,代码来源:completion_queue.c

示例8: grpc_cq_hack_spin_pollset

void grpc_cq_hack_spin_pollset(grpc_completion_queue *cc) {
  gpr_mu_lock(GRPC_POLLSET_MU(&cc->pollset));
  grpc_pollset_kick(&cc->pollset);
  grpc_pollset_work(&cc->pollset,
                    gpr_time_add(gpr_now(), gpr_time_from_millis(100)));
  gpr_mu_unlock(GRPC_POLLSET_MU(&cc->pollset));
}
开发者ID:AddictXQ,项目名称:grpc,代码行数:7,代码来源:completion_queue.c

示例9: grpc_pollset_init

static grpc_connected_subchannel *connect_subchannel(grpc_subchannel *c) {
  grpc_pollset pollset;
  grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
  grpc_pollset_init(&pollset);
  grpc_pollset_set_init(&g_interested_parties);
  grpc_pollset_set_add_pollset(&exec_ctx, &g_interested_parties, &pollset);
  grpc_subchannel_notify_on_state_change(&exec_ctx, c, &g_interested_parties,
                                         &g_state,
                                         grpc_closure_create(state_changed, c));
  grpc_exec_ctx_flush(&exec_ctx);
  gpr_mu_lock(GRPC_POLLSET_MU(&pollset));
  while (g_state != GRPC_CHANNEL_READY) {
    grpc_pollset_worker worker;
    grpc_pollset_work(&exec_ctx, &pollset, &worker,
                      gpr_now(GPR_CLOCK_MONOTONIC),
                      GRPC_TIMEOUT_SECONDS_TO_DEADLINE(1));
    gpr_mu_unlock(GRPC_POLLSET_MU(&pollset));
    grpc_exec_ctx_flush(&exec_ctx);
    gpr_mu_lock(GRPC_POLLSET_MU(&pollset));
  }
  grpc_pollset_shutdown(&exec_ctx, &pollset,
                        grpc_closure_create(destroy_pollset, &pollset));
  grpc_pollset_set_destroy(&g_interested_parties);
  gpr_mu_unlock(GRPC_POLLSET_MU(&pollset));
  grpc_exec_ctx_finish(&exec_ctx);
  return grpc_subchannel_get_connected_subchannel(c);
}
开发者ID:An-mol,项目名称:grpc,代码行数:27,代码来源:h2_uchannel.c

示例10: gpr_mu_lock

grpc_event *grpc_completion_queue_pluck(grpc_completion_queue *cc, void *tag,
                                        gpr_timespec deadline) {
  event *ev = NULL;

  gpr_mu_lock(GRPC_POLLSET_MU(&cc->pollset));
  for (;;) {
    if ((ev = pluck_event(cc, tag))) {
      break;
    }
    if (cc->shutdown) {
      ev = create_shutdown_event();
      break;
    }
    if (cc->allow_polling && grpc_pollset_work(&cc->pollset, deadline)) {
      continue;
    }
    if (gpr_cv_wait(GRPC_POLLSET_CV(&cc->pollset),
                    GRPC_POLLSET_MU(&cc->pollset), deadline)) {
      gpr_mu_unlock(GRPC_POLLSET_MU(&cc->pollset));
      return NULL;
    }
  }
  gpr_mu_unlock(GRPC_POLLSET_MU(&cc->pollset));
  GRPC_SURFACE_TRACE_RETURNED_EVENT(cc, &ev->base);
  return &ev->base;
}
开发者ID:AddictXQ,项目名称:grpc,代码行数:26,代码来源:completion_queue.c

示例11: read_and_write_test_read_handler

static void read_and_write_test_read_handler(void *data, int success) {
  struct read_and_write_test_state *state = data;

loop:
  state->bytes_read += count_slices(
      state->incoming.slices, state->incoming.count, &state->current_read_data);
  if (state->bytes_read == state->target_bytes || !success) {
    gpr_log(GPR_INFO, "Read handler done");
    gpr_mu_lock(GRPC_POLLSET_MU(g_pollset));
    state->read_done = 1 + success;
    grpc_pollset_kick(g_pollset, NULL);
    gpr_mu_unlock(GRPC_POLLSET_MU(g_pollset));
  } else if (success) {
    switch (grpc_endpoint_read(state->read_ep, &state->incoming,
                               &state->done_read)) {
      case GRPC_ENDPOINT_ERROR:
        success = 0;
        goto loop;
      case GRPC_ENDPOINT_DONE:
        success = 1;
        goto loop;
      case GRPC_ENDPOINT_PENDING:
        break;
    }
  }
}
开发者ID:JoeWoo,项目名称:grpc,代码行数:26,代码来源:endpoint_tests.c

示例12: must_succeed

static void must_succeed(grpc_exec_ctx *exec_ctx, void *p, int success) {
  GPR_ASSERT(success == 1);
  gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset));
  *(int *)p = 1;
  grpc_pollset_kick(&g_pollset, NULL);
  gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset));
}
开发者ID:xianglinghui,项目名称:grpc,代码行数:7,代码来源:workqueue_test.c

示例13: read_and_write_test_write_handler

static void read_and_write_test_write_handler(grpc_exec_ctx *exec_ctx,
                                              void *data, bool success) {
  struct read_and_write_test_state *state = data;
  gpr_slice *slices = NULL;
  size_t nslices;

  if (success) {
    state->bytes_written += state->current_write_size;
    if (state->target_bytes - state->bytes_written <
        state->current_write_size) {
      state->current_write_size = state->target_bytes - state->bytes_written;
    }
    if (state->current_write_size != 0) {
      slices = allocate_blocks(state->current_write_size, 8192, &nslices,
                               &state->current_write_data);
      gpr_slice_buffer_reset_and_unref(&state->outgoing);
      gpr_slice_buffer_addn(&state->outgoing, slices, nslices);
      grpc_endpoint_write(exec_ctx, state->write_ep, &state->outgoing,
                          &state->done_write);
      free(slices);
      return;
    }
  }

  gpr_log(GPR_INFO, "Write handler done");
  gpr_mu_lock(GRPC_POLLSET_MU(g_pollset));
  state->write_done = 1 + success;
  grpc_pollset_kick(g_pollset, NULL);
  gpr_mu_unlock(GRPC_POLLSET_MU(g_pollset));
}
开发者ID:An-mol,项目名称:grpc,代码行数:30,代码来源:endpoint_tests.c

示例14: read_cb

static void read_cb(void *user_data, int success) {
  struct read_socket_state *state = (struct read_socket_state *)user_data;
  ssize_t read_bytes;
  int current_data;

  GPR_ASSERT(success);

  gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset));
  current_data = state->read_bytes % 256;
  read_bytes = count_slices(state->incoming.slices, state->incoming.count,
                            &current_data);
  state->read_bytes += read_bytes;
  gpr_log(GPR_INFO, "Read %d bytes of %d", read_bytes,
          state->target_read_bytes);
  if (state->read_bytes >= state->target_read_bytes) {
    gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset));
  } else {
    switch (grpc_endpoint_read(state->ep, &state->incoming, &state->read_cb)) {
      case GRPC_ENDPOINT_DONE:
        gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset));
        read_cb(user_data, 1);
        break;
      case GRPC_ENDPOINT_ERROR:
        gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset));
        read_cb(user_data, 0);
        break;
      case GRPC_ENDPOINT_PENDING:
        gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset));
        break;
    }
  }
}
开发者ID:larsonmpdx,项目名称:grpc,代码行数:32,代码来源:tcp_posix_test.c

示例15: got_port_from_server

static void got_port_from_server(grpc_exec_ctx *exec_ctx, void *arg,
                                 const grpc_httpcli_response *response) {
  size_t i;
  int port = 0;
  portreq *pr = arg;

  if (!response || response->status != 200) {
    grpc_httpcli_request req;
    memset(&req, 0, sizeof(req));
    GPR_ASSERT(pr->retries < 10);
    pr->retries++;
    req.host = pr->server;
    req.path = "/get";
    gpr_log(GPR_DEBUG, "failed port pick from server: retrying");
    sleep(1);
    grpc_httpcli_get(exec_ctx, pr->ctx, &pr->pollset, &req,
                     GRPC_TIMEOUT_SECONDS_TO_DEADLINE(10), got_port_from_server,
                     pr);
    return;
  }
  GPR_ASSERT(response);
  GPR_ASSERT(response->status == 200);
  for (i = 0; i < response->body_length; i++) {
    GPR_ASSERT(response->body[i] >= '0' && response->body[i] <= '9');
    port = port * 10 + response->body[i] - '0';
  }
  GPR_ASSERT(port > 1024);
  gpr_mu_lock(GRPC_POLLSET_MU(&pr->pollset));
  pr->port = port;
  grpc_pollset_kick(&pr->pollset, NULL);
  gpr_mu_unlock(GRPC_POLLSET_MU(&pr->pollset));
}
开发者ID:spietz-handy,项目名称:grpc,代码行数:32,代码来源:port_posix.c


注:本文中的GRPC_POLLSET_MU函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。