void grpc_event_finish(grpc_event *base) { event *ev = (event *)base; ev->on_finish(ev->on_finish_user_data, GRPC_OP_OK); if (ev->base.call) { grpc_call_internal_unref(ev->base.call, 1); } gpr_free(ev); }
static void finish_send_op(grpc_call *call, grpc_ioreq_op op, write_state ws, grpc_op_error error) { lock(call); finish_ioreq_op(call, op, error); call->sending = 0; call->write_state = ws; unlock(call); grpc_call_internal_unref(call, 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); }
void grpc_call_destroy(grpc_call *c) { int cancel; lock(c); if (c->have_alarm) { grpc_alarm_cancel(&c->alarm); c->have_alarm = 0; } cancel = c->read_state != READ_STATE_STREAM_CLOSED; unlock(c); if (cancel) grpc_call_cancel(c); grpc_call_internal_unref(c, 1); }
static void unlock(grpc_call *call) { send_action sa = SEND_NOTHING; completed_request completed_requests[GRPC_IOREQ_OP_COUNT]; int completing_requests = 0; int need_more_data = call->need_more_data && (call->write_state >= WRITE_STATE_STARTED || !call->is_client); int i; if (need_more_data) { call->need_more_data = 0; } if (!call->completing && call->num_completed_requests != 0) { completing_requests = call->num_completed_requests; memcpy(completed_requests, call->completed_requests, sizeof(completed_requests)); call->num_completed_requests = 0; call->completing = 1; grpc_call_internal_ref(call); } if (!call->sending) { sa = choose_send_action(call); if (sa != SEND_NOTHING) { call->sending = 1; grpc_call_internal_ref(call); } } gpr_mu_unlock(&call->mu); if (need_more_data) { request_more_data(call); } if (sa != SEND_NOTHING) { enact_send_action(call, sa); } if (completing_requests > 0) { for (i = 0; i < completing_requests; i++) { completed_requests[i].on_complete(call, completed_requests[i].status, completed_requests[i].user_data); } lock(call); call->completing = 0; unlock(call); grpc_call_internal_unref(call, 0); } }
void grpc_call_stream_closed(grpc_call_element *elem) { grpc_call *call = CALL_FROM_TOP_ELEM(elem); set_read_state(call, READ_STATE_STREAM_CLOSED); grpc_call_internal_unref(call, 0); }