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; } } }
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, ¤t_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; } } }
static void read_and_write_test_read_handler(grpc_exec_ctx *exec_ctx, void *data, bool success) { struct read_and_write_test_state *state = data; 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) { grpc_endpoint_read(exec_ctx, state->read_ep, &state->incoming, &state->done_read); } }
static void read_and_write_test_read_handler(grpc_exec_ctx *exec_ctx, void *data, grpc_error *error) { struct read_and_write_test_state *state = data; state->bytes_read += count_slices( state->incoming.slices, state->incoming.count, &state->current_read_data); if (state->bytes_read == state->target_bytes || error != GRPC_ERROR_NONE) { gpr_log(GPR_INFO, "Read handler done"); gpr_mu_lock(g_mu); state->read_done = 1 + (error == GRPC_ERROR_NONE); GRPC_LOG_IF_ERROR("pollset_kick", grpc_pollset_kick(g_pollset, NULL)); gpr_mu_unlock(g_mu); } else if (error == GRPC_ERROR_NONE) { grpc_endpoint_read(exec_ctx, state->read_ep, &state->incoming, &state->done_read); } }
static void read_cb(grpc_exec_ctx *exec_ctx, void *user_data, int success) { struct read_socket_state *state = (struct read_socket_state *)user_data; size_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, ¤t_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 { grpc_endpoint_read(exec_ctx, state->ep, &state->incoming, &state->read_cb); gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset)); } }
static void read_cb(grpc_exec_ctx *exec_ctx, void *user_data, grpc_error *error) { struct read_socket_state *state = (struct read_socket_state *)user_data; size_t read_bytes; int current_data; GPR_ASSERT(error == GRPC_ERROR_NONE); gpr_mu_lock(g_mu); current_data = state->read_bytes % 256; read_bytes = count_slices(state->incoming.slices, state->incoming.count, ¤t_data); state->read_bytes += read_bytes; gpr_log(GPR_INFO, "Read %" PRIuPTR " bytes of %" PRIuPTR, read_bytes, state->target_read_bytes); if (state->read_bytes >= state->target_read_bytes) { gpr_mu_unlock(g_mu); } else { grpc_endpoint_read(exec_ctx, state->ep, &state->incoming, &state->read_cb); gpr_mu_unlock(g_mu); } }