comet

package
v0.0.0-...-d9ad550 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2019 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InitTCP

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

InitTCP listen all tcp.bind and start accept connections.

func InitWebsocket

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

InitWebsocket listen all tcp.bind and start accept connections.

func InitWebsocketWithTLS

func InitWebsocketWithTLS(server *Server, addrs []string, certFile, privateFile string, accept int) (err error)

InitWebsocketWithTLS init websocket with tls.

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, platform string)

Broadcast push msgs to all channels in the bucket.

func (*Bucket) BroadcastRoom

func (b *Bucket) BroadcastRoom(arg *grpc.BroadcastRoomReq)

BroadcastRoom broadcast a message to specified room

func (*Bucket) ChangeRoom

func (b *Bucket) ChangeRoom(nrid string, ch *Channel) (err error)

ChangeRoom change ro room

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

func (b *Bucket) DelRoom(room *Room)

DelRoom delete a room by roomid.

func (*Bucket) IPCount

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

IPCount get ip count.

func (*Bucket) Put

func (b *Bucket) Put(rid string, ch *Channel) (err error)

Put put a channel according with sub key.

func (*Bucket) Room

func (b *Bucket) Room(rid string) (room *Room)

Room get a room by roomid.

func (*Bucket) RoomCount

func (b *Bucket) RoomCount() int

RoomCount room count in the bucket

func (*Bucket) Rooms

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

Rooms get all room id where online number > 0.

func (*Bucket) RoomsCount

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

RoomsCount get all room id where online number > 0.

func (*Bucket) UpRoomsCount

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

UpRoomsCount update all room count

type Channel

type Channel struct {
	Room     *Room
	CliProto Ring

	Writer bufio.Writer
	Reader bufio.Reader
	Next   *Channel
	Prev   *Channel

	Mid      int64
	Key      string
	IP       string
	Platform 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) NeedPush

func (c *Channel) NeedPush(op int32, platform string) bool

NeedPush verify if in watch.

func (*Channel) Push

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

Push server push message.

func (*Channel) Ready

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

Ready check the channel ready or close?

func (*Channel) Signal

func (c *Channel) Signal()

Signal send signal to the channel, protocol ready.

func (*Channel) UnWatch

func (c *Channel) UnWatch(accepts ...int32)

UnWatch unwatch an operation

func (*Channel) Watch

func (c *Channel) Watch(accepts ...int32)

Watch watch a operation.

type Ring

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

Ring .

func NewRing

func NewRing(num int) *Ring

NewRing .

func (*Ring) Get

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

Get .

func (*Ring) GetAdv

func (r *Ring) GetAdv()

GetAdv .

func (*Ring) Init

func (r *Ring) Init(num int)

Init .

func (*Ring) Reset

func (r *Ring) Reset()

Reset .

func (*Ring) Set

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

Set .

func (*Ring) SetAdv

func (r *Ring) SetAdv()

SetAdv .

type Room

type Room struct {
	ID string

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

Room is a room.

func NewRoom

func NewRoom(id string) (r *Room)

NewRoom new a room struct, store channel room info.

func (*Room) Close

func (r *Room) Close()

Close close the room.

func (*Room) Del

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

Del delete channel from the room.

func (*Room) OnlineNum

func (r *Room) OnlineNum() int32

OnlineNum the room all online.

func (*Room) Push

func (r *Room) Push(p *grpc.Proto)

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

func (*Room) Put

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

Put put channel into the room.

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
}

RoundOptions .

type Server

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

Server .

func NewServer

func NewServer(c *conf.Config) *Server

NewServer returns a new Server.

func (*Server) Bucket

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

Bucket get the bucket by subkey.

func (*Server) Buckets

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

Buckets return all buckets.

func (*Server) Close

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

Close close the server.

func (*Server) Connect

func (s *Server) Connect(p *model.Proto, cookie string) (mid int64, key, rid, platform string, accepts []int32, err error)

Connect .

func (*Server) Disconnect

func (s *Server) Disconnect(mid int64, key string) (err error)

Disconnect .

func (*Server) Heartbeat

func (s *Server) Heartbeat(mid int64, key string) (err error)

Heartbeat .

func (*Server) NextKey

func (s *Server) NextKey() string

NextKey generate a server key.

func (*Server) Operate

func (s *Server) Operate(p *model.Proto, ch *Channel, b *Bucket) (err error)

Operate .

func (*Server) RandServerHearbeat

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

RandServerHearbeat rand server heartbeat.

func (*Server) RenewOnline

func (s *Server) RenewOnline(serverID string, rommCount map[string]int32) (allRoom map[string]int32, err error)

RenewOnline .

func (*Server) Report

func (s *Server) Report(mid int64, room string, p *model.Proto) (rp *model.Proto, err error)

Report message to logic.

func (*Server) ServeTCP

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

ServeTCP .

func (*Server) ServeWebsocket

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

ServeWebsocket .

Directories

Path Synopsis
g

Jump to

Keyboard shortcuts

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