Documentation ¶
Index ¶
- func InitTCP(server *TcpServer, numCPU int, connType channel.ConnType) (listener *net.TCPListener, err error)
- func ProtoReady(logHead string, ch *channel.Channel) (err error)
- type Bucket
- func (b *Bucket) BroadcastRoom(req *pb.SendToRoomReq)
- func (b *Bucket) ChangeRoom(newRoomId string, ch *channel.Channel) (err error)
- func (b *Bucket) ChannelCount() int
- func (b *Bucket) DelChannel(currCh *channel.Channel)
- func (b *Bucket) DelRoomById(room *channel.Room)
- func (b *Bucket) GetChannel(key string) (ch *channel.Channel)
- func (b *Bucket) GetRoomById(roomId string) (room *channel.Room)
- func (b *Bucket) GetRoomsOnline() map[string]struct{}
- func (b *Bucket) IPCount() (res map[string]struct{})
- func (b *Bucket) ProcessProtoToRoom(index int)
- func (b *Bucket) Put(ch *channel.Channel) (err error)
- func (b *Bucket) RoomCount() int
- func (b *Bucket) RoomsCount() (res map[string]int32)
- func (b *Bucket) UpdateRoomOnline(roomCountMap map[string]int32)
- type Round
- type RoundOptions
- type TcpServer
- func (s *TcpServer) AllocBucket(key string) *Bucket
- func (s *TcpServer) BroadcastToAllBucket(proto *protocol.Proto, speed int)
- func (s *TcpServer) Buckets() []*Bucket
- func (s *TcpServer) Close() (err error)
- func (s *TcpServer) Connect(ctx context.Context, params *channel.AuthParams) (hbCfg *pb.HbCfg, err error)
- func (s *TcpServer) Disconnect(ctx context.Context, ch *channel.Channel) (err error)
- func (s *TcpServer) Heartbeat(ctx context.Context, userInfo *channel.UserInfo) (err error)
- func (s *TcpServer) OpFromClient(ctx context.Context, logHead string, proto *protocol.Proto, ...) (err error)
- func (s *TcpServer) RandHeartbeatTime() time.Duration
- func (s *TcpServer) Receive(ctx context.Context, ch *channel.Channel, p *protocol.Proto) (err error)
- func (s *TcpServer) ResetTimerHeartbeat(ctx context.Context, logHead string, ch *channel.Channel)
- func (s *TcpServer) SetTimerHandshake(logHead string, ch *channel.Channel)
- func (s *TcpServer) SetTimerHeartbeat(ctx context.Context, logHead string, ch *channel.Channel, hbCfg *pb.HbCfg, ...)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Bucket ¶
type Bucket struct {
// contains filtered or unexported fields
}
Bucket global value, use bucket to manage all the channel(all TCP connection)
func (*Bucket) BroadcastRoom ¶
func (b *Bucket) BroadcastRoom(req *pb.SendToRoomReq)
BroadcastRoom 房间广播:发送一个Proto到某个房间ID(即:SendToAllChan => Proto => ROOM)
func (*Bucket) ChangeRoom ¶
ChangeRoom change ro room
func (*Bucket) ChannelCount ¶
func (*Bucket) DelChannel ¶
DelChannel 删除一个用户的Channel
func (*Bucket) DelRoomById ¶
DelRoomById 通过房间ID,删除房间
func (*Bucket) GetRoomById ¶
GetRoomById 通过房间ID,获取房间
func (*Bucket) GetRoomsOnline ¶
GetRoomsOnline 获取所有在线人数大于0的房间
func (*Bucket) ProcessProtoToRoom ¶
ProcessProtoToRoom 处理发送都某个房间ID的消息 (Pop => ROOM => Proto => DEAL)
func (*Bucket) RoomsCount ¶
RoomsCount get all room id where online number > 0.
func (*Bucket) UpdateRoomOnline ¶
UpdateRoomOnline 更新每个房间的所有在线人数
type Round ¶
type Round struct { Timers []time.Timer BufferHash bytes.Hash // contains filtered or unexported fields }
Round used for connection round-robin get a reader/writer/timer for split big lock.
type RoundOptions ¶
RoundOptions round options.
type TcpServer ¶
type TcpServer struct {
// contains filtered or unexported fields
}
TcpServer 服务器(主体入口)
func NewTcpServer ¶
func NewTcpServer(conf *conf.Config) (*TcpServer, *registry.KratosServiceInstance)
NewTcpServer returns a new TcpServer.
func (*TcpServer) AllocBucket ¶
func (*TcpServer) BroadcastToAllBucket ¶
BroadcastToAllBucket 消息广播:广播到所有Bucket的所有Channel
func (*TcpServer) Disconnect ¶
func (*TcpServer) OpFromClient ¶
func (s *TcpServer) OpFromClient(ctx context.Context, logHead string, proto *protocol.Proto, ch *channel.Channel, bucket *Bucket) (err error)
OpFromClient 专门处理客户端上行的TCP消息
func (*TcpServer) RandHeartbeatTime ¶
RandHeartbeatTime 生成一个随机的心跳时间
func (*TcpServer) Receive ¶
func (s *TcpServer) Receive(ctx context.Context, ch *channel.Channel, p *protocol.Proto) (err error)
Receive receive a message.
func (*TcpServer) ResetTimerHeartbeat ¶
ResetTimerHeartbeat reset timer: for heartbeat
func (*TcpServer) SetTimerHandshake ¶
SetTimerHandshake set timer: for handshake