Exemplo n.º 1
0
void grpc_chttp2_list_add_check_read_ops(
    grpc_exec_ctx *exec_ctx, grpc_chttp2_transport_global *transport_global,
    grpc_chttp2_stream_global *stream_global) {
  grpc_chttp2_transport *t = TRANSPORT_FROM_GLOBAL(transport_global);
  if (!t->executor.check_read_ops_scheduled) {
    grpc_combiner_execute_finally(exec_ctx, t->executor.combiner,
                                  &t->initiate_read_flush_locked,
                                  GRPC_ERROR_NONE, false);
    t->executor.check_read_ops_scheduled = true;
  }
  stream_list_add(TRANSPORT_FROM_GLOBAL(transport_global),
                  STREAM_FROM_GLOBAL(stream_global),
                  GRPC_CHTTP2_LIST_CHECK_READ_OPS);
}
Exemplo n.º 2
0
void grpc_chttp2_list_add_read_write_state_changed(
    grpc_chttp2_transport_global *transport_global,
    grpc_chttp2_stream_global *stream_global) {
  stream_list_add(TRANSPORT_FROM_GLOBAL(transport_global),
                  STREAM_FROM_GLOBAL(stream_global),
                  GRPC_CHTTP2_LIST_READ_WRITE_STATE_CHANGED);
}
Exemplo n.º 3
0
void grpc_chttp2_list_remove_incoming_window_updated(
    grpc_chttp2_transport_global *transport_global,
    grpc_chttp2_stream_global *stream_global) {
  stream_list_maybe_remove(TRANSPORT_FROM_GLOBAL(transport_global),
                           STREAM_FROM_GLOBAL(stream_global),
                           GRPC_CHTTP2_LIST_INCOMING_WINDOW_UPDATED);
}
Exemplo n.º 4
0
void grpc_chttp2_list_remove_stalled_by_transport(
    grpc_chttp2_transport_global *transport_global,
    grpc_chttp2_stream_global *stream_global) {
  stream_list_maybe_remove(TRANSPORT_FROM_GLOBAL(transport_global),
                           STREAM_FROM_GLOBAL(stream_global),
                           GRPC_CHTTP2_LIST_STALLED_BY_TRANSPORT);
}
Exemplo n.º 5
0
void grpc_chttp2_list_add_waiting_for_concurrency(
    grpc_chttp2_transport_global *transport_global,
    grpc_chttp2_stream_global *stream_global) {
  stream_list_add(TRANSPORT_FROM_GLOBAL(transport_global),
                  STREAM_FROM_GLOBAL(stream_global),
                  GRPC_CHTTP2_LIST_WAITING_FOR_CONCURRENCY);
}
Exemplo n.º 6
0
bool grpc_chttp2_list_remove_writable_stream(
    grpc_chttp2_transport_global *transport_global,
    grpc_chttp2_stream_global *stream_global) {
  return stream_list_maybe_remove(TRANSPORT_FROM_GLOBAL(transport_global),
                                  STREAM_FROM_GLOBAL(stream_global),
                                  GRPC_CHTTP2_LIST_WRITABLE);
}
Exemplo n.º 7
0
void grpc_chttp2_list_add_writable_stream(
    grpc_chttp2_transport_global *transport_global,
    grpc_chttp2_stream_global *stream_global) {
  GPR_ASSERT(stream_global->id != 0);
  stream_list_add(TRANSPORT_FROM_GLOBAL(transport_global),
                  STREAM_FROM_GLOBAL(stream_global), GRPC_CHTTP2_LIST_WRITABLE);
}
Exemplo n.º 8
0
void grpc_chttp2_list_add_closed_waiting_for_writing(
    grpc_chttp2_transport_global *transport_global,
    grpc_chttp2_stream_global *stream_global) {
  stream_list_add(TRANSPORT_FROM_GLOBAL(transport_global),
                  STREAM_FROM_GLOBAL(stream_global),
                  GRPC_CHTTP2_LIST_CLOSED_WAITING_FOR_WRITING);
}
Exemplo n.º 9
0
void grpc_chttp2_list_remove_writable_window_update_stream(
    grpc_chttp2_transport_global *transport_global,
    grpc_chttp2_stream_global *stream_global) {
  stream_list_maybe_remove(TRANSPORT_FROM_GLOBAL(transport_global),
                           STREAM_FROM_GLOBAL(stream_global),
                           GRPC_CHTTP2_LIST_WRITABLE_WINDOW_UPDATE);
}
Exemplo n.º 10
0
void grpc_chttp2_list_add_check_read_ops(
    grpc_chttp2_transport_global *transport_global,
    grpc_chttp2_stream_global *stream_global) {
  stream_list_add(TRANSPORT_FROM_GLOBAL(transport_global),
                  STREAM_FROM_GLOBAL(stream_global),
                  GRPC_CHTTP2_LIST_CHECK_READ_OPS);
}
Exemplo n.º 11
0
bool grpc_chttp2_list_remove_check_read_ops(
    grpc_chttp2_transport_global *transport_global,
    grpc_chttp2_stream_global *stream_global) {
  return stream_list_maybe_remove(TRANSPORT_FROM_GLOBAL(transport_global),
                                  STREAM_FROM_GLOBAL(stream_global),
                                  GRPC_CHTTP2_LIST_CHECK_READ_OPS);
}
Exemplo n.º 12
0
void grpc_chttp2_list_add_unannounced_incoming_window_available(
    grpc_chttp2_transport_global *transport_global,
    grpc_chttp2_stream_global *stream_global) {
  GPR_ASSERT(stream_global->id != 0);
  stream_list_add(TRANSPORT_FROM_GLOBAL(transport_global),
                  STREAM_FROM_GLOBAL(stream_global),
                  GRPC_CHTTP2_LIST_UNANNOUNCED_INCOMING_WINDOW_AVAILABLE);
}
Exemplo n.º 13
0
void grpc_chttp2_list_remove_unannounced_incoming_window_available(
    grpc_chttp2_transport_global *transport_global,
    grpc_chttp2_stream_global *stream_global) {
  stream_list_maybe_remove(
      TRANSPORT_FROM_GLOBAL(transport_global),
      STREAM_FROM_GLOBAL(stream_global),
      GRPC_CHTTP2_LIST_UNANNOUNCED_INCOMING_WINDOW_AVAILABLE);
}
Exemplo n.º 14
0
static void perform_op_locked(grpc_chttp2_transport_global *transport_global,
                              grpc_chttp2_stream_global *stream_global,
                              grpc_transport_op *op) {
  if (op->cancel_with_status != GRPC_STATUS_OK) {
    cancel_from_api(transport_global, stream_global, op->cancel_with_status);
  }

  if (op->send_ops) {
    GPR_ASSERT(stream_global->outgoing_sopb == NULL);
    stream_global->send_done_closure = op->on_done_send;
    if (!stream_global->cancelled) {
      stream_global->outgoing_sopb = op->send_ops;
      if (op->is_last_send &&
          stream_global->write_state == GRPC_WRITE_STATE_OPEN) {
        stream_global->write_state = GRPC_WRITE_STATE_QUEUED_CLOSE;
      }
      if (stream_global->id == 0) {
        GRPC_CHTTP2_IF_TRACING(gpr_log(
            GPR_DEBUG,
            "HTTP:%s: New grpc_chttp2_stream %p waiting for concurrency",
            transport_global->is_client ? "CLI" : "SVR", stream_global));
        grpc_chttp2_list_add_waiting_for_concurrency(transport_global,
                                                     stream_global);
        maybe_start_some_streams(transport_global);
      } else if (stream_global->outgoing_window > 0) {
        grpc_chttp2_list_add_writable_stream(transport_global, stream_global);
      }
    } else {
      grpc_sopb_reset(op->send_ops);
      grpc_chttp2_schedule_closure(transport_global,
                                   stream_global->send_done_closure, 0);
    }
  }

  if (op->recv_ops) {
    GPR_ASSERT(stream_global->publish_sopb == NULL);
    GPR_ASSERT(stream_global->published_state != GRPC_STREAM_CLOSED);
    stream_global->recv_done_closure = op->on_done_recv;
    stream_global->publish_sopb = op->recv_ops;
    stream_global->publish_sopb->nops = 0;
    stream_global->publish_state = op->recv_state;
    grpc_chttp2_incoming_metadata_live_op_buffer_end(
        &stream_global->outstanding_metadata);
    grpc_chttp2_list_add_read_write_state_changed(transport_global,
                                                  stream_global);
    grpc_chttp2_list_add_writable_window_update_stream(transport_global,
                                                       stream_global);
  }

  if (op->bind_pollset) {
    add_to_pollset_locked(TRANSPORT_FROM_GLOBAL(transport_global),
                          op->bind_pollset);
  }

  if (op->on_consumed) {
    grpc_chttp2_schedule_closure(transport_global, op->on_consumed, 1);
  }
}
Exemplo n.º 15
0
int grpc_chttp2_list_pop_cancelled_waiting_for_writing(
    grpc_chttp2_transport_global *transport_global,
    grpc_chttp2_stream_global **stream_global) {
  grpc_chttp2_stream *stream;
  int r = stream_list_pop(TRANSPORT_FROM_GLOBAL(transport_global), &stream,
                          GRPC_CHTTP2_LIST_CANCELLED_WAITING_FOR_WRITING);
  *stream_global = &stream->global;
  return r;
}
Exemplo n.º 16
0
int grpc_chttp2_list_pop_writable_window_update_stream(
    grpc_chttp2_transport_global *transport_global,
    grpc_chttp2_stream_global **stream_global) {
  grpc_chttp2_stream *stream;
  int r = stream_list_pop(TRANSPORT_FROM_GLOBAL(transport_global), &stream,
                          GRPC_CHTTP2_LIST_WRITABLE_WINDOW_UPDATE);
  *stream_global = &stream->global;
  return r;
}
Exemplo n.º 17
0
int grpc_chttp2_list_pop_closed_waiting_for_parsing(
    grpc_chttp2_transport_global *transport_global,
    grpc_chttp2_stream_global **stream_global) {
  grpc_chttp2_stream *stream;
  int r = stream_list_pop(TRANSPORT_FROM_GLOBAL(transport_global), &stream,
                          GRPC_CHTTP2_LIST_CLOSED_WAITING_FOR_PARSING);
  *stream_global = &stream->global;
  return r;
}
Exemplo n.º 18
0
int grpc_chttp2_list_pop_waiting_for_concurrency(
    grpc_chttp2_transport_global *transport_global,
    grpc_chttp2_stream_global **stream_global) {
  grpc_chttp2_stream *stream;
  int r = stream_list_pop(TRANSPORT_FROM_GLOBAL(transport_global), &stream,
                          GRPC_CHTTP2_LIST_WAITING_FOR_CONCURRENCY);
  *stream_global = &stream->global;
  return r;
}
Exemplo n.º 19
0
int grpc_chttp2_list_pop_read_write_state_changed(
    grpc_chttp2_transport_global *transport_global,
    grpc_chttp2_stream_global **stream_global) {
  grpc_chttp2_stream *stream;
  int r = stream_list_pop(TRANSPORT_FROM_GLOBAL(transport_global), &stream,
                          GRPC_CHTTP2_LIST_READ_WRITE_STATE_CHANGED);
  *stream_global = &stream->global;
  return r;
}
Exemplo n.º 20
0
static void connectivity_state_set(
    grpc_chttp2_transport_global *transport_global,
    grpc_connectivity_state state, const char *reason) {
  GRPC_CHTTP2_IF_TRACING(
      gpr_log(GPR_DEBUG, "set connectivity_state=%d", state));
  grpc_connectivity_state_set_with_scheduler(
      &TRANSPORT_FROM_GLOBAL(transport_global)->channel_callback.state_tracker,
      state, schedule_closure_for_connectivity, transport_global, reason);
}
Exemplo n.º 21
0
static void connectivity_state_set(
    grpc_exec_ctx *exec_ctx, grpc_chttp2_transport_global *transport_global,
    grpc_connectivity_state state, const char *reason) {
  GRPC_CHTTP2_IF_TRACING(
      gpr_log(GPR_DEBUG, "set connectivity_state=%d", state));
  grpc_connectivity_state_set(exec_ctx, &TRANSPORT_FROM_GLOBAL(transport_global)
                                             ->channel_callback.state_tracker,
                              state, reason);
}
Exemplo n.º 22
0
void grpc_chttp2_for_all_streams(
    grpc_chttp2_transport_global *transport_global, void *user_data,
    void (*cb)(grpc_chttp2_transport_global *transport_global, void *user_data,
               grpc_chttp2_stream_global *stream_global)) {
  grpc_chttp2_stream *s;
  grpc_chttp2_transport *t = TRANSPORT_FROM_GLOBAL(transport_global);
  for (s = t->lists[GRPC_CHTTP2_LIST_ALL_STREAMS].head; s != NULL;
       s = s->links[GRPC_CHTTP2_LIST_ALL_STREAMS].next) {
    cb(transport_global, user_data, &s->global);
  }
}
Exemplo n.º 23
0
int grpc_chttp2_list_pop_stalled_by_transport(
    grpc_chttp2_transport_global *transport_global,
    grpc_chttp2_stream_global **stream_global) {
  grpc_chttp2_stream *stream;
  int r = stream_list_pop(TRANSPORT_FROM_GLOBAL(transport_global), &stream,
                          GRPC_CHTTP2_LIST_STALLED_BY_TRANSPORT);
  if (r != 0) {
    *stream_global = &stream->global;
  }
  return r;
}
Exemplo n.º 24
0
int grpc_chttp2_list_pop_check_read_ops(
    grpc_chttp2_transport_global *transport_global,
    grpc_chttp2_stream_global **stream_global) {
  grpc_chttp2_stream *stream;
  int r = stream_list_pop(TRANSPORT_FROM_GLOBAL(transport_global), &stream,
                          GRPC_CHTTP2_LIST_CHECK_READ_OPS);
  if (r != 0) {
    *stream_global = &stream->global;
  }
  return r;
}
Exemplo n.º 25
0
int grpc_chttp2_list_pop_writable_stream(
    grpc_chttp2_transport_global *transport_global,
    grpc_chttp2_transport_writing *transport_writing,
    grpc_chttp2_stream_global **stream_global,
    grpc_chttp2_stream_writing **stream_writing) {
  grpc_chttp2_stream *stream;
  int r = stream_list_pop(TRANSPORT_FROM_GLOBAL(transport_global), &stream,
                          GRPC_CHTTP2_LIST_WRITABLE);
  *stream_global = &stream->global;
  *stream_writing = &stream->writing;
  return r;
}
Exemplo n.º 26
0
int grpc_chttp2_list_pop_incoming_window_updated(
    grpc_chttp2_transport_global *transport_global,
    grpc_chttp2_transport_parsing *transport_parsing,
    grpc_chttp2_stream_global **stream_global,
    grpc_chttp2_stream_parsing **stream_parsing) {
  grpc_chttp2_stream *stream;
  int r = stream_list_pop(TRANSPORT_FROM_GLOBAL(transport_global), &stream,
                          GRPC_CHTTP2_LIST_INCOMING_WINDOW_UPDATED);
  *stream_global = &stream->global;
  *stream_parsing = &stream->parsing;
  return r;
}
Exemplo n.º 27
0
static void maybe_start_some_streams(
    grpc_chttp2_transport_global *transport_global) {
  grpc_chttp2_stream_global *stream_global;
  /* start streams where we have free grpc_chttp2_stream ids and free
   * concurrency */
  while (transport_global->next_stream_id <= MAX_CLIENT_STREAM_ID &&
         transport_global->concurrent_stream_count <
             transport_global
                 ->settings[GRPC_PEER_SETTINGS]
                           [GRPC_CHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS] &&
         grpc_chttp2_list_pop_waiting_for_concurrency(transport_global,
                                                      &stream_global)) {
    GRPC_CHTTP2_IF_TRACING(gpr_log(
        GPR_DEBUG, "HTTP:%s: Allocating new grpc_chttp2_stream %p to id %d",
        transport_global->is_client ? "CLI" : "SVR", stream_global,
        transport_global->next_stream_id));

    GPR_ASSERT(stream_global->id == 0);
    stream_global->id = transport_global->next_stream_id;
    transport_global->next_stream_id += 2;

    if (transport_global->next_stream_id >= MAX_CLIENT_STREAM_ID) {
      connectivity_state_set(transport_global, GRPC_CHANNEL_TRANSIENT_FAILURE,
                             "no_more_stream_ids");
    }

    stream_global->outgoing_window =
        transport_global->settings[GRPC_PEER_SETTINGS]
                                  [GRPC_CHTTP2_SETTINGS_INITIAL_WINDOW_SIZE];
    stream_global->incoming_window =
        transport_global->settings[GRPC_SENT_SETTINGS]
                                  [GRPC_CHTTP2_SETTINGS_INITIAL_WINDOW_SIZE];
    stream_global->max_recv_bytes = 
        GPR_MAX(stream_global->incoming_window, stream_global->max_recv_bytes);
    grpc_chttp2_stream_map_add(
        &TRANSPORT_FROM_GLOBAL(transport_global)->new_stream_map,
        stream_global->id, STREAM_FROM_GLOBAL(stream_global));
    stream_global->in_stream_map = 1;
    transport_global->concurrent_stream_count++;
    grpc_chttp2_list_add_incoming_window_updated(transport_global,
                                                 stream_global);
    grpc_chttp2_list_add_writable_stream(transport_global, stream_global);

  }
  /* cancel out streams that will never be started */
  while (transport_global->next_stream_id >= MAX_CLIENT_STREAM_ID &&
         grpc_chttp2_list_pop_waiting_for_concurrency(transport_global,
                                                      &stream_global)) {
    cancel_from_api(transport_global, stream_global, GRPC_STATUS_UNAVAILABLE);
  }
}
Exemplo n.º 28
0
int grpc_chttp2_list_pop_unannounced_incoming_window_available(
    grpc_chttp2_transport_global *transport_global,
    grpc_chttp2_transport_parsing *transport_parsing,
    grpc_chttp2_stream_global **stream_global,
    grpc_chttp2_stream_parsing **stream_parsing) {
  grpc_chttp2_stream *stream;
  int r =
      stream_list_pop(TRANSPORT_FROM_GLOBAL(transport_global), &stream,
                      GRPC_CHTTP2_LIST_UNANNOUNCED_INCOMING_WINDOW_AVAILABLE);
  if (r != 0) {
    *stream_global = &stream->global;
    *stream_parsing = &stream->parsing;
  }
  return r;
}
Exemplo n.º 29
0
static void perform_stream_op_locked(
    grpc_exec_ctx *exec_ctx, grpc_chttp2_transport_global *transport_global,
    grpc_chttp2_stream_global *stream_global, grpc_transport_stream_op *op) {
  if (op->cancel_with_status != GRPC_STATUS_OK) {
    cancel_from_api(transport_global, stream_global, op->cancel_with_status);
  }

  if (op->close_with_status != GRPC_STATUS_OK) {
    close_from_api(transport_global, stream_global, op->close_with_status,
                   op->optional_close_message);
  }

  if (op->send_ops) {
    GPR_ASSERT(stream_global->outgoing_sopb == NULL);
    stream_global->send_done_closure = op->on_done_send;
    if (!stream_global->cancelled) {
      stream_global->written_anything = 1;
      stream_global->outgoing_sopb = op->send_ops;
      if (op->is_last_send &&
          stream_global->write_state == GRPC_WRITE_STATE_OPEN) {
        stream_global->write_state = GRPC_WRITE_STATE_QUEUED_CLOSE;
      }
      if (stream_global->id == 0) {
        GRPC_CHTTP2_IF_TRACING(gpr_log(
            GPR_DEBUG,
            "HTTP:%s: New grpc_chttp2_stream %p waiting for concurrency",
            transport_global->is_client ? "CLI" : "SVR", stream_global));
        grpc_chttp2_list_add_waiting_for_concurrency(transport_global,
                                                     stream_global);
        maybe_start_some_streams(exec_ctx, transport_global);
      } else if (stream_global->outgoing_window > 0) {
        grpc_chttp2_list_add_writable_stream(transport_global, stream_global);
      }
    } else {
      grpc_sopb_reset(op->send_ops);
      grpc_exec_ctx_enqueue(exec_ctx, stream_global->send_done_closure, 0);
    }
  }

  if (op->recv_ops) {
    GPR_ASSERT(stream_global->publish_sopb == NULL);
    GPR_ASSERT(stream_global->published_state != GRPC_STREAM_CLOSED);
    stream_global->recv_done_closure = op->on_done_recv;
    stream_global->publish_sopb = op->recv_ops;
    stream_global->publish_sopb->nops = 0;
    stream_global->publish_state = op->recv_state;
    /* clamp max recv bytes */
    op->max_recv_bytes = GPR_MIN(op->max_recv_bytes, GPR_UINT32_MAX);
    if (stream_global->max_recv_bytes < op->max_recv_bytes) {
      GRPC_CHTTP2_FLOWCTL_TRACE_STREAM(
          "op", transport_global, stream_global, max_recv_bytes,
          op->max_recv_bytes - stream_global->max_recv_bytes);
      GRPC_CHTTP2_FLOWCTL_TRACE_STREAM(
          "op", transport_global, stream_global, unannounced_incoming_window,
          op->max_recv_bytes - stream_global->max_recv_bytes);
      stream_global->unannounced_incoming_window +=
          (gpr_uint32)op->max_recv_bytes - stream_global->max_recv_bytes;
      stream_global->max_recv_bytes = (gpr_uint32)op->max_recv_bytes;
    }
    grpc_chttp2_incoming_metadata_live_op_buffer_end(
        &stream_global->outstanding_metadata);
    grpc_chttp2_list_add_read_write_state_changed(transport_global,
                                                  stream_global);
    if (stream_global->id != 0) {
      grpc_chttp2_list_add_writable_stream(transport_global, stream_global);
    }
  }

  if (op->bind_pollset) {
    add_to_pollset_locked(exec_ctx, TRANSPORT_FROM_GLOBAL(transport_global),
                          op->bind_pollset);
  }

  grpc_exec_ctx_enqueue(exec_ctx, op->on_consumed, 1);
}