comet

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2022 License: MIT Imports: 34 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InitTCP

func InitTCP(server *Comet, addrs []string, accept int) (err error)

InitTCP listen all tcp.bind and start accept connections.

func InitWebsocket

func InitWebsocket(server *Comet, addrs []string, accept int) (err error)

InitWebsocket listen all tcp.bind and start accept connections.

Types

type Bucket

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

Bucket is a channel holder.

func NewBucket

func NewBucket(c *conf.Bucket) (b *Bucket)

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

func (*Bucket) Broadcast

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

Broadcast push msgs to all channels in the bucket.

func (*Bucket) BroadcastGroup

func (b *Bucket) BroadcastGroup(arg *grpc.BroadcastGroupReq)

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) 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 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) GetNode

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

func (Channel) Groups

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

Close close the channel.

func (*Channel) Push

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

Push server push message.

func (*Channel) Ready

func (c *Channel) Ready() *grpc.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 Comet

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

Comet is comet server.

func New

func New(c *conf.Config) *Comet

NewServer returns a new Server.

func (*Comet) Bucket

func (s *Comet) Bucket(subKey string) *Bucket

Bucket get the bucket by subkey.

func (*Comet) Buckets

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

Buckets return all buckets.

func (*Comet) Close

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

Close close the server.

func (*Comet) Connect

func (s *Comet) Connect(c context.Context, p *comet.Proto) (key string, hb time.Duration, errMsg string, err error)

Connect connected a connection.

func (*Comet) Disconnect

func (s *Comet) Disconnect(c context.Context, key string) (err error)

Disconnect disconnected a connection.

func (*Comet) Heartbeat

func (s *Comet) Heartbeat(ctx context.Context, key string) (err error)

Heartbeat heartbeat a connection session.

func (*Comet) Operate

func (s *Comet) Operate(ctx context.Context, p *grpc.Proto, ch *Channel, tsk *dtask.Task) error

Operate operate.

func (*Comet) RandServerHearbeat

func (s *Comet) RandServerHearbeat() time.Duration

RandServerHearbeat rand server heartbeat.

func (*Comet) Receive

func (s *Comet) Receive(ctx context.Context, key string, p *comet.Proto) (err error)

Receive receive a message.

func (*Comet) ServeTCP

func (s *Comet) ServeTCP(conn *net.TCPConn, rp, wp *bytes.Pool, tr *xtime.Timer)

ServeTCP serve a tcp connection.

func (*Comet) ServeWebsocket

func (s *Comet) ServeWebsocket(conn net.Conn, rp, wp *bytes.Pool, tr *xtime.Timer)

ServeWebsocket serve a websocket connection.

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 *grpc.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 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 *grpc.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 *grpc.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 userd for connection round-robin get a reader/writer/timer for split big lock.

func NewRound

func NewRound(c *conf.Config) (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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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