gob

package
v0.0.0-...-5a37ffa Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2018 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CallTypeNone   = 0
	CallTypeLoop   = 1
	CallTypeOnce   = 2
	CallTypeCancel = 3
)

Variables

View Source
var ErrNotSuportType = errors.New("type is not suported")
View Source
var ErrPendingTooLong = errors.New("call is pending too long")
View Source
var ErrSendError = errors.New("got error when send to network")
View Source
var ErrShutdown = errors.New("connection is shut down")

Functions

func Register

func Register(msg IMsg) (err error)

Register msg要先注册后,才能正确接收该类型的数据

Types

type Call

type Call struct {
	Args      interface{}  // Args作为请求的body
	ReplyType reflect.Type // 需要的返回值类型 (*struct)

	MethodNO uint32                             //请求类型
	Done     func(reply interface{}, err error) //在收到返回值或未能正确调用的时候调用
	Type     uint32                             //调用类型,只发不等待请求数据,none:0;一次请求循环多次接收,loop:1; 一次请求一次接收,once:2;取消调用:cancel:3
	TimeOut  int64                              //超时时间,超市部分赶回,则代表调用失败
}

type Client

type Client struct {
	sync.Mutex // protects following
	// contains filtered or unexported fields
}

func Dial

func Dial(network, address string) (*Client, error)

Dial connects to an RPC server at the specified network address.

func NewClient

func NewClient(conn io.ReadWriteCloser) *Client

func (*Client) Close

func (client *Client) Close() error

func (*Client) GetReply

func (client *Client) GetReply(args IMsg,
	reply IMsg,
	_type uint32,
	timeOut int64,
	doneFunc func(reply interface{}, err error),
)

SendReply 外部发rpc的时候调用

func (*Client) Send

func (client *Client) Send(args IMsg) (err error)

Send 外部发rpc的时候调用

func (*Client) SendCall

func (client *Client) SendCall(call *Call)

SendCall 外部发rpc的时候调用

type ClientCodec

type ClientCodec interface {
	// WriteRequest must be safe for concurrent use by multiple goroutines.
	WriteRequest(*Request, interface{}) error
	ReadResponseHeader(*Response) error
	ReadResponseBody(interface{}) error

	Close() error
}

type IMsg

type IMsg interface {
	RecvMsg(logT *log.TraceInfoST) (msgs PkgRtn, err error)
	//MsgNO() uint16 //返回对应的消息编号,每种消息一个编号,保证唯一性
	IMsgRtn
}

IMsg 是路由层(消息分发层)和逻辑层(消息处理层)之间传递的数据结构,Msg:message的缩写

type IMsgRtn

type IMsgRtn interface {
	MsgNO() uint16 //消息编号
}

IMsgRtn 是路由层(消息分发层)和逻辑层(消息处理层)之间传递的数据结构,Msg:message的缩写

type Pkg

type Pkg struct {
	Msg IMsg

	//gob的每个请求都有一个自动增加的针对连接唯一的编号,相当于是一个session,
	//当client收到数据时,client会根据编号调用回调函数,
	//所以,server端收到消息后,必须保存消息的编号,以便在回复消息的时候有目的地!
	Seq uint64
}

Pkg 每次收到消息,通过这个结构包装后写到channel中

type PkgRtn

type PkgRtn struct {
	Msg IMsgRtn
	Seq uint64 //gob的每个请求都有一个自动增加的针对连接唯一的编号,相当于是一个session

	LogT *log.TraceInfoST
}

MsgRtn 是RecvMsg()方法的返回值,Msg:message的缩写,Rtn:return的缩写

type Request

type Request struct {
	MethodNO uint32 //
	Seq      uint64 // sequence number chosen by client
	// contains filtered or unexported fields
}

type Response

type Response struct {
	MethodNO uint32 // echoes that of the Request
	Seq      uint64 // echoes that of the request
	Error    string // error, if any.
	// contains filtered or unexported fields
}

type Server

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

Server 一条连接一个Server,连接的相关的信息可以存这里

func NewServer

func NewServer() *Server

NewServer returns a new Server.

func (*Server) ServeConn

func (server *Server) ServeConn(conn io.ReadWriteCloser) (channel.IChanN, channel.IChanN, error)

type ServerCodec

type ServerCodec interface {
	ReadRequestHeader(*Request) error
	ReadRequestBody(interface{}) error
	// WriteResponse must be safe for concurrent use by multiple goroutines.
	WriteResponse(*Response, interface{}) error

	Close() error
}

type ServerError

type ServerError string

func (ServerError) Error

func (e ServerError) Error() string

Directories

Path Synopsis
test

Jump to

Keyboard shortcuts

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