rpc

package
v0.0.0-...-ba0e684 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 19, 2022 License: Apache-2.0 Imports: 7 Imported by: 4

Documentation

Index

Constants

View Source
const (
	ConnDialTimeout  = time.Second * 3
	ConnReadTimeout  = 30 * time.Second
	ConnWriteTimeout = 10 * time.Second
)

TODO(wutao1): make these parameters configurable

Variables

View Source
var ErrConnectionNotReady = errors.New("connection is not ready")

Functions

func IsNetworkClosed

func IsNetworkClosed(err error) bool

IsNetworkClosed returns whether the session is shutdown by the peer.

func IsNetworkTimeoutErr

func IsNetworkTimeoutErr(err error) bool

IsNetworkTimeoutErr returns whether the given error is a timeout error.

Types

type Codec

type Codec interface {
	// Marshal returns the wire format of v.
	Marshal(v interface{}) ([]byte, error)
	// Unmarshal parses the wire format into v.
	Unmarshal(data []byte, v interface{}) error
	// String returns the name of the Codec implementation.
	String() string
}

Codec defines the interface that this client uses to encode and decode messages. Note that implementations of this interface must be thread safe; a Codec's methods can be called from concurrent goroutines.

type ConnState

type ConnState int
const (
	// The state that a connection starts from.
	ConnStateInit ConnState = iota

	ConnStateConnecting

	ConnStateReady

	// The state that indicates some error occurred in the previous operations.
	ConnStateTransientFailure

	// The state that RpcConn will turn into after Close() is called.
	ConnStateClosed
)

func (ConnState) String

func (s ConnState) String() string

type ReadStream

type ReadStream struct {
	// contains filtered or unexported fields
}

low-level rpc reader.

func NewReadStream

func NewReadStream(reader io.Reader) *ReadStream

func (*ReadStream) Next

func (r *ReadStream) Next(toRead int) ([]byte, error)

type RpcConn

type RpcConn struct {
	Endpoint string
	// contains filtered or unexported fields
}

RpcConn maintains a network connection to a particular endpoint.

func NewFakeRpcConn

func NewFakeRpcConn(reader io.Reader, writer io.Writer) *RpcConn

Create a fake client with specified reader and writer.

func NewRpcConn

func NewRpcConn(addr string) *RpcConn

Returns an idle connection.

func (*RpcConn) Close

func (rc *RpcConn) Close() (err error)

This function is thread-safe.

func (*RpcConn) GetState

func (rc *RpcConn) GetState() ConnState

thread-safe

func (*RpcConn) Read

func (rc *RpcConn) Read(size int) (bytes []byte, err error)

Read is not intended to be cancellable using context by outside user. The only approach to cancel the operation is to close the connection. If the current socket is not well established for reading, the operation will fail and return error immediately. This function is not-thread-safe, because the underlying TCP IO buffer is not-thread-safe. Package users should call Read in a single goroutine.

func (*RpcConn) SetReadTimeout

func (rc *RpcConn) SetReadTimeout(timeout time.Duration)

Not thread-safe

func (*RpcConn) SetWriteTimeout

func (rc *RpcConn) SetWriteTimeout(timeout time.Duration)

Not thread-safe

func (*RpcConn) TryConnect

func (rc *RpcConn) TryConnect() (err error)

This function is thread-safe.

func (*RpcConn) Write

func (rc *RpcConn) Write(msgBytes []byte) (err error)

type WriteStream

type WriteStream struct {
	// contains filtered or unexported fields
}

low-level rpc writer.

func NewWriteStream

func NewWriteStream(writer io.Writer) *WriteStream

NewWriteStream always receives a *net.TcpConn as `writer`, except in testing it can accept a buffer as the fake writer.

func (*WriteStream) Write

func (s *WriteStream) Write(msgBytes []byte) error

invoke an asynchronous write for message.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL