本文整理汇总了Golang中github.com/cockroachdb/cockroach/rpc/codec.NewClientCodec函数的典型用法代码示例。如果您正苦于以下问题:Golang NewClientCodec函数的具体用法?Golang NewClientCodec怎么用?Golang NewClientCodec使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewClientCodec函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: getClient
func (lt *localRPCTransport) getClient(id roachpb.StoreID) (*netrpc.Client, error) {
lt.mu.Lock()
defer lt.mu.Unlock()
select {
case <-lt.closed:
return nil, util.Errorf("transport is closed")
default:
}
client, ok := lt.clients[id]
if ok {
return client, nil
}
srvWithAddr, ok := lt.servers[id]
if !ok {
return nil, util.Errorf("unknown peer %v", id)
}
address := srvWithAddr.addr.String()
// If this wasn't test code we wouldn't want to call Dial while holding the lock.
conn, err := codec.TLSDialHTTP("tcp", address, base.NetworkTimeout, nil)
if err != nil {
return nil, err
}
client = netrpc.NewClientWithCodec(codec.NewClientCodec(conn))
lt.clients[id] = client
return client, err
}
示例2: connect
// connect attempts a single connection attempt. On success, updates `c.conn`.
func (c *Client) connect() error {
conn, err := tlsDialHTTP(c.addr.NetworkField, c.addr.StringField, c.tlsConfig)
if err != nil {
return err
}
c.conn.Store(internalConn{
conn: conn,
client: rpc.NewClientWithCodec(codec.NewClientCodec(conn)),
})
return nil
}
示例3: connect
// connect attempts a single connection attempt. On success, updates `c.conn`.
func (c *Client) connect() error {
conn, err := tlsDialHTTP(c.addr.NetworkField, c.addr.StringField, c.tlsConfig)
if err != nil {
return err
}
if oldConn := (*internalConn)(atomic.SwapPointer(&c.conn, unsafe.Pointer(&internalConn{
conn: conn,
client: rpc.NewClientWithCodec(codec.NewClientCodec(conn)),
}))); oldConn != nil {
oldConn.conn.Close()
}
return nil
}
示例4: connect
// connect dials the connection in a backoff/retry loop.
func (c *Client) connect(opts *retry.Options, context *Context) error {
// Attempt to dial connection.
retryOpts := clientRetryOptions
if opts != nil {
retryOpts = *opts
}
retryOpts.Stopper = context.Stopper
for r := retry.Start(retryOpts); r.Next(); {
tlsConfig, err := context.GetClientTLSConfig()
if err != nil {
// Problem loading the TLS config. Retrying will not help.
return err
}
conn, err := tlsDialHTTP(c.addr.Network(), c.addr.String(), tlsConfig)
if err != nil {
// Retry if the error is temporary, otherwise fail fast.
if t, ok := err.(net.Error); ok && t.Temporary() {
if log.V(1) {
log.Warning(err)
}
continue
}
return err
}
c.mu.Lock()
c.Client = rpc.NewClientWithCodec(codec.NewClientCodec(conn))
c.lAddr = conn.LocalAddr()
c.mu.Unlock()
if c.lAddr == nil {
return errClosed
}
// Ensure at least one heartbeat succeeds before exiting the
// retry loop. If it fails, don't retry: The node is probably
// dead.
if err = c.heartbeat(); err != nil {
return err
}
return nil
}
return util.Errorf("system is stopping")
}
示例5: connect
// connect dials the connection in a backoff/retry loop.
func (c *Client) connect(opts *retry.Options, context *Context) error {
// Attempt to dial connection.
retryOpts := clientRetryOptions
if opts != nil {
retryOpts = *opts
}
retryOpts.Tag = fmt.Sprintf("client %s connection", c.addr)
retryOpts.Stopper = context.Stopper
if err := retry.WithBackoff(retryOpts, func() (retry.Status, error) {
tlsConfig, err := context.GetClientTLSConfig()
if err != nil {
// Problem loading the TLS config. Retrying will not help.
return retry.Break, err
}
conn, err := tlsDialHTTP(c.addr.Network(), c.addr.String(), tlsConfig)
if err != nil {
// Retry if the error is temporary, otherwise fail fast.
if t, ok := err.(net.Error); ok && t.Temporary() {
return retry.Continue, err
}
return retry.Break, err
}
c.mu.Lock()
c.Client = rpc.NewClientWithCodec(codec.NewClientCodec(conn))
c.lAddr = conn.LocalAddr()
c.mu.Unlock()
// Ensure at least one heartbeat succeeds before exiting the
// retry loop. If it fails, don't retry: The node is probably
// dead.
if err = c.heartbeat(); err != nil {
return retry.Break, err
}
return retry.Break, nil
}); err != nil {
return err
}
return nil
}
示例6: newRPCSender
// newRPCSender returns a new instance of rpcSender.
func newRPCSender(server string, context *base.Context, retryOpts retry.Options) (*rpcSender, error) {
addr, err := net.ResolveTCPAddr("tcp", server)
if err != nil {
return nil, err
}
tlsConfig, err := context.GetClientTLSConfig()
if err != nil {
return nil, err
}
conn, err := codec.TLSDialHTTP(addr.Network(), addr.String(), base.NetworkTimeout, tlsConfig)
if err != nil {
return nil, err
}
client := rpc.NewClientWithCodec(codec.NewClientCodec(conn))
return &rpcSender{
user: context.User,
client: client,
retryOpts: retryOpts,
}, nil
}