class
GRPC::Transport::Http2ServerConnection
Overview
Http2ServerConnection handles one accepted TCP connection on the server side. It receives gRPC requests, dispatches to registered services, and sends responses.
Included Modules
Defined in:
grpc/transport/http2_server_connection.crConstant Summary
-
DATA_READ_CB =
LibNghttp2::DataSourceReadCallback.new do |session, stream_id, buf, length, data_flags, source, _user_data| ctx = Box(ResponseContext).unbox(source.value.ptr) to_copy = (Math.min(length.to_i, ctx.remaining)).to_i if to_copy > 0 buf.copy_from(ctx.data.to_unsafe + ctx.offset, to_copy) ctx.offset = ctx.offset + to_copy end if ctx.remaining == 0 data_flags.value = data_flags.value | (LibNghttp2::DATA_FLAG_EOF | LibNghttp2::DATA_FLAG_NO_END_STREAM) trailer_nva = [] of LibNghttp2::Nv ctx.trailer_entries.each do |name, value| name_slice = name.to_slice value_slice = value.to_slice trailer_nva << LibNghttp2::Nv.new(name: name_slice.to_unsafe, value: value_slice.to_unsafe, namelen: name_slice.size, valuelen: value_slice.size, flags: LibNghttp2::NV_FLAG_NONE) end rc = LibNghttp2.submit_trailer(session, stream_id, trailer_nva.to_unsafe, trailer_nva.size) if rc < 0 next LibNghttp2::ERR_CALLBACK_FAILURE.to_i64 end end to_copy.to_i64 end -
DATA read callback for nghttp2 when sending a response body. Must be a module-level constant (non-closure) proc.
When the body is exhausted the callback also submits the trailing HEADERS frame (grpc-status / grpc-message). Per nghttp2 documentation, nghttp2_submit_trailer is safe to call from the data source read callback.
-
LOGGER =
::Log.for(self) -
STREAMING_DATA_READ_CB =
LibNghttp2::DataSourceReadCallback.new do |_session, _stream_id, buf, length, data_flags, source, _user_data| sb = Box(SendBuffer).unbox(source.value.ptr) to_copy = (Math.min(length.to_i, sb.remaining)).to_i if to_copy > 0 buf.copy_from(sb.data.to_unsafe + sb.offset, to_copy) sb.offset = sb.offset + to_copy end if sb.remaining == 0 data_flags.value = data_flags.value | (LibNghttp2::DATA_FLAG_EOF | LibNghttp2::DATA_FLAG_NO_END_STREAM) end to_copy.to_i64 end -
DATA read callback for server-streaming: sends one message chunk. Sets DATA_FLAG_EOF | DATA_FLAG_NO_END_STREAM when the buffer is exhausted so the stream stays open for subsequent data or trailer submission.
Constructors
Instance Method Summary
- #on_begin_headers_cb(frame : Pointer(Void)) : Nil
- #on_data_chunk_cb(stream_id : Int32, data : Pointer(UInt8), len : LibC::SizeT) : Nil
- #on_frame_recv_cb(frame : Pointer(Void)) : Nil
- #on_frame_send_cb(frame : Pointer(Void)) : Nil
- #on_header_cb(frame : Pointer(Void), name : Pointer(UInt8), nlen : LibC::SizeT, value : Pointer(UInt8), vlen : LibC::SizeT) : Nil
- #on_stream_close_cb(stream_id : Int32, error_code : UInt32) : Nil
Instance methods inherited from module GRPC::Transport::ServerTransport
close : Nil
close,
closed? : Bool
closed?,
run_recv_loop : Nil
run_recv_loop
Instance methods inherited from class GRPC::Transport::Http2Connection
close : Nil
close,
closed? : Bool
closed?,
on_begin_headers_cb(frame : Pointer(Void)) : Nil
on_begin_headers_cb,
on_data_chunk_cb(stream_id : Int32, data : Pointer(UInt8), len : LibC::SizeT) : Nil
on_data_chunk_cb,
on_frame_recv_cb(frame : Pointer(Void)) : Nil
on_frame_recv_cb,
on_frame_send_cb(frame : Pointer(Void)) : Nil
on_frame_send_cb,
on_header_cb(frame : Pointer(Void), name : Pointer(UInt8), nlen : LibC::SizeT, value : Pointer(UInt8), vlen : LibC::SizeT) : Nil
on_header_cb,
on_stream_close_cb(stream_id : Int32, error_code : UInt32) : Nil
on_stream_close_cb,
run_recv_loop : Nil
run_recv_loop
Constructor methods inherited from class GRPC::Transport::Http2Connection
new(socket : IO, peer_address : String = "unknown")
new
Constructor Detail
def self.new(socket : IO, services : Hash(String, Service), interceptors : Array(ServerInterceptor) = [] of ServerInterceptor, peer_address : String = "unknown", tls_socket : OpenSSL::SSL::Socket::Server | Nil = nil)
#
Instance Method Detail
def on_data_chunk_cb(stream_id : Int32, data : Pointer(UInt8), len : LibC::SizeT) : Nil
#
def on_header_cb(frame : Pointer(Void), name : Pointer(UInt8), nlen : LibC::SizeT, value : Pointer(UInt8), vlen : LibC::SizeT) : Nil
#