当前仓库属于暂停状态,部分功能使用受限,详情请查阅 仓库状态说明
2 Star 0 Fork 1

JUMEI_ARCH/go-plugins
暂停

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
stream.go 1.39 KB
一键复制 编辑 原始数据 按行查看 历史
Asim Aslam 提交于 2018-03-03 12:28 . switch to stdlib context
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()
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/JMArch/go-plugins.git
git@gitee.com:JMArch/go-plugins.git
JMArch
go-plugins
go-plugins
v0.9.2

搜索帮助