fetcp

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2019 License: MIT Imports: 7 Imported by: 0

README

fetcp

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrConnClosing   = errors.New("use of closed network connection")
	ErrWriteBlocking = errors.New("write packet was blocking")
	ErrReadBlocking  = errors.New("read packet was blocking")
)

Error type

Functions

func ReloadConfig

func ReloadConfig()

Types

type Conn

type Conn struct {
	HeatBeatStatus     bool  // heatbeat status
	LastTimeOfHeatBeat int64 // last heatbeat time
	// contains filtered or unexported fields
}

Conn exposes a set of callbacks for the various events that occur on a connection

func (*Conn) AsyncWritePacket

func (c *Conn) AsyncWritePacket(p Packet, timeout time.Duration) (err error)

AsyncWritePacket async writes a packet, this method will never block

func (*Conn) Close

func (c *Conn) Close()

Close closes the connection

func (*Conn) Do

func (c *Conn) Do()

Do it

func (*Conn) GetExtraData

func (c *Conn) GetExtraData() interface{}

GetExtraData gets the extra data from the Conn

func (*Conn) GetRawConn

func (c *Conn) GetRawConn() *net.TCPConn

GetRawConn returns the raw net.TCPConn from the Conn

func (*Conn) HeartBeatTimeOutCheck

func (c *Conn) HeartBeatTimeOutCheck(lastTimeOfHeatBeat int64)

func (*Conn) IsClosed

func (c *Conn) IsClosed() bool

IsClosed indicates whether or not the connection is closed

func (*Conn) PutExtraData

func (c *Conn) PutExtraData(data interface{})

PutExtraData puts the extra data with the Conn

func (*Conn) StartHeartBeatTimeOutCheck

func (c *Conn) StartHeartBeatTimeOutCheck()

type ConnCallback

type ConnCallback interface {
	// OnConnect is called when the connection was accepted,
	// If the return value of false is closed
	OnConnect(*Conn) bool

	// OnMessage is called when the connection receives a packet,
	// If the return value of false is closed
	OnMessage(*Conn, Packet) bool

	// OnClose is called when the connection closed
	OnClose(*Conn)
}

ConnCallback is an interface of methods that are used as callbacks on a connection

type Packet

type Packet interface {
	Serialize() []byte
}

type Protocol

type Protocol interface {
	ReadPacket(c *Conn) (Packet, error)
}

type Server

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

func NewServer

func NewServer(callback ConnCallback, protocol Protocol) *Server

func (*Server) Server

func (s *Server) Server()

func (*Server) Start

func (s *Server) Start(listener *net.TCPListener, acceptTimeout time.Duration)

Start starts service

func (*Server) Stop

func (s *Server) Stop()

Stop stops service

type SrvConfig

type SrvConfig struct {
	ServerName             string
	Port                   int
	PacketSendChanLimit    int
	PacketReceiveChanLimit int
	ConnectTimeOut         int64
	HeatbeatCheck          bool
	HeatbeatCheckSpec      int
}
var (
	ServerConfig *SrvConfig
)

Jump to

Keyboard shortcuts

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