server

package
v0.0.0-...-ebe70a3 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2020 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrorSendEmptyPacket error while sending empty packet
	ErrorSendEmptyPacket = errors.New("sending invalid packet (nil)")
	// ErrorQueueFull error while tx queue is full
	ErrorQueueFull = errors.New("sending queue is full")
)

Functions

func SetConfig

func SetConfig(cfg *Config)

SetConfig setup server configuration

func StartWS

func StartWS()

StartWS start accepting websocket connections

func UseLogger

func UseLogger(l *zap.Logger)

UseLogger set logger for this sub-system

func WaitSocketShutdown

func WaitSocketShutdown()

WaitSocketShutdown wait for all client connection to close

Types

type Config

type Config struct {
	// HTTPort number for HTTP to listen on
	HTTPPort int
	// SocketReadDeadLine duration
	SocketReadDeadLine time.Duration
	// SocketReadBufferSize in bytes
	SocketReadBufferSize int
	// SocketWriteBufferSize in bytes
	SocketWriteBufferSize int
	// SocketSessionCacheSize size of outgoing packet queue
	SocketSessionCacheSize int
	// SocketTxQueueLength size of incoming packet queue
	SocketTxQueueLength int
	// SocketRPMLimit request per minute limit
	SocketRPMLimit int
	// SocketGracefulTimeout seconds to wait for a connection close
	SocketGracefulTimeout time.Duration
	// AuthTimeout timeout duration before authentication
	AuthTimeout time.Duration
	// WSAllowOrigin allow origin
	WSAllowOrigin bool
	// WSWriteDeadLine websocket write timeout
	WSWriteDeadLine time.Duration
}

Config server options

type ConnWriteFunc

type ConnWriteFunc func([]byte) (int, error)

ConnWriteFunc writes data to connection, for standard socket and web socket

type Sender

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

Sender send packets to the client

func NewSender

func NewSender(ctrl chan struct{}, queueSize, sendCacheSize int, writer ConnWriteFunc) *Sender

NewSender create and returns a sender instance

func (*Sender) EnqueueOutgoing

func (buf *Sender) EnqueueOutgoing(pkg []byte) error

EnqueueOutgoing push data to the sender's pending channel

func (*Sender) SendLoop

func (buf *Sender) SendLoop()

SendLoop packets sending routine

Jump to

Keyboard shortcuts

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