MCPcopy Create free account
hub / github.com/CPChain/chain / write

Method write

api/rpc/client.go:477–494  ·  view source on GitHub ↗
(ctx context.Context, msg interface{})

Source from the content-addressed store, hash-verified

475}
476
477func (c *Client) write(ctx context.Context, msg interface{}) error {
478 deadline, ok := ctx.Deadline()
479 if !ok {
480 deadline = time.Now().Add(defaultWriteTimeout)
481 }
482 // The previous write failed. Try to establish a new connection.
483 if c.writeConn == nil {
484 if err := c.reconnect(ctx); err != nil {
485 return err
486 }
487 }
488 c.writeConn.SetWriteDeadline(deadline)
489 err := json.NewEncoder(c.writeConn).Encode(msg)
490 if err != nil {
491 c.writeConn = nil
492 }
493 return err
494}
495
496func (c *Client) reconnect(ctx context.Context) error {
497 newconn, err := c.connectFunc(ctx)

Callers 3

sendMethod · 0.95
mainFunction · 0.80
mainFunction · 0.80

Calls 4

reconnectMethod · 0.95
AddMethod · 0.65
NowMethod · 0.65
SetWriteDeadlineMethod · 0.45

Tested by

no test coverage detected