Documentation ¶
Index ¶
- Constants
- Variables
- func DecodeRequestBody(req *http.Request, ptr interface{}) error
- func GetClientIP(req *http.Request) string
- func NewFakeConn(node fatchoy.NodeID, addr string) fatchoy.Endpoint
- func NewFakeEndpoint(node fatchoy.NodeID, ud interface{}) fatchoy.Endpoint
- func ReadLenMessage(conn net.Conn, msg proto.Message) error
- func ReadProtoMessage(conn net.Conn, enc codec.Encoder, decrypt cipher.BlockCryptor, ...) error
- func RequestProtoMessage(conn net.Conn, enc codec.Encoder, command int32, req, resp proto.Message) error
- func RequestRawMessage(conn net.Conn, req, ack proto.Message) error
- func SendProtoMessage(conn io.Writer, enc codec.Encoder, encrypt cipher.BlockCryptor, command int32, ...) error
- func WriteLenMessage(conn net.Conn, msg proto.Message) error
- type Buffer
- func (b *Buffer) PeekBool() bool
- func (b *Buffer) PeekFloat32() float32
- func (b *Buffer) PeekFloat64() float64
- func (b *Buffer) PeekInt16() int16
- func (b *Buffer) PeekInt32() int32
- func (b *Buffer) PeekInt64() int64
- func (b *Buffer) PeekInt8() int8
- func (b *Buffer) PeekUint16() uint16
- func (b *Buffer) PeekUint32() uint32
- func (b *Buffer) PeekUint64() uint64
- func (b *Buffer) PeekUint8() uint8
- func (b *Buffer) ReadBool() bool
- func (b *Buffer) ReadFloat32() float32
- func (b *Buffer) ReadFloat64() float64
- func (b *Buffer) ReadInt16() int16
- func (b *Buffer) ReadInt32() int32
- func (b *Buffer) ReadInt64() int64
- func (b *Buffer) ReadInt8() int8
- func (b *Buffer) ReadUint16() uint16
- func (b *Buffer) ReadUint32() uint32
- func (b *Buffer) ReadUint64() uint64
- func (b *Buffer) ReadUint8() uint8
- func (b *Buffer) WriteBool(v bool)
- func (b *Buffer) WriteFloat32(f float32)
- func (b *Buffer) WriteFloat64(f float64)
- func (b *Buffer) WriteInt16(n int16)
- func (b *Buffer) WriteInt32(n int32)
- func (b *Buffer) WriteInt64(n int64)
- func (b *Buffer) WriteInt8(n int8)
- func (b *Buffer) WriteUInt8(n uint8)
- func (b *Buffer) WriteUint16(n uint16)
- func (b *Buffer) WriteUint32(n uint32)
- func (b *Buffer) WriteUint64(n uint64)
- type ConcurrentEndpointMap
- func (m *ConcurrentEndpointMap) Clear()
- func (m *ConcurrentEndpointMap) Foreach(action func(fatchoy.Endpoint) int)
- func (m *ConcurrentEndpointMap) Get(node fatchoy.NodeID) fatchoy.Endpoint
- func (m *ConcurrentEndpointMap) Has(node fatchoy.NodeID) bool
- func (m *ConcurrentEndpointMap) IsEmpty() bool
- func (m *ConcurrentEndpointMap) IterBuffered() <-chan Tuple
- func (m *ConcurrentEndpointMap) Keys() []fatchoy.NodeID
- func (m *ConcurrentEndpointMap) Pop(node fatchoy.NodeID) fatchoy.Endpoint
- func (m *ConcurrentEndpointMap) Put(node fatchoy.NodeID, endpoint fatchoy.Endpoint)
- func (m *ConcurrentEndpointMap) PutIfAbsent(node fatchoy.NodeID, endpoint fatchoy.Endpoint)
- func (m *ConcurrentEndpointMap) Remove(node fatchoy.NodeID)
- func (m *ConcurrentEndpointMap) Size() int
- func (m *ConcurrentEndpointMap) Values() []fatchoy.Endpoint
- type EndpointHashMap
- func (m *EndpointHashMap) Clear()
- func (m *EndpointHashMap) Foreach(action func(fatchoy.Endpoint) int)
- func (m *EndpointHashMap) Get(node fatchoy.NodeID) fatchoy.Endpoint
- func (m *EndpointHashMap) Has(node fatchoy.NodeID) bool
- func (m *EndpointHashMap) IsEmpty() bool
- func (m *EndpointHashMap) Keys() []fatchoy.NodeID
- func (m *EndpointHashMap) Pop(node fatchoy.NodeID) fatchoy.Endpoint
- func (m *EndpointHashMap) Put(node fatchoy.NodeID, endpoint fatchoy.Endpoint)
- func (m *EndpointHashMap) PutIfAbsent(node fatchoy.NodeID, endpoint fatchoy.Endpoint)
- func (m *EndpointHashMap) Remove(node fatchoy.NodeID)
- func (m *EndpointHashMap) Size() int
- func (m *EndpointHashMap) Values() []fatchoy.Endpoint
- type EndpointMapShard
- type Error
- type FakeConn
- type FakeEndpoint
- func (e *FakeEndpoint) Close() error
- func (e *FakeEndpoint) ErrorChan() <-chan error
- func (e *FakeEndpoint) ForceClose(error)
- func (e *FakeEndpoint) Go(fatchoy.EndpointFlag)
- func (e *FakeEndpoint) IsRunning() bool
- func (e *FakeEndpoint) Node() fatchoy.NodeID
- func (e *FakeEndpoint) OutMsgChan() chan<- *fatchoy.Packet
- func (e *FakeEndpoint) RawConn() net.Conn
- func (e *FakeEndpoint) RemoteAddr() string
- func (e *FakeEndpoint) Send(pkt *fatchoy.Packet) error
- func (e *FakeEndpoint) SetEncryptPair(cipher.BlockCryptor, cipher.BlockCryptor)
- func (e *FakeEndpoint) SetNode(v fatchoy.NodeID)
- func (e *FakeEndpoint) SetUserData(v interface{})
- func (e *FakeEndpoint) Stats() *stats.Stats
- func (e *FakeEndpoint) UserData() interface{}
- type StreamConn
- func (c *StreamConn) ErrorChan() <-chan error
- func (c *StreamConn) Init(node fatchoy.NodeID, enc codec.Encoder, incoming chan<- *fatchoy.Packet, ...)
- func (c *StreamConn) IsRunning() bool
- func (c *StreamConn) Node() fatchoy.NodeID
- func (c *StreamConn) OutMsgChan() chan<- *fatchoy.Packet
- func (c *StreamConn) RemoteAddr() string
- func (c *StreamConn) SetEncryptPair(encrypt cipher.BlockCryptor, decrypt cipher.BlockCryptor)
- func (c *StreamConn) SetNode(node fatchoy.NodeID)
- func (c *StreamConn) SetRemoteAddr(addr string)
- func (c *StreamConn) SetUserData(ud interface{})
- func (c *StreamConn) Stats() *stats.Stats
- func (c *StreamConn) UserData() interface{}
- type TcpConn
- type TcpServer
- type Tuple
Constants ¶
View Source
const ( StatBytesRecv int = iota // bytes received StatBytesSent // bytes sent StatPacketsRecv // packets received StatPacketsSent // packets sent NumStat )
View Source
const EndpointMapShardCount = 16
Variables ¶
View Source
var ( ErrConnIsClosing = errors.New("connection is closing when sending") ErrConnOutboundOverflow = errors.New("connection outbound queue overflow") ErrConnForceClose = errors.New("connection forced to close") )
View Source
var ErrBufferOutOfRange = errors.New("buffer out of range")
View Source
var (
RequestReadTimeout = 100 // 默认read超时时间,100s
)
View Source
var (
TConnReadTimeout = 200 // seconds
)
Functions ¶
func DecodeRequestBody ¶ added in v0.6.3
解析http请求的body为json
func NewFakeEndpoint ¶ added in v0.3.10
func ReadLenMessage ¶ added in v0.1.5
读取2字节开头的message
func ReadProtoMessage ¶ added in v0.1.12
func ReadProtoMessage(conn net.Conn, enc codec.Encoder, decrypt cipher.BlockCryptor, msg proto.Message) error
读取一条protobuf消息
func RequestProtoMessage ¶ added in v0.1.12
func RequestProtoMessage(conn net.Conn, enc codec.Encoder, command int32, req, resp proto.Message) error
send并且立即recv(不加密)
func RequestRawMessage ¶ added in v0.6.3
写入req并且等待读取ack
Types ¶
type Buffer ¶
func (*Buffer) PeekFloat32 ¶
func (*Buffer) PeekFloat64 ¶
func (*Buffer) PeekUint16 ¶
func (*Buffer) PeekUint32 ¶
func (*Buffer) PeekUint64 ¶
func (*Buffer) ReadFloat32 ¶
func (*Buffer) ReadFloat64 ¶
func (*Buffer) ReadUint16 ¶
func (*Buffer) ReadUint32 ¶
func (*Buffer) ReadUint64 ¶
func (*Buffer) WriteFloat32 ¶
func (*Buffer) WriteFloat64 ¶
func (*Buffer) WriteInt16 ¶
func (*Buffer) WriteInt32 ¶
func (*Buffer) WriteInt64 ¶
func (*Buffer) WriteUInt8 ¶
func (*Buffer) WriteUint16 ¶
func (*Buffer) WriteUint32 ¶
func (*Buffer) WriteUint64 ¶
type ConcurrentEndpointMap ¶ added in v0.3.10
type ConcurrentEndpointMap struct {
// contains filtered or unexported fields
}
线程安全的EndpointMap,适合数据量很大的场景
func NewConcurrentEndpointMap ¶ added in v0.3.10
func NewConcurrentEndpointMap() *ConcurrentEndpointMap
func (*ConcurrentEndpointMap) Clear ¶ added in v0.3.10
func (m *ConcurrentEndpointMap) Clear()
func (*ConcurrentEndpointMap) Foreach ¶ added in v0.3.10
func (m *ConcurrentEndpointMap) Foreach(action func(fatchoy.Endpoint) int)
action应该对map是read-only
func (*ConcurrentEndpointMap) Get ¶ added in v0.3.10
func (m *ConcurrentEndpointMap) Get(node fatchoy.NodeID) fatchoy.Endpoint
func (*ConcurrentEndpointMap) Has ¶ added in v0.3.10
func (m *ConcurrentEndpointMap) Has(node fatchoy.NodeID) bool
func (*ConcurrentEndpointMap) IsEmpty ¶ added in v0.3.10
func (m *ConcurrentEndpointMap) IsEmpty() bool
func (*ConcurrentEndpointMap) IterBuffered ¶ added in v0.3.10
func (m *ConcurrentEndpointMap) IterBuffered() <-chan Tuple
IterBuffered returns a buffered iterator which could be used in a for range loop.
func (*ConcurrentEndpointMap) Keys ¶ added in v0.3.10
func (m *ConcurrentEndpointMap) Keys() []fatchoy.NodeID
func (*ConcurrentEndpointMap) Pop ¶ added in v0.3.10
func (m *ConcurrentEndpointMap) Pop(node fatchoy.NodeID) fatchoy.Endpoint
Pop removes an element from the map and returns it
func (*ConcurrentEndpointMap) Put ¶ added in v0.3.10
func (m *ConcurrentEndpointMap) Put(node fatchoy.NodeID, endpoint fatchoy.Endpoint)
func (*ConcurrentEndpointMap) PutIfAbsent ¶ added in v0.3.10
func (m *ConcurrentEndpointMap) PutIfAbsent(node fatchoy.NodeID, endpoint fatchoy.Endpoint)
func (*ConcurrentEndpointMap) Remove ¶ added in v0.3.10
func (m *ConcurrentEndpointMap) Remove(node fatchoy.NodeID)
func (*ConcurrentEndpointMap) Size ¶ added in v0.3.10
func (m *ConcurrentEndpointMap) Size() int
func (*ConcurrentEndpointMap) Values ¶ added in v0.3.10
func (m *ConcurrentEndpointMap) Values() []fatchoy.Endpoint
type EndpointHashMap ¶ added in v0.3.10
type EndpointHashMap struct {
// contains filtered or unexported fields
}
线程安全的EndpointMap,适合数据量不是很大的场景
func NewEndpointHashMap ¶ added in v0.3.10
func NewEndpointHashMap() *EndpointHashMap
func (*EndpointHashMap) Clear ¶ added in v0.3.10
func (m *EndpointHashMap) Clear()
func (*EndpointHashMap) Foreach ¶ added in v0.3.10
func (m *EndpointHashMap) Foreach(action func(fatchoy.Endpoint) int)
action应该对map是read-only
func (*EndpointHashMap) Get ¶ added in v0.3.10
func (m *EndpointHashMap) Get(node fatchoy.NodeID) fatchoy.Endpoint
func (*EndpointHashMap) Has ¶ added in v0.3.10
func (m *EndpointHashMap) Has(node fatchoy.NodeID) bool
func (*EndpointHashMap) IsEmpty ¶ added in v0.3.10
func (m *EndpointHashMap) IsEmpty() bool
func (*EndpointHashMap) Keys ¶ added in v0.3.10
func (m *EndpointHashMap) Keys() []fatchoy.NodeID
func (*EndpointHashMap) Pop ¶ added in v0.3.10
func (m *EndpointHashMap) Pop(node fatchoy.NodeID) fatchoy.Endpoint
Pop removes an element from the map and returns it
func (*EndpointHashMap) Put ¶ added in v0.3.10
func (m *EndpointHashMap) Put(node fatchoy.NodeID, endpoint fatchoy.Endpoint)
func (*EndpointHashMap) PutIfAbsent ¶ added in v0.3.10
func (m *EndpointHashMap) PutIfAbsent(node fatchoy.NodeID, endpoint fatchoy.Endpoint)
func (*EndpointHashMap) Remove ¶ added in v0.3.10
func (m *EndpointHashMap) Remove(node fatchoy.NodeID)
func (*EndpointHashMap) Size ¶ added in v0.3.10
func (m *EndpointHashMap) Size() int
func (*EndpointHashMap) Values ¶ added in v0.3.10
func (m *EndpointHashMap) Values() []fatchoy.Endpoint
type EndpointMapShard ¶ added in v0.3.10
func (*EndpointMapShard) Clear ¶ added in v0.3.10
func (s *EndpointMapShard) Clear()
type FakeConn ¶
type FakeConn struct {
StreamConn
}
a fake endpoint
func (*FakeConn) ForceClose ¶
func (*FakeConn) Go ¶
func (c *FakeConn) Go(flag fatchoy.EndpointFlag)
type FakeEndpoint ¶ added in v0.3.10
type FakeEndpoint struct {
// contains filtered or unexported fields
}
func (*FakeEndpoint) ErrorChan ¶ added in v0.3.10
func (e *FakeEndpoint) ErrorChan() <-chan error
func (*FakeEndpoint) ForceClose ¶ added in v0.3.10
func (e *FakeEndpoint) ForceClose(error)
func (*FakeEndpoint) Go ¶ added in v0.3.10
func (e *FakeEndpoint) Go(fatchoy.EndpointFlag)
开启read/write线程
func (*FakeEndpoint) IsRunning ¶ added in v0.3.10
func (e *FakeEndpoint) IsRunning() bool
func (*FakeEndpoint) Node ¶ added in v0.6.2
func (e *FakeEndpoint) Node() fatchoy.NodeID
func (*FakeEndpoint) OutMsgChan ¶ added in v0.4.1
func (e *FakeEndpoint) OutMsgChan() chan<- *fatchoy.Packet
func (*FakeEndpoint) RawConn ¶ added in v0.3.10
func (e *FakeEndpoint) RawConn() net.Conn
func (*FakeEndpoint) RemoteAddr ¶ added in v0.3.10
func (e *FakeEndpoint) RemoteAddr() string
func (*FakeEndpoint) Send ¶ added in v0.4.1
func (e *FakeEndpoint) Send(pkt *fatchoy.Packet) error
发送消息
func (*FakeEndpoint) SetEncryptPair ¶ added in v0.3.10
func (e *FakeEndpoint) SetEncryptPair(cipher.BlockCryptor, cipher.BlockCryptor)
设置加解密
func (*FakeEndpoint) SetNode ¶ added in v0.6.2
func (e *FakeEndpoint) SetNode(v fatchoy.NodeID)
func (*FakeEndpoint) SetUserData ¶ added in v0.3.10
func (e *FakeEndpoint) SetUserData(v interface{})
绑定自定义数据
func (*FakeEndpoint) UserData ¶ added in v0.3.10
func (e *FakeEndpoint) UserData() interface{}
type StreamConn ¶
type StreamConn struct {
// contains filtered or unexported fields
}
stream connection
func (*StreamConn) ErrorChan ¶ added in v0.3.5
func (c *StreamConn) ErrorChan() <-chan error
func (*StreamConn) IsRunning ¶ added in v0.1.20
func (c *StreamConn) IsRunning() bool
func (*StreamConn) Node ¶ added in v0.6.2
func (c *StreamConn) Node() fatchoy.NodeID
func (*StreamConn) OutMsgChan ¶ added in v0.4.1
func (c *StreamConn) OutMsgChan() chan<- *fatchoy.Packet
func (*StreamConn) RemoteAddr ¶
func (c *StreamConn) RemoteAddr() string
func (*StreamConn) SetEncryptPair ¶
func (c *StreamConn) SetEncryptPair(encrypt cipher.BlockCryptor, decrypt cipher.BlockCryptor)
func (*StreamConn) SetNode ¶ added in v0.6.2
func (c *StreamConn) SetNode(node fatchoy.NodeID)
func (*StreamConn) SetRemoteAddr ¶
func (c *StreamConn) SetRemoteAddr(addr string)
func (*StreamConn) SetUserData ¶
func (c *StreamConn) SetUserData(ud interface{})
func (*StreamConn) Stats ¶
func (c *StreamConn) Stats() *stats.Stats
func (*StreamConn) UserData ¶
func (c *StreamConn) UserData() interface{}
type TcpConn ¶
type TcpConn struct { StreamConn // contains filtered or unexported fields }
TCP connection
func NewTcpConn ¶
func (*TcpConn) ForceClose ¶
func (*TcpConn) Go ¶
func (t *TcpConn) Go(flag fatchoy.EndpointFlag)
type TcpServer ¶
type TcpServer struct {
// contains filtered or unexported fields
}
func NewTcpServer ¶
func (*TcpServer) BacklogChan ¶
Click to show internal directories.
Click to hide internal directories.