Documentation ¶
Index ¶
- Constants
- Variables
- func IsNetworkClosed(err error) bool
- func IsNetworkTimeoutErr(err error) bool
- type Codec
- type ConnState
- type ReadStream
- type RpcConn
- func (rc *RpcConn) Close() (err error)
- func (rc *RpcConn) GetState() ConnState
- func (rc *RpcConn) Read(size int) (bytes []byte, err error)
- func (rc *RpcConn) SetReadTimeout(timeout time.Duration)
- func (rc *RpcConn) SetWriteTimeout(timeout time.Duration)
- func (rc *RpcConn) TryConnect() (err error)
- func (rc *RpcConn) Write(msgBytes []byte) (err error)
- type WriteStream
Constants ¶
const ( ConnDialTimeout = time.Second * 3 ConnReadTimeout = 30 * time.Second ConnWriteTimeout = 10 * time.Second )
TODO(wutao1): make these parameters configurable
Variables ¶
var ErrConnectionNotReady = errors.New("connection is not ready")
Functions ¶
func IsNetworkClosed ¶
IsNetworkClosed returns whether the session is shutdown by the peer.
func IsNetworkTimeoutErr ¶
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 )
type ReadStream ¶
type ReadStream struct {
// contains filtered or unexported fields
}
low-level rpc reader.
func NewReadStream ¶
func NewReadStream(reader io.Reader) *ReadStream
type RpcConn ¶
type RpcConn struct { Endpoint string // contains filtered or unexported fields }
RpcConn maintains a network connection to a particular endpoint.
func NewFakeRpcConn ¶
Create a fake client with specified reader and writer.
func (*RpcConn) Read ¶
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 ¶
Not thread-safe
func (*RpcConn) SetWriteTimeout ¶
Not thread-safe
func (*RpcConn) TryConnect ¶
This function is thread-safe.
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.