worker

package
v1.5.28 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2021 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MIN_DATA_SIZE    = 12
	UINT32_SIZE      = 4
	QUEUE_SIZE       = 64
	BUFFER_SIZE      = 512
	DEFAULT_TIME_OUT = 5 * time.Second

	//package data type
	PDT_OK            = 1
	PDT_ERROR         = 2
	PDT_CAN_DO        = 3
	PDT_CANT_DO       = 4
	PDT_NO_JOB        = 5
	PDT_HAVE_JOB      = 6
	PDT_TOSLEEP       = 7
	PDT_WAKEUP        = 8
	PDT_WAKEUPED      = 9
	PDT_S_GET_DATA    = 10
	PDT_S_RETURN_DATA = 11
	PDT_W_GRAB_JOB    = 12
	PDT_W_ADD_FUNC    = 13
	PDT_W_DEL_FUNC    = 14
	PDT_W_RETURN_DATA = 15
	PDT_C_DO_JOB      = 16
	PDT_C_GET_DATA    = 17
)
View Source
const (
	CONN_TYPE_INIT   = 0
	CONN_TYPE_SERVER = 1
	CONN_TYPE_WORKER = 2
	CONN_TYPE_CLIENT = 3
	PARAMS_TYPE_ONE  = 4
	PARAMS_TYPE_MUL  = 5
	JOB_STATUS_INIT  = 6
	JOB_STATUS_DOING = 7
	JOB_STATUS_DONE  = 8
)

Variables

View Source
var RESTIMEOUT = errors.New("RESTIMEOUT")

Functions

func GetBuffer

func GetBuffer(n int) (buf []byte)

func GetConnType

func GetConnType(data []byte) (connType uint32)

Types

type Client

type Client struct {
	sync.Mutex

	Req      *Request
	ResQueue chan *Response

	Timeout time.Duration

	ErrHandler   ErrHandler
	RespHandlers *RespHandlerMap
	// contains filtered or unexported fields
}

func NewClient

func NewClient(network, addr string) (client *Client, err error)

func (*Client) ClientRead

func (c *Client) ClientRead()

func (*Client) Close

func (c *Client) Close()

func (*Client) Do

func (c *Client) Do(funcName string, params []byte, callback RespHandler) (err error)

func (*Client) HandlerResp

func (c *Client) HandlerResp(resp *Response)

func (*Client) ProcessResp

func (c *Client) ProcessResp()

func (*Client) Read

func (c *Client) Read(length int) (data []byte, err error)

func (*Client) Write

func (c *Client) Write() (err error)

type ErrHandler

type ErrHandler func(err error)

type Request

type Request struct {
	DataType uint32
	Data     []byte
	DataLen  uint32

	Handle     string
	HandleLen  uint32
	ParamsType uint32
	ParamsLen  uint32
	Params     []byte
	Ret        []byte
	RetLen     uint32
}

func NewReq

func NewReq() (req *Request)

func (*Request) ContentPack

func (req *Request) ContentPack(dataType uint32, handle string, params []byte) (content []byte, contentLen uint32)

打包内容

func (*Request) EncodePack

func (req *Request) EncodePack() (data []byte)

打包

type RespHandler

type RespHandler func(resp *Response)

type RespHandlerMap

type RespHandlerMap struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewResHandlerMap

func NewResHandlerMap() *RespHandlerMap

func (*RespHandlerMap) DelResHandlerMap

func (rhm *RespHandlerMap) DelResHandlerMap(key string)

func (*RespHandlerMap) GetResHandlerMap

func (rhm *RespHandlerMap) GetResHandlerMap(key string) (handler RespHandler, exist bool)

func (*RespHandlerMap) PutResHandlerMap

func (rhm *RespHandlerMap) PutResHandlerMap(key string, handler RespHandler)

type Response

type Response struct {
	DataType   uint32
	Data       []byte
	DataLen    uint32
	Handle     string
	HandleLen  uint32
	ParamsType uint32
	ParamsLen  uint32
	Params     []byte
	Ret        []byte
	RetLen     uint32
}

func DecodePack

func DecodePack(data []byte) (resp *Response, resLen int, err error)

解包

func NewRes

func NewRes() (res *Response)

func (*Response) GetResError

func (resp *Response) GetResError() (err error)

func (*Response) GetResResult

func (resp *Response) GetResResult() (data []byte, err error)

type RetStruct

type RetStruct struct {
	Code int
	Msg  string
	Data []byte
}

func GetRetStruct

func GetRetStruct() *RetStruct

Jump to

Keyboard shortcuts

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