代码拉取完成,页面将自动刷新
package grpc
import (
"context"
"io"
"sync"
"github.com/micro/go-micro/client"
"google.golang.org/grpc"
)
// Implements the streamer interface
type grpcStream struct {
sync.RWMutex
seq uint64
closed chan bool
err error
conn *grpc.ClientConn
request client.Request
stream grpc.ClientStream
context context.Context
}
func (g *grpcStream) isClosed() bool {
select {
case <-g.closed:
return true
default:
return false
}
}
func (g *grpcStream) Context() context.Context {
return g.context
}
func (g *grpcStream) Request() client.Request {
return g.request
}
func (g *grpcStream) Send(msg interface{}) error {
g.Lock()
defer g.Unlock()
if g.isClosed() {
g.err = errShutdown
return errShutdown
}
if err := g.stream.SendMsg(msg); err != nil {
g.err = err
return err
}
return nil
}
func (g *grpcStream) Recv(msg interface{}) error {
g.Lock()
defer g.Unlock()
if g.isClosed() {
g.err = errShutdown
return errShutdown
}
if err := g.stream.RecvMsg(msg); err != nil {
if err == io.EOF && !g.isClosed() {
g.err = io.ErrUnexpectedEOF
return io.ErrUnexpectedEOF
}
g.err = err
return err
}
return nil
}
func (g *grpcStream) Error() error {
g.RLock()
defer g.RUnlock()
return g.err
}
func (g *grpcStream) Close() error {
select {
case <-g.closed:
return nil
default:
close(g.closed)
g.stream.CloseSend()
return g.conn.Close()
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。