本文整理汇总了Golang中github.com/pingcap/kvproto/pkg/msgpb.Message类的典型用法代码示例。如果您正苦于以下问题:Golang Message类的具体用法?Golang Message怎么用?Golang Message使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Message类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestWrongMessageID
func (s *testClientSuite) TestWrongMessageID(c *C) {
l := startServer(":61237", c, func(conn net.Conn, c *C) {
var msg msgpb.Message
msgID, err := util.ReadMessage(conn, &msg)
c.Assert(err, IsNil)
resp := msgpb.Message{
MsgType: msgpb.MessageType_KvResp,
KvResp: &pb.Response{
Type: msg.GetKvReq().GetType(),
},
}
// Send the request back to client, set wrong msgID for the 1st
// request.
if msgID == 1 {
err = util.WriteMessage(conn, msgID+100, &resp)
} else {
err = util.WriteMessage(conn, msgID, &resp)
}
c.Assert(err, IsNil)
})
defer l.Close()
cli := newRPCClient()
req := &pb.Request{
Type: pb.MessageType_CmdGet,
}
// Wrong ID for the first request, correct for the rests.
_, err := cli.SendKVReq(":61237", req, readTimeoutShort)
c.Assert(err, NotNil)
resp, err := cli.SendKVReq(":61237", req, readTimeoutShort)
c.Assert(err, IsNil)
c.Assert(resp.GetType(), Equals, req.GetType())
}
开发者ID:pingcap,项目名称:tidb,代码行数:32,代码来源:client_test.go
示例2: readThenCloseRequest
func readThenCloseRequest(conn net.Conn, c *C) {
c.Assert(conn, NotNil)
defer conn.Close()
var msg msgpb.Message
msgID, err := util.ReadMessage(conn, &msg)
c.Assert(err, IsNil)
c.Assert(msg.GetKvReq(), NotNil)
c.Assert(msgID, Greater, uint64(0))
}
开发者ID:pingcap,项目名称:tidb,代码行数:9,代码来源:client_test.go
示例3: SendCopReq
// SendCopReq sends a Request to co-processor and receives Response.
func (c *rpcClient) SendCopReq(req *coprocessor.Request) (*coprocessor.Response, error) {
conn, err := c.pool.Get()
if err != nil {
return nil, errors.Trace(err)
}
defer conn.Close()
msg := msgpb.Message{
MsgType: msgpb.MessageType_CopReq.Enum(),
CopReq: req,
}
err = c.doSend(conn, &msg)
if err == nil {
if msg.GetMsgType() != msgpb.MessageType_CopResp || msg.GetCopResp() == nil {
err = errors.Trace(errInvalidResponse)
}
}
if err != nil {
// This connection is not valid any more, so close its underlying conn.
if poolConn, ok := conn.(*pool.PoolConn); ok {
poolConn.MarkUnusable()
}
return nil, errors.Trace(err)
}
return msg.GetCopResp(), nil
}
开发者ID:anywhy,项目名称:tidb,代码行数:26,代码来源:client.go
示例4: SendKVReq
// SendKVReq sends a Request to kv server and receives Response.
func (c *rpcClient) SendKVReq(addr string, req *kvrpcpb.Request, timeout time.Duration) (*kvrpcpb.Response, error) {
sendReqCounter.WithLabelValues("kv").Inc()
start := time.Now()
defer func() { sendReqHistogram.WithLabelValues("kv").Observe(time.Since(start).Seconds()) }()
conn, err := c.p.GetConn(addr)
if err != nil {
return nil, errors.Trace(err)
}
defer c.p.PutConn(conn)
msg := msgpb.Message{
MsgType: msgpb.MessageType_KvReq,
KvReq: req,
}
err = c.doSend(conn, &msg, writeTimeout, timeout)
if err != nil {
conn.Close()
return nil, errors.Trace(err)
}
if msg.GetMsgType() != msgpb.MessageType_KvResp || msg.GetKvResp() == nil {
conn.Close()
return nil, errors.Trace(errInvalidResponse)
}
return msg.GetKvResp(), nil
}
开发者ID:jmptrader,项目名称:tidb,代码行数:26,代码来源:client.go
示例5: doSend
func (c *rpcClient) doSend(conn *Conn, msg *msgpb.Message) error {
curMsgID := atomic.AddUint64(&c.msgID, 1)
log.Debugf("Send request msgID[%d] type[%v]", curMsgID, msg.GetMsgType())
if err := util.WriteMessage(conn, curMsgID, msg); err != nil {
return errors.Trace(err)
}
if err := conn.Flush(); err != nil {
return errors.Trace(err)
}
msgID, err := util.ReadMessage(conn.BufioReader(), msg)
if err != nil {
return errors.Trace(err)
}
if curMsgID != msgID {
log.Errorf("Sent msgID[%d] mismatches recv msgID[%d]", curMsgID, msgID)
}
log.Debugf("Receive response msgID[%d] type[%v]", msgID, msg.GetMsgType())
return nil
}
开发者ID:tangfeixiong,项目名称:tidb,代码行数:19,代码来源:client.go
示例6: handleRequest
// handleRequest receive Request then send empty Response back fill with same Type.
func handleRequest(conn net.Conn, c *C) {
c.Assert(conn, NotNil)
defer conn.Close()
var msg msgpb.Message
msgID, err := util.ReadMessage(conn, &msg)
c.Assert(err, IsNil)
c.Assert(msgID, Greater, uint64(0))
c.Assert(msg.GetMsgType(), Equals, msgpb.MessageType_KvReq)
req := msg.GetKvReq()
c.Assert(req, NotNil)
var resp pb.Response
resp.Type = req.Type
msg = msgpb.Message{
MsgType: msgpb.MessageType_KvResp,
KvResp: &resp,
}
err = util.WriteMessage(conn, msgID, &msg)
c.Assert(err, IsNil)
}
开发者ID:pingcap,项目名称:tidb,代码行数:21,代码来源:client_test.go
示例7: doSend
func (c *rpcClient) doSend(conn net.Conn, msg *msgpb.Message) error {
curMsgID := atomic.AddUint64(&c.msgID, 1)
log.Debugf("Send request msgID[%d] type[%v]", curMsgID, msg.GetMsgType())
if err := conn.SetWriteDeadline(time.Now().Add(writeTimeout)); err != nil {
log.Warn("Set write deadline failed, it may be blocked.")
}
if err := util.WriteMessage(conn, curMsgID, msg); err != nil {
return errors.Trace(err)
}
if err := conn.SetReadDeadline(time.Now().Add(readTimeout)); err != nil {
log.Warn("Set read deadline failed, it may be blocked.")
}
msgID, err := util.ReadMessage(conn, msg)
if err != nil {
return errors.Trace(err)
}
if curMsgID != msgID {
log.Errorf("Sent msgID[%d] mismatches recv msgID[%d]", curMsgID, msgID)
}
log.Debugf("Receive response msgID[%d] type[%v]", msgID, msg.GetMsgType())
return nil
}
开发者ID:anywhy,项目名称:tidb,代码行数:22,代码来源:client.go
示例8: doSend
func (c *rpcClient) doSend(conn *Conn, msg *msgpb.Message, writeTimeout time.Duration, readTimeout time.Duration) error {
curMsgID := atomic.AddUint64(&c.msgID, 1)
log.Debugf("Send request msgID[%d] type[%v]", curMsgID, msg.GetMsgType())
conn.SetWriteDeadline(time.Now().Add(writeTimeout))
if err := util.WriteMessage(conn, curMsgID, msg); err != nil {
return errors.Trace(err)
}
if err := conn.Flush(); err != nil {
return errors.Trace(err)
}
conn.SetReadDeadline(time.Now().Add(readTimeout))
msgID, err := util.ReadMessage(conn.BufioReader(), msg)
if err != nil {
return errors.Trace(err)
}
if curMsgID != msgID {
log.Errorf("Sent msgID[%d] mismatches recv msgID[%d]", curMsgID, msgID)
return errors.Trace(errInvalidResponse)
}
log.Debugf("Receive response msgID[%d] type[%v]", msgID, msg.GetMsgType())
return nil
}
开发者ID:jmptrader,项目名称:tidb,代码行数:22,代码来源:client.go
示例9: SendKVReq
// SendKVReq sends a Request to kv server and receives Response.
func (c *rpcClient) SendKVReq(addr string, req *kvrpcpb.Request) (*kvrpcpb.Response, error) {
conn, err := c.p.GetConn(addr)
if err != nil {
return nil, errors.Trace(err)
}
defer c.p.PutConn(conn)
msg := msgpb.Message{
MsgType: msgpb.MessageType_KvReq.Enum(),
KvReq: req,
}
err = c.doSend(conn, &msg)
if err != nil {
return nil, errors.Trace(err)
}
if msg.GetMsgType() != msgpb.MessageType_KvResp || msg.GetKvResp() == nil {
return nil, errors.Trace(errInvalidResponse)
}
return msg.GetKvResp(), nil
}
开发者ID:tangfeixiong,项目名称:tidb,代码行数:20,代码来源:client.go
示例10: SendCopReq
// SendCopReq sends a Request to co-processor and receives Response.
func (c *rpcClient) SendCopReq(addr string, req *coprocessor.Request) (*coprocessor.Response, error) {
conn, err := c.p.GetConn(addr)
if err != nil {
return nil, errors.Trace(err)
}
defer c.p.PutConn(conn)
msg := msgpb.Message{
MsgType: msgpb.MessageType_CopReq,
CopReq: req,
}
err = c.doSend(conn, &msg)
if err != nil {
conn.Close()
return nil, errors.Trace(err)
}
if msg.GetMsgType() != msgpb.MessageType_CopResp || msg.GetCopResp() == nil {
conn.Close()
return nil, errors.Trace(errInvalidResponse)
}
return msg.GetCopResp(), nil
}
开发者ID:yangxuanjia,项目名称:tidb,代码行数:22,代码来源:client.go
注:本文中的github.com/pingcap/kvproto/pkg/msgpb.Message类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论