Exemplo n.º 1
0
static void tcp_handle_write(grpc_exec_ctx *exec_ctx, void *arg /* grpc_tcp */,
                             grpc_error *error) {
  grpc_tcp *tcp = (grpc_tcp *)arg;
  grpc_closure *cb;

  if (error != GRPC_ERROR_NONE) {
    cb = tcp->write_cb;
    tcp->write_cb = NULL;
    cb->cb(exec_ctx, cb->cb_arg, error);
    TCP_UNREF(exec_ctx, tcp, "write");
    return;
  }

  if (!tcp_flush(tcp, &error)) {
    if (grpc_tcp_trace) {
      gpr_log(GPR_DEBUG, "write: delayed");
    }
    grpc_fd_notify_on_write(exec_ctx, tcp->em_fd, &tcp->write_closure);
  } else {
    cb = tcp->write_cb;
    tcp->write_cb = NULL;
    if (grpc_tcp_trace) {
      const char *str = grpc_error_string(error);
      gpr_log(GPR_DEBUG, "write: %s", str);
      grpc_error_free_string(str);
    }

    grpc_closure_run(exec_ctx, cb, error);
    TCP_UNREF(exec_ctx, tcp, "write");
  }
}
Exemplo n.º 2
0
static void reclaimer_cb(grpc_exec_ctx *exec_ctx, void *args,
                         grpc_error *error) {
  GPR_ASSERT(error == GRPC_ERROR_NONE);
  reclaimer_args *a = args;
  grpc_resource_user_free(exec_ctx, a->resource_user, a->size);
  grpc_resource_user_finish_reclamation(exec_ctx, a->resource_user);
  grpc_closure_run(exec_ctx, a->then, GRPC_ERROR_NONE);
  gpr_free(a);
}
Exemplo n.º 3
0
static void ru_allocated_slices(grpc_exec_ctx *exec_ctx, void *arg,
                                grpc_error *error) {
  grpc_resource_user_slice_allocator *slice_allocator = arg;
  if (error == GRPC_ERROR_NONE) {
    for (size_t i = 0; i < slice_allocator->count; i++) {
      grpc_slice_buffer_add_indexed(
          slice_allocator->dest, ru_slice_create(slice_allocator->resource_user,
                                                 slice_allocator->length));
    }
  }
  grpc_closure_run(exec_ctx, &slice_allocator->on_done, GRPC_ERROR_REF(error));
}
Exemplo n.º 4
0
static void hc_on_recv_trailing_metadata(grpc_exec_ctx *exec_ctx,
                                         void *user_data, grpc_error *error) {
  grpc_call_element *elem = user_data;
  call_data *calld = elem->call_data;
  client_recv_filter_args a;
  a.elem = elem;
  a.exec_ctx = exec_ctx;
  grpc_metadata_batch_filter(calld->recv_trailing_metadata, client_recv_filter,
                             &a);
  grpc_closure_run(exec_ctx, calld->on_done_recv_trailing_metadata,
                   GRPC_ERROR_REF(error));
}
Exemplo n.º 5
0
/* returns true if reclamation is proceeding */
static bool rq_reclaim(grpc_exec_ctx *exec_ctx,
                       grpc_resource_quota *resource_quota, bool destructive) {
  if (resource_quota->reclaiming) return true;
  grpc_rulist list = destructive ? GRPC_RULIST_RECLAIMER_DESTRUCTIVE
                                 : GRPC_RULIST_RECLAIMER_BENIGN;
  grpc_resource_user *resource_user = rulist_pop_head(resource_quota, list);
  if (resource_user == NULL) return false;
  if (grpc_resource_quota_trace) {
    gpr_log(GPR_DEBUG, "RQ %s %s: initiate %s reclamation",
            resource_quota->name, resource_user->name,
            destructive ? "destructive" : "benign");
  }
  resource_quota->reclaiming = true;
  grpc_resource_quota_internal_ref(resource_quota);
  grpc_closure *c = resource_user->reclaimers[destructive];
  resource_user->reclaimers[destructive] = NULL;
  grpc_closure_run(exec_ctx, c, GRPC_ERROR_NONE);
  return true;
}
Exemplo n.º 6
0
static void call_read_cb(grpc_exec_ctx *exec_ctx, grpc_tcp *tcp,
                         grpc_error *error) {
  grpc_closure *cb = tcp->read_cb;

  if (grpc_tcp_trace) {
    size_t i;
    const char *str = grpc_error_string(error);
    gpr_log(GPR_DEBUG, "read: error=%s", str);
    grpc_error_free_string(str);
    for (i = 0; i < tcp->incoming_buffer->count; i++) {
      char *dump = grpc_dump_slice(tcp->incoming_buffer->slices[i],
                                   GPR_DUMP_HEX | GPR_DUMP_ASCII);
      gpr_log(GPR_DEBUG, "READ %p (peer=%s): %s", tcp, tcp->peer_string, dump);
      gpr_free(dump);
    }
  }

  tcp->read_cb = NULL;
  tcp->incoming_buffer = NULL;
  grpc_closure_run(exec_ctx, cb, error);
}
Exemplo n.º 7
0
static void unused_reclaimer_cb(grpc_exec_ctx *exec_ctx, void *arg,
                                grpc_error *error) {
  GPR_ASSERT(error == GRPC_ERROR_CANCELLED);
  grpc_closure_run(exec_ctx, arg, GRPC_ERROR_NONE);
}