comet

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bucket

type Bucket struct {
	// contains filtered or unexported fields
}

Bucket is a channel holder.

func NewBucket

func NewBucket(cfg *BucketConfig) (b *Bucket)

NewBucket new a bucket struct. store the key with im channel.

func (*Bucket) Broadcast

func (b *Bucket) Broadcast(p *protocol.Proto, op int32)

Broadcast push msgs to all channels in the bucket.

func (*Bucket) BroadcastGroup

func (b *Bucket) BroadcastGroup(gid string, p *protocol.Proto)

BroadcastGroup broadcast a message to specified group

func (*Bucket) Channel

func (b *Bucket) Channel(key string) (ch *Channel)

Channel get a channel by sub key.

func (*Bucket) ChannelCount

func (b *Bucket) ChannelCount() int

ChannelCount channel count in the bucket

func (*Bucket) ChannelsCount

func (b *Bucket) ChannelsCount() (res []string)

func (*Bucket) Del

func (b *Bucket) Del(dch *Channel)

Del delete the channel by sub key.

func (*Bucket) DelGroup

func (b *Bucket) DelGroup(group *Group)

DelGroup delete a room by group id.

func (*Bucket) Group

func (b *Bucket) Group(gid string) (group *Group)

Group get a group by group id.

func (*Bucket) GroupCount

func (b *Bucket) GroupCount() int

group GroupCount room count in the bucket

func (*Bucket) GroupsCount

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

GroupsCount get all group id where online number > 0.

func (*Bucket) Put

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

Put put a channel according with sub key.

func (*Bucket) PutGroup

func (b *Bucket) PutGroup(gid string) (group *Group, err error)

Put put a group according with sub key.

type BucketConfig

type BucketConfig struct {
	Size          int    `json:",default=32"`
	Channel       int    `json:",default=1024"`
	Groups        int    `json:",default=1024"`
	RoutineAmount uint64 `json:",default=32"`
	RoutineSize   int    `json:",default=1024"`
}

BucketConfig is bucket config.

type Channel

type Channel struct {
	CliProto Ring

	Writer bufio.Writer
	Reader bufio.Reader

	Seq  int32
	Key  string
	IP   string
	Port string
	// contains filtered or unexported fields
}

Channel used by message pusher send msg to write goroutine.

func NewChannel

func NewChannel(cli, svr int) *Channel

NewChannel new a channel.

func (*Channel) Close

func (c *Channel) Close()

Close close the channel.

func (*Channel) DelNode

func (c *Channel) DelNode(id string)

func (*Channel) GetGroups

func (c *Channel) GetGroups() []string

func (*Channel) GetIP

func (c *Channel) GetIP() string

func (*Channel) GetKey

func (c *Channel) GetKey() string

func (*Channel) GetNode

func (c *Channel) GetNode(id string) *Node

func (*Channel) GetPort

func (c *Channel) GetPort() string

func (*Channel) GetSeq

func (c *Channel) GetSeq() int32

base info just for debug

func (Channel) Groups

func (c Channel) Groups() map[string]*Node

Close close the channel.

func (*Channel) Push

func (c *Channel) Push(p *protocol.Proto) (seq int32, err error)

Push server push message.

func (*Channel) Ready

func (c *Channel) Ready() *protocol.Proto

Ready check the channel ready or close?

func (*Channel) SetNode

func (c *Channel) SetNode(id string, node *Node)

func (*Channel) Signal

func (c *Channel) Signal()

Signal send signal to the channel, protocol ready.

type Group

type Group struct {
	ID string

	Online    int32 // dirty read is ok
	AllOnline int32
	// contains filtered or unexported fields
}

Group is a group and store channel group info.

func NewGroup

func NewGroup(id string) (r *Group)

NewGroup new a group struct, store channel group info.

func (*Group) Close

func (r *Group) Close()

Close close the group.

func (*Group) Del

func (r *Group) Del(ch *Channel) bool

Del delete channel from the group.

func (*Group) Members

func (r *Group) Members() ([]string, []string)

group members Key,IP

func (*Group) OnlineNum

func (r *Group) OnlineNum() int32

OnlineNum the group all online.

func (*Group) Push

func (r *Group) Push(p *protocol.Proto)

Push push msg to the group, if chan full discard it.

func (*Group) Put

func (r *Group) Put(ch *Channel) (err error)

Put put channel into the group.

type GroupCastReq

type GroupCastReq struct {
	// contains filtered or unexported fields
}

type Node

type Node struct {
	Current *Channel
	Next    *Node
	Prev    *Node
}

type Ring

type Ring struct {
	// contains filtered or unexported fields
}

Ring ring proto buffer.

func NewRing

func NewRing(num int) *Ring

NewRing new a ring buffer.

func (*Ring) Get

func (r *Ring) Get() (proto *protocol.Proto, err error)

Get get a proto from ring.

func (*Ring) GetAdv

func (r *Ring) GetAdv()

GetAdv incr read index.

func (*Ring) Init

func (r *Ring) Init(num int)

Init init ring.

func (*Ring) Reset

func (r *Ring) Reset()

Reset reset ring.

func (*Ring) Set

func (r *Ring) Set() (proto *protocol.Proto, err error)

Set get a proto to write.

func (*Ring) SetAdv

func (r *Ring) SetAdv()

SetAdv incr write index.

type Round

type Round struct {
	// contains filtered or unexported fields
}

Round used for connection round-robin get a reader/writer/timer for split big lock.

func NewRound

func NewRound(opts RoundOptions) (r *Round)

NewRound new a round struct.

func (*Round) Reader

func (r *Round) Reader(rn int) *bytes.Pool

Reader get a reader memory buffer.

func (*Round) Timer

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

Timer get a timer.

func (*Round) Writer

func (r *Round) Writer(rn int) *bytes.Pool

Writer get a writer memory buffer pool.

type RoundOptions

type RoundOptions struct {
	Timer        int
	TimerSize    int
	Reader       int
	ReadBuf      int
	ReadBufSize  int
	Writer       int
	WriteBuf     int
	WriteBufSize int
	Task         int
	TaskSize     int
}

RoundOptions round options.

Jump to

Keyboard shortcuts

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