comet

package
v0.0.0-...-414654c Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2021 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 *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.

func InitWhitelist

func InitWhitelist(c *conf.Whitelist) (err error)

InitWhitelist a whitelist struct.

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 *protocol.Proto, op int32)

Broadcast push msgs to all channels in the bucket.

func (*Bucket) BroadcastRoom

func (b *Bucket) BroadcastRoom(arg *pb.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
	// 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) bool

NeedPush verify if in watch.

func (*Channel) Push

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

Push server push message.

func (*Channel) Ready

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

type Room struct {
	ID string

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

Room is a room and store channel room info.

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 *protocol.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 used 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 round options.

type Server

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

Server is comet 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(c context.Context, p *protocol.Proto, cookie string) (mid int64, key, rid string, accepts []int32, heartbeat time.Duration, err error)

Connect connected a connection.

func (*Server) Disconnect

func (s *Server) Disconnect(c context.Context, mid int64, key string) (err error)

Disconnect disconnected a connection.

func (*Server) Heartbeat

func (s *Server) Heartbeat(ctx context.Context, mid int64, key string) (err error)

Heartbeat heartbeat a connection session.

func (*Server) Operate

func (s *Server) Operate(ctx context.Context, p *protocol.Proto, ch *Channel, b *Bucket) error

Operate operate.

func (*Server) RandServerHearbeat

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

RandServerHearbeat rand server heartbeat.

func (*Server) Receive

func (s *Server) Receive(ctx context.Context, mid int64, p *protocol.Proto) (err error)

Receive receive a message.

func (*Server) RenewOnline

func (s *Server) RenewOnline(ctx context.Context, serverID string, roomCount map[string]int32) (allRoom map[string]int32, err error)

RenewOnline renew room online.

func (*Server) ServeTCP

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

ServeTCP serve a tcp connection.

func (*Server) ServeWebsocket

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

ServeWebsocket serve a websocket connection.

type Whitelist

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

Whitelist .

func (*Whitelist) Contains

func (w *Whitelist) Contains(mid int64) (ok bool)

Contains whitelist contains a mid or not.

func (*Whitelist) Printf

func (w *Whitelist) Printf(format string, v ...interface{})

Printf calls l.Output to print to the logger.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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