Documentation ¶
Index ¶
- Constants
- Variables
- func CanSetBool(x reflect.Value) bool
- func CanSetFloat(x reflect.Value) bool
- func CanSetInt(x reflect.Value) bool
- func CanSetUint(x reflect.Value) bool
- func HttpRsp404(current *CurrentContent)
- func HttpRspOk(current *CurrentContent)
- func HttpRspString(current *CurrentContent, rsp string)
- func Marshal(m interface{}, encodeType int) ([]byte, error)
- func SpbDecode(data []byte, x interface{}) error
- func SpbEncode(data interface{}) ([]byte, error)
- func Unmarshal(data []byte, m interface{}, encodeType int) error
- type BufferPool
- type CMDType
- type Closer
- type Connect
- type Connector
- func (c *Connector) Addr() string
- func (c *Connector) ChangeAddr(addr string)
- func (c *Connector) Close()
- func (c *Connector) GetID() uint64
- func (c *Connector) IsClose() bool
- func (c *Connector) IsConnected() bool
- func (c *Connector) NotifyReconn()
- func (c *Connector) ReconnCount() int
- func (c *Connector) Send(data []byte) error
- func (c *Connector) Session() *Session
- type CurrentContent
- type FuncOnClose
- type FuncOnOpen
- type HttpService
- type Listener
- type LoopService
- type MsgParse
- type ReqProto
- type RpcFuncException
- type RpcService
- type RspProto
- type Server
- func (svr *Server) AddEchoService(name, address string, heartbeat uint32, threadId int) (*Service, error)
- func (svr *Server) AddHttpService(name, address string, heartbeat uint32, imp HttpService, threadId int) (*Service, error)
- func (svr *Server) AddLoopService(name string, imp LoopService, threadId int) (*Service, error)
- func (svr *Server) AddRpcService(name, address string, heartbeat uint32, imp *ServiceRpc, threadId int) (*Service, error)
- func (svr *Server) AddService(name, address string, heartbeat uint32, imp ServiceImp, threadId int) (*Service, error)
- func (svr *Server) AddTcpProxyService(address string, heartbeat uint32, threadId int, proxyaddr []string, ...) error
- func (svr *Server) Start() error
- func (svr *Server) Stop()
- type Service
- func (service *Service) GetConnect(id uint64) *Connect
- func (service *Service) Imp() ServiceImp
- func (service *Service) IterateConnect(callback func(*Connect) bool)
- func (service *Service) NewConnect(address string, userdata interface{}) *Connect
- func (service *Service) ParseMsg(sess *Session, data []byte) int
- type ServiceBase
- func (service *ServiceBase) Destroy()
- func (service *ServiceBase) HandleError(current *CurrentContent, err error)
- func (service *ServiceBase) HandleMessage(current *CurrentContent, msgID uint64, msg interface{})
- func (service *ServiceBase) HashProcessor(current *CurrentContent, msgID uint64, msg interface{}) (processorID int)
- func (service *ServiceBase) HeartBeatTimeOut(sess *Session)
- func (service *ServiceBase) Init() bool
- func (service *ServiceBase) Loop()
- func (service *ServiceBase) SessionClose(sess *Session)
- func (service *ServiceBase) SessionOpen(sess *Session)
- func (service *ServiceBase) Unmarshal(sess *Session, data []byte) (lenParsed int, msgID int64, msg interface{}, err error)
- type ServiceEcho
- type ServiceHttp
- func (service *ServiceHttp) HandleError(current *CurrentContent, err error)
- func (service *ServiceHttp) HandleMessage(current *CurrentContent, msgID uint64, msg interface{})
- func (service *ServiceHttp) HashProcessor(current *CurrentContent, msgID uint64, msg interface{}) (processorID int)
- func (service *ServiceHttp) Init() bool
- func (service *ServiceHttp) Loop()
- func (service *ServiceHttp) Unmarshal(sess *Session, data []byte) (lenParsed int, msgID int64, msg interface{}, err error)
- type ServiceImp
- type ServiceLoop
- type ServiceProxyC
- type ServiceProxyS
- func (service *ServiceProxyS) HandleError(current *CurrentContent, err error)
- func (service *ServiceProxyS) HashProcessor(current *CurrentContent, msgID uint64, msg interface{}) (processorID int)
- func (service *ServiceProxyS) HeartBeatTimeOut(sess *Session)
- func (service *ServiceProxyS) SessionClose(sess *Session)
- func (service *ServiceProxyS) Unmarshal(sess *Session, data []byte) (lenParsed int, msgID int64, msg interface{}, err error)
- type ServiceRpc
- func (service *ServiceRpc) HandleError(current *CurrentContent, err error)
- func (service *ServiceRpc) HandleMessage(current *CurrentContent, msgID uint64, msg interface{})
- func (service *ServiceRpc) HashProcessor(current *CurrentContent, msgID uint64, msg interface{}) (processorID int)
- func (service *ServiceRpc) Init() bool
- func (service *ServiceRpc) Loop()
- func (service *ServiceRpc) RpcCall(sess *Session, funcName string, params ...interface{}) error
- func (service *ServiceRpc) RpcCall_Sync(sess *Session, funcName string, params ...interface{}) error
- func (service *ServiceRpc) SendReq(sess *Session, req ReqProto) error
- func (service *ServiceRpc) SendRsp(sess *Session, rsp RspProto) error
- func (service *ServiceRpc) SendUdpReq(sess *Session, peer net.Addr, req ReqProto) error
- func (service *ServiceRpc) SendUdpRsp(sess *Session, peer net.Addr, rsp RspProto) error
- func (service *ServiceRpc) UdpRpcCall(sess *Session, peer net.Addr, funcName string, params ...interface{}) error
- func (service *ServiceRpc) UdpRpcCall_Sync(sess *Session, peer net.Addr, funcName string, params ...interface{}) error
- func (service *ServiceRpc) Unmarshal(sess *Session, data []byte) (lenParsed int, msgID int64, msg interface{}, err error)
- type Session
- type Spb
Constants ¶
View Source
const ( EncodeTyepSpb = 0 EncodeTyepJson = 1 )
View Source
const ( RpcErrNoRemoteFunc = -1 RpcErrCallTimeout = -2 RpcErrFuncParamErr = -3 )
View Source
const ( SpbPackDataType_Integer_Positive = 0 SpbPackDataType_Integer_Negative = 1 SpbPackDataType_Float = 2 SpbPackDataType_Double = 3 SpbPackDataType_String = 4 SpbPackDataType_Vector = 5 SpbPackDataType_Map = 6 SpbPackDataType_StructBegin = 7 SpbPackDataType_StructEnd = 8 )
Variables ¶
View Source
var ( ErrSocketClosed = errors.New("socket closed") ErrSocketIsOpen = errors.New("socket is open") ErrSendOverTime = errors.New("send message over time") ErrSendBuffIsFull = errors.New("send buffer is full") ErrMsgParseNil = errors.New("MsgParse is nil") )
View Source
var ( MsgBuffSize = 1024 MinMsgSize = 64 MaxMsgSize = 2 * 1024 * 1024 //the length of send queue WriterListLen = 256 RecvListLen = 256 )
message recv buffer size
View Source
var GlobalSessionID uint64
session id
View Source
var (
SysLog *stlog.Logger
)
View Source
var (
TimeOut int64 = 5 //sec
)
Functions ¶
func CanSetBool ¶ added in v1.1.0
func CanSetFloat ¶ added in v1.1.0
func CanSetUint ¶ added in v1.1.0
func HttpRsp404 ¶ added in v1.1.0
func HttpRsp404(current *CurrentContent)
func HttpRspOk ¶ added in v1.1.0
func HttpRspOk(current *CurrentContent)
func HttpRspString ¶ added in v1.1.0
func HttpRspString(current *CurrentContent, rsp string)
Types ¶
type BufferPool ¶
type BufferPool struct { }
func (*BufferPool) Alloc ¶
func (bp *BufferPool) Alloc(bufsize int) []byte
func (*BufferPool) Free ¶
func (bp *BufferPool) Free([]byte)
type Connector ¶
type Connector struct {
// contains filtered or unexported fields
}
func NewConnector ¶
NewConnector reconnect at 0s 1s 4s 9s 16s...;when call send changeAddr NotifyReconn, reconnect at once
func (*Connector) ChangeAddr ¶
func (*Connector) IsConnected ¶
func (*Connector) NotifyReconn ¶
func (c *Connector) NotifyReconn()
func (*Connector) ReconnCount ¶
type CurrentContent ¶
type HttpService ¶
type HttpService interface { Init() bool Loop() Handle(current *CurrentContent, req *http.Request, e error) HashProcessor(current *CurrentContent, req *http.Request) (processorID int) }
type Listener ¶
type Listener struct {
// contains filtered or unexported fields
}
func NewListener ¶
func NewUdpListener ¶ added in v1.1.0
func (*Listener) GetSession ¶
func (*Listener) IterateSession ¶
type LoopService ¶
type LoopService interface { Init() bool Loop() }
type RpcFuncException ¶ added in v1.1.0
type RpcFuncException func(rspCode int32)
type RpcService ¶ added in v1.1.0
type RpcService interface { Loop() HandleError(current *CurrentContent, err error) HashProcessor(current *CurrentContent) (processorID int) }
type Server ¶
type Server struct { ProcessorThreadsNum int //number of threads in server. // contains filtered or unexported fields }
func (*Server) AddEchoService ¶
func (*Server) AddHttpService ¶
func (*Server) AddLoopService ¶
func (*Server) AddRpcService ¶ added in v1.1.0
func (svr *Server) AddRpcService(name, address string, heartbeat uint32, imp *ServiceRpc, threadId int) (*Service, error)
AddRpcService imp: NewServiceRpc
func (*Server) AddService ¶
func (svr *Server) AddService(name, address string, heartbeat uint32, imp ServiceImp, threadId int) (*Service, error)
AddService must be called before server started. address could be null,then you get a service without listen. when heartbeat(second)=0,heartbeat will be close. call service.NewConnect start a connector
func (*Server) AddTcpProxyService ¶
type Service ¶
func (*Service) GetConnect ¶
func (*Service) Imp ¶
func (service *Service) Imp() ServiceImp
func (*Service) IterateConnect ¶
func (*Service) NewConnect ¶
type ServiceBase ¶
type ServiceBase struct { }
ServiceImpBase
func (*ServiceBase) Destroy ¶
func (service *ServiceBase) Destroy()
func (*ServiceBase) HandleError ¶
func (service *ServiceBase) HandleError(current *CurrentContent, err error)
func (*ServiceBase) HandleMessage ¶
func (service *ServiceBase) HandleMessage(current *CurrentContent, msgID uint64, msg interface{})
func (*ServiceBase) HashProcessor ¶
func (service *ServiceBase) HashProcessor(current *CurrentContent, msgID uint64, msg interface{}) (processorID int)
func (*ServiceBase) HeartBeatTimeOut ¶
func (service *ServiceBase) HeartBeatTimeOut(sess *Session)
func (*ServiceBase) Init ¶
func (service *ServiceBase) Init() bool
func (*ServiceBase) Loop ¶
func (service *ServiceBase) Loop()
func (*ServiceBase) SessionClose ¶
func (service *ServiceBase) SessionClose(sess *Session)
func (*ServiceBase) SessionOpen ¶
func (service *ServiceBase) SessionOpen(sess *Session)
type ServiceEcho ¶
type ServiceEcho struct {
ServiceBase
}
ServiceImpEcho
func (*ServiceEcho) HashProcessor ¶
func (service *ServiceEcho) HashProcessor(current *CurrentContent, msgID uint64, msg interface{}) (processorID int)
type ServiceHttp ¶
type ServiceHttp struct { ServiceBase // contains filtered or unexported fields }
ServiceHttp
func (*ServiceHttp) HandleError ¶
func (service *ServiceHttp) HandleError(current *CurrentContent, err error)
func (*ServiceHttp) HandleMessage ¶
func (service *ServiceHttp) HandleMessage(current *CurrentContent, msgID uint64, msg interface{})
func (*ServiceHttp) HashProcessor ¶
func (service *ServiceHttp) HashProcessor(current *CurrentContent, msgID uint64, msg interface{}) (processorID int)
func (*ServiceHttp) Init ¶ added in v1.1.0
func (service *ServiceHttp) Init() bool
func (*ServiceHttp) Loop ¶ added in v1.1.0
func (service *ServiceHttp) Loop()
type ServiceImp ¶
type ServiceImp interface { Init() bool Loop() Destroy() HandleMessage(current *CurrentContent, msgID uint64, msg interface{}) HandleError(*CurrentContent, error) SessionOpen(sess *Session) SessionClose(sess *Session) HeartBeatTimeOut(sess *Session) // Unmarshal protocol parsed //lenParsed is the length read from 'data'. //msgID and msg are messages parsed from data. //when lenParsed <= 0 or msgID < 0,msg and err will be ignored. Unmarshal(sess *Session, data []byte) (lenParsed int, msgID int64, msg interface{}, err error) // HashProcessor sess msgID msg are returned by func of Unmarshal //processorID is the thread who process this msg;it should between 1-ProcessorThreadsNum. //if processorID == 0, it only uses main thread of the service. //if processorID < 0, it will use hash of session id. HashProcessor(current *CurrentContent, msgID uint64, msg interface{}) (processorID int) }
type ServiceLoop ¶
type ServiceLoop struct { ServiceBase // contains filtered or unexported fields }
func (*ServiceLoop) Init ¶
func (service *ServiceLoop) Init() bool
func (*ServiceLoop) Loop ¶
func (service *ServiceLoop) Loop()
type ServiceProxyC ¶
type ServiceProxyC struct {
ServiceBase
}
func (*ServiceProxyC) HashProcessor ¶
func (service *ServiceProxyC) HashProcessor(current *CurrentContent, msgID uint64, msg interface{}) (processorID int)
type ServiceProxyS ¶
type ServiceProxyS struct { ServiceBase // contains filtered or unexported fields }
func (*ServiceProxyS) HandleError ¶
func (service *ServiceProxyS) HandleError(current *CurrentContent, err error)
func (*ServiceProxyS) HashProcessor ¶
func (service *ServiceProxyS) HashProcessor(current *CurrentContent, msgID uint64, msg interface{}) (processorID int)
func (*ServiceProxyS) HeartBeatTimeOut ¶
func (service *ServiceProxyS) HeartBeatTimeOut(sess *Session)
func (*ServiceProxyS) SessionClose ¶
func (service *ServiceProxyS) SessionClose(sess *Session)
type ServiceRpc ¶ added in v1.1.0
type ServiceRpc struct { ServiceBase // contains filtered or unexported fields }
func NewServiceRpc ¶ added in v1.1.0
func NewServiceRpc(imp RpcService) *ServiceRpc
func (*ServiceRpc) HandleError ¶ added in v1.1.0
func (service *ServiceRpc) HandleError(current *CurrentContent, err error)
func (*ServiceRpc) HandleMessage ¶ added in v1.1.0
func (service *ServiceRpc) HandleMessage(current *CurrentContent, msgID uint64, msg interface{})
func (*ServiceRpc) HashProcessor ¶ added in v1.1.0
func (service *ServiceRpc) HashProcessor(current *CurrentContent, msgID uint64, msg interface{}) (processorID int)
func (*ServiceRpc) Init ¶ added in v1.1.0
func (service *ServiceRpc) Init() bool
func (*ServiceRpc) Loop ¶ added in v1.1.0
func (service *ServiceRpc) Loop()
func (*ServiceRpc) RpcCall ¶ added in v1.1.0
func (service *ServiceRpc) RpcCall(sess *Session, funcName string, params ...interface{}) error
RpcCall remotesession remotefunction(string) functionparams callback(could nil) exception(could nil, func(rspCode int32))
func (*ServiceRpc) RpcCall_Sync ¶ added in v1.1.0
func (service *ServiceRpc) RpcCall_Sync(sess *Session, funcName string, params ...interface{}) error
func (*ServiceRpc) SendReq ¶ added in v1.1.0
func (service *ServiceRpc) SendReq(sess *Session, req ReqProto) error
func (*ServiceRpc) SendRsp ¶ added in v1.1.0
func (service *ServiceRpc) SendRsp(sess *Session, rsp RspProto) error
func (*ServiceRpc) SendUdpReq ¶ added in v1.1.0
func (*ServiceRpc) SendUdpRsp ¶ added in v1.1.0
func (*ServiceRpc) UdpRpcCall ¶ added in v1.1.0
func (*ServiceRpc) UdpRpcCall_Sync ¶ added in v1.1.0
type Session ¶
type Session struct { UserData interface{} // contains filtered or unexported fields }
func NewSession ¶
func NewSession(con net.Conn, msgparse MsgParse, onopen FuncOnOpen, onclose FuncOnClose, heartbeat uint32, isudp bool) (*Session, error)
func (*Session) RemoteAddr ¶
Click to show internal directories.
Click to hide internal directories.