deepwzh的技术笔记
  • Golang
  • Python
  • Cpp
杂项
前端开发
  • 计算机网络
  • 操作系统
  • 数据库
云原生
Devops
AIGC
关于作者
  • Golang
  • Python
  • Cpp
杂项
前端开发
  • 计算机网络
  • 操作系统
  • 数据库
云原生
Devops
AIGC
关于作者
  • Golang
  • 工具
  • 最佳实践
  • 学习资料
  • 代码生成
  • 安装与配置

    • 安装与配置
    • GVM
    • 私有仓库拉取
    • 安装与配置
  • 库

    • 库
    • Grpc-go
    • 命令行参数
    • 依赖注入库 wire
  • 编译器

    • 编译器
    • clean
    • 逃逸分析
    • 编译过程
    • 构建选项
    • 编译优化

      • 编译优化
      • PGO
  • 语言

    • 语言
    • defer
    • go:embed
  • 微服务框架

    • 微服务框架
    • Kratos

      • Kratos
      • 集成三方 web 框架
      • 项目结构体系

Grpc-go

接口

ClientSteam

type ClientStream interface {
    _// Header returns the header metadata received from the server if there_
    _// is any. It blocks if the metadata is not ready to read._
    Header() (metadata.MD, error)
    _// Trailer returns the trailer metadata from the server, if there is any._
    _// It must only be called after stream.CloseAndRecv has returned, or_
    _// stream.Recv has returned a non-nil error (including io.EOF)._
    Trailer() metadata.MD
    _// CloseSend closes the send direction of the stream. It closes the stream_
    _// when non-nil error is met. It is also not safe to call CloseSend_
    _// concurrently with SendMsg._
    CloseSend() error
    _// Context returns the context for this stream._
    _//_
    _// It should not be called until after Header or RecvMsg has returned. Once_
    _// called, subsequent client-side retries are disabled._
    Context() context.Context
    _// SendMsg is generally called by generated code. On error, SendMsg aborts_
    _// the stream. If the error was generated by the client, the status is_
    _// returned directly; otherwise, io.EOF is returned and the status of_
    _// the stream may be discovered using RecvMsg._
    _//_
    _// SendMsg blocks until:_
    _//   - There is sufficient flow control to schedule m with the transport, or_
    _//   - The stream is done, or_
    _//   - The stream breaks._
    _//_
    _// SendMsg does not wait until the message is received by the server. An_
    _// untimely stream closure may result in lost messages. To ensure delivery,_
    _// users should ensure the RPC completed successfully using RecvMsg._
    _//_
    _// It is safe to have a goroutine calling SendMsg and another goroutine_
    _// calling RecvMsg on the same stream at the same time, but it is not safe_
    _// to call SendMsg on the same stream in different goroutines. It is also_
    _// not safe to call CloseSend concurrently with SendMsg._
    SendMsg(_m_ any) error
    _// RecvMsg blocks until it receives a message into m or the stream is_
    _// done. It returns io.EOF when the stream completes successfully. On_
    _// any other error, the stream is aborted and the error contains the RPC_
    _// status._
    _//_
    _// It is safe to have a goroutine calling SendMsg and another goroutine_
    _// calling RecvMsg on the same stream at the same time, but it is not_
    _// safe to call RecvMsg on the same stream in different goroutines._
    RecvMsg(_m_ any) error
}

ClientTransport

type ClientTransport interface {
    _// Close tears down this transport. Once it returns, the transport_
    _// should not be accessed any more. The caller must make sure this_
    _// is called only once._
    Close(_err_ error)

    _// GracefulClose starts to tear down the transport: the transport will stop_
    _// accepting new RPCs and NewStream will return error. Once all streams are_
    _// finished, the transport will close._
    _//_
    _// It does not block._
    GracefulClose()

    _// NewStream creates a Stream for an RPC._
    NewStream(_ctx_ context.Context, _callHdr_ *CallHdr) (*ClientStream, error)

    _// Error returns a channel that is closed when some I/O error_
    _// happens. Typically the caller should have a goroutine to monitor_
    _// this in order to take action (e.g., close the current transport_
    _// and create a new one) in error case. It should not return nil_
    _// once the transport is initiated._
    Error() <-chan struct{}

    _// GoAway returns a channel that is closed when ClientTransport_
    _// receives the draining signal from the server (e.g., GOAWAY frame in_
    _// HTTP/2)._
    GoAway() <-chan struct{}

    _// GetGoAwayReason returns the reason why GoAway frame was received, along_
    _// with a human readable string with debug info._
    GetGoAwayReason() (GoAwayReason, string)

    _// RemoteAddr returns the remote network address._
    RemoteAddr() net.Addr
}

初始化 client

newCCResolverWrapper 实现了 resolve.ClientConn

newCCBalancerWrapper 实现了 balancer.ClientConn

客户端发送数据包流程

Prev
库
Next
命令行参数