Пример #1
0
static void call_alarm(void *arg, int success) {
  grpc_call *call = arg;
  if (success) {
    if (call->is_client) {
      grpc_call_cancel_with_status(call, GRPC_STATUS_DEADLINE_EXCEEDED,
                                   "Deadline Exceeded");
    } else {
      grpc_call_cancel(call);
    }
  }
  grpc_call_internal_unref(call, 1);
}
Пример #2
0
void grpc_server_cancel_all_calls(grpc_server *server) {
  call_data *calld;
  grpc_call **calls;
  size_t call_count;
  size_t call_capacity;
  int is_first = 1;
  size_t i;

  gpr_mu_lock(&server->mu_call);

  GPR_ASSERT(server->shutdown);

  if (!server->lists[ALL_CALLS]) {
    gpr_mu_unlock(&server->mu_call);
    return;
  }

  call_capacity = 8;
  call_count = 0;
  calls = gpr_malloc(sizeof(grpc_call *) * call_capacity);

  for (calld = server->lists[ALL_CALLS];
       calld != server->lists[ALL_CALLS] || is_first;
       calld = calld->links[ALL_CALLS].next) {
    if (call_count == call_capacity) {
      call_capacity *= 2;
      calls = gpr_realloc(calls, sizeof(grpc_call *) * call_capacity);
    }
    calls[call_count++] = calld->call;
    GRPC_CALL_INTERNAL_REF(calld->call, "cancel_all");
    is_first = 0;
  }

  gpr_mu_unlock(&server->mu_call);

  for (i = 0; i < call_count; i++) {
    grpc_call_cancel_with_status(calls[i], GRPC_STATUS_UNAVAILABLE,
                                 "Unavailable");
    GRPC_CALL_INTERNAL_UNREF(calls[i], "cancel_all", 1);
  }

  gpr_free(calls);
}
Пример #3
0
GPR_EXPORT grpc_call_error GPR_CALLTYPE
grpcsharp_call_cancel_with_status(grpc_call *call, grpc_status_code status,
                                  const char *description) {
  return grpc_call_cancel_with_status(call, status, description, NULL);
}
Пример #4
0
grpc_call_error grpc_call_cancel(grpc_call *call, void *reserved) {
  GRPC_API_TRACE("grpc_call_cancel(call=%p, reserved=%p)", 2, (call, reserved));
  GPR_ASSERT(!reserved);
  return grpc_call_cancel_with_status(call, GRPC_STATUS_CANCELLED, "Cancelled",
                                      NULL);
}
Пример #5
0
static void simple_request_body(grpc_end2end_test_fixture f, size_t num_ops) {
  grpc_call *c;
  gpr_timespec deadline = five_seconds_time();
  cq_verifier *cqv = cq_verifier_create(f.cq);
  grpc_op ops[6];
  grpc_op *op;
  grpc_metadata_array initial_metadata_recv;
  grpc_metadata_array trailing_metadata_recv;
  grpc_status_code status;
  grpc_call_error error;
  char *details = NULL;
  size_t details_capacity = 0;

  gpr_log(GPR_DEBUG, "test with %" PRIuPTR " ops", num_ops);

  c = grpc_channel_create_call(f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq,
                               "/foo", "foo.test.google.fr:1234", deadline,
                               NULL);
  GPR_ASSERT(c);

  grpc_metadata_array_init(&initial_metadata_recv);
  grpc_metadata_array_init(&trailing_metadata_recv);

  memset(ops, 0, sizeof(ops));
  op = ops;
  op->op = GRPC_OP_RECV_STATUS_ON_CLIENT;
  op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv;
  op->data.recv_status_on_client.status = &status;
  op->data.recv_status_on_client.status_details = &details;
  op->data.recv_status_on_client.status_details_capacity = &details_capacity;
  op->flags = 0;
  op->reserved = NULL;
  op++;
  op->op = GRPC_OP_RECV_INITIAL_METADATA;
  op->data.recv_initial_metadata = &initial_metadata_recv;
  op->flags = 0;
  op->reserved = NULL;
  op++;
  op->op = GRPC_OP_SEND_INITIAL_METADATA;
  op->data.send_initial_metadata.count = 0;
  op->flags = 0;
  op->reserved = NULL;
  op++;
  op->op = GRPC_OP_SEND_CLOSE_FROM_CLIENT;
  op->flags = 0;
  op->reserved = NULL;
  op++;
  GPR_ASSERT(num_ops <= (size_t)(op - ops));
  error = grpc_call_start_batch(c, ops, num_ops, tag(1), NULL);
  GPR_ASSERT(GRPC_CALL_OK == error);

  grpc_call_cancel_with_status(c, GRPC_STATUS_UNIMPLEMENTED, "xyz", NULL);

  CQ_EXPECT_COMPLETION(cqv, tag(1), 1);
  cq_verify(cqv);

  GPR_ASSERT(status == GRPC_STATUS_UNIMPLEMENTED);
  GPR_ASSERT(0 == strcmp(details, "xyz"));

  gpr_free(details);
  grpc_metadata_array_destroy(&initial_metadata_recv);
  grpc_metadata_array_destroy(&trailing_metadata_recv);

  grpc_call_destroy(c);

  cq_verifier_destroy(cqv);
}
Пример #6
0
grpc_call_error grpc_call_cancel(grpc_call *call) {
  return grpc_call_cancel_with_status(call, GRPC_STATUS_CANCELLED, "Cancelled");
}