server

package
v0.0.0-...-fc6b28f Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2017 License: GPL-3.0 Imports: 18 Imported by: 0

Documentation

Overview

*

  • @file pool.go
  • @brief pool of goroutined *
  • Contains Task and Pool types and methods to work with Pool

*

  • @file telnet.go
  • @brief Telnet protocol *
  • Contains specific for this protocol methods

*

  • @file user.go
  • @brief Users and Sessions *
  • Contains User and Session types,
  • Methods to login new user

Index

Constants

View Source
const (
	ConnKey key = 0 + iota
	ServerKey
	ChanKey
)
View Source
const (
	BC_ALL   = 1 << iota ///< All users in this session accept message
	BC_SELF              ///< Only sender accept message
	BC_OTHER             ///< All users in this session without sender accept message
)

* @brief enum BroadcastFlags * * Specified, who will have broadcastins message

Variables

This section is empty.

Functions

func SyncFuncWithTimeout

func SyncFuncWithTimeout(f Func, ctx context.Context, timeout time.Duration) error

Types

type Func

type Func func(context.Context) error ///< Goroutine

/ Task intreface (see @class Type)

type Pool

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

*

  • @class Pool
  • @brief Pool of goroutines *
  • It contains concurrency goroutines and send new task into tasksChan,
  • when task is done, goroutine send result into resultsChan

func NewPool

func NewPool(concurrency int) Pool

*

  • @brief Create new Pool object
  • @param[in] concurrency Number of goroutines in pool
  • @return Pointer to created Pool

func (*Pool) Add

func (p *Pool) Add(work Func, ctx context.Context)

*

  • @brief Add new task into Pool
  • @param[in] args Arguments to call goroutine
  • @return t Added task

func (*Pool) Run

func (p *Pool) Run()

*

  • @brief Start this Pool *
  • Runs all workers

func (*Pool) Size

func (p *Pool) Size() int

*

  • @brief Return size of Pool
  • @return Size of Pool

func (*Pool) Stop

func (p *Pool) Stop()

*

  • @brief Waight while all workers stop
  • @return errs Array of error *
  • It close tasksChan and wait while all goroutines finished

type Server

type Server struct {
	Timeout           time.Duration  ///< Timeout in seconds of waiting user play (default 30)
	TimeoutForLogin   time.Duration  ///< Timeout in seconds of waiting user login (default 300)
	Deadline          time.Duration  ///< Deadline for connection (in milliseconds) (default 1000)
	Pool              Pool           ///< Pool of goroutines
	MaxUsernameLength int            ///< Maximum length of user name
	Sessions          []Session      ///< Array of active sessions
	Users             map[string]int ///< Map of logins in each sessionID
	Signals           chan os.Signal ///< Channel of system signals like SIGINT and SIGKILL
	WaitTime          time.Duration
	SystemLogin       string
	// contains filtered or unexported fields
}

*

  • @class Server
  • @brief Telnet game server core *
  • Main class, provides telnet-server,
  • which contributes sessions, users, games, scores and other

func New

func New(cfg conf.ServerConf) Server

*

  • @brief Constructor of class Server
  • @param[in] cfg Server configuration
  • @return server Pointer to new Server object *
  • Make light and eazy fast initialisation of server directly

func (*Server) PostRun

func (s *Server) PostRun()

*

  • @brief Shutdown the Server *
  • Unlock, free all allocated memory and handlers, save data

func (*Server) PreRun

func (s *Server) PreRun(cfg conf.ServerConf) error

func (*Server) Run

func (s *Server) Run() error

*

  • @brief Start Server with given parameters
  • @return err Error if critical error occured

type Session

type Session struct {
	Users []User     ///< Array of users in this session
	Game  *game.Game ///< Game object
}

*

  • @class Session
  • @brief Class, provides information about Session *
  • Session is a thing which aggregate users in one game

type Task

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

*

  • @class Task
  • @brief Asyncronic task which works in goroutine *
  • It must have Work method which start in goroutine
  • with arguments args and store it's result into result field

type User

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

*

  • @class User
  • @brief Class, provides information about User

Jump to

Keyboard shortcuts

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