comet

package
v0.0.0-...-50b78f6 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2024 License: MIT Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InitTCP

func InitTCP(server *TcpServer, numCPU int, connType channel.ConnType) (listener *net.TCPListener, err error)

func ProtoReady

func ProtoReady(logHead string, ch *channel.Channel) (err error)

ProtoReady 处理TCP客户端的消息 使用for循环处理:如果客户端发送频率非常高,可以通过for循环把连续的proto读取出来了

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 NewBucket

func NewBucket(conf *conf.Bucket) *Bucket

func (*Bucket) BroadcastRoom

func (b *Bucket) BroadcastRoom(req *pb.SendToRoomReq)

BroadcastRoom 房间广播:发送一个Proto到某个房间ID(即:SendToAllChan => Proto => ROOM)

func (*Bucket) ChangeRoom

func (b *Bucket) ChangeRoom(newRoomId string, ch *channel.Channel) (err error)

ChangeRoom change ro room

func (*Bucket) ChannelCount

func (b *Bucket) ChannelCount() int

func (*Bucket) DelChannel

func (b *Bucket) DelChannel(currCh *channel.Channel)

DelChannel 删除一个用户的Channel

func (*Bucket) DelRoomById

func (b *Bucket) DelRoomById(room *channel.Room)

DelRoomById 通过房间ID,删除房间

func (*Bucket) GetChannel

func (b *Bucket) GetChannel(key string) (ch *channel.Channel)

func (*Bucket) GetRoomById

func (b *Bucket) GetRoomById(roomId string) (room *channel.Room)

GetRoomById 通过房间ID,获取房间

func (*Bucket) GetRoomsOnline

func (b *Bucket) GetRoomsOnline() map[string]struct{}

GetRoomsOnline 获取所有在线人数大于0的房间

func (*Bucket) IPCount

func (b *Bucket) IPCount() (res map[string]struct{})

func (*Bucket) ProcessProtoToRoom

func (b *Bucket) ProcessProtoToRoom(index int)

ProcessProtoToRoom 处理发送都某个房间ID的消息 (Pop => ROOM => Proto => DEAL)

func (*Bucket) Put

func (b *Bucket) Put(ch *channel.Channel) (err error)

func (*Bucket) RoomCount

func (b *Bucket) RoomCount() int

func (*Bucket) RoomsCount

func (b *Bucket) RoomsCount() (res map[string]int32)

RoomsCount get all room id where online number > 0.

func (*Bucket) UpdateRoomOnline

func (b *Bucket) UpdateRoomOnline(roomCountMap map[string]int32)

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.

func NewRound

func NewRound(c *conf.Config) (round *Round)

NewRound new a round struct.

func (*Round) TimerPool

func (r *Round) TimerPool(rn int) *time.Timer

TimerPool get a timer.

type RoundOptions

type RoundOptions struct {
	TimerPool *conf.TimerPool
}

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 (s *TcpServer) AllocBucket(key string) *Bucket

func (*TcpServer) BroadcastToAllBucket

func (s *TcpServer) BroadcastToAllBucket(proto *protocol.Proto, speed int)

BroadcastToAllBucket 消息广播:广播到所有Bucket的所有Channel

func (*TcpServer) Buckets

func (s *TcpServer) Buckets() []*Bucket

Buckets return all buckets.

func (*TcpServer) Close

func (s *TcpServer) Close() (err error)

func (*TcpServer) Connect

func (s *TcpServer) Connect(ctx context.Context, params *channel.AuthParams) (hbCfg *pb.HbCfg, err error)

func (*TcpServer) Disconnect

func (s *TcpServer) Disconnect(ctx context.Context, ch *channel.Channel) (err error)

func (*TcpServer) Heartbeat

func (s *TcpServer) Heartbeat(ctx context.Context, userInfo *channel.UserInfo) (err error)

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

func (s *TcpServer) RandHeartbeatTime() time.Duration

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

func (s *TcpServer) ResetTimerHeartbeat(ctx context.Context, logHead string, ch *channel.Channel)

ResetTimerHeartbeat reset timer: for heartbeat

func (*TcpServer) SetTimerHandshake

func (s *TcpServer) SetTimerHandshake(logHead string, ch *channel.Channel)

SetTimerHandshake set timer: for handshake

func (*TcpServer) SetTimerHeartbeat

func (s *TcpServer) SetTimerHeartbeat(ctx context.Context, logHead string, ch *channel.Channel, hbCfg *pb.HbCfg, bucket *Bucket)

SetTimerHeartbeat set timer: for heartbeat

Directories

Path Synopsis
api

Jump to

Keyboard shortcuts

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