server

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2021 License: Apache-2.0 Imports: 6 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BytesToInt16

func BytesToInt16(buf []byte) int16

func BytesToInt32

func BytesToInt32(buf []byte) int32

func BytesToInt64

func BytesToInt64(buf []byte) int64

func BytesToInt8

func BytesToInt8(buf []byte) int8

func BytesToUInt16

func BytesToUInt16(buf []byte) uint16

func BytesToUInt32

func BytesToUInt32(buf []byte) uint32

func BytesToUInt64

func BytesToUInt64(buf []byte) uint64

func BytesToUInt8

func BytesToUInt8(buf []byte) uint8

Types

type Config

type Config struct {
	OpenCheck      bool
	BodyLenOffset  int32
	PackageLenType LenType
	PackageMax     int32
	HeaderLen      int32
}

func NewConfig

func NewConfig(openCheck bool, bodyLenOffset int32, headerLen int32, packageLenType LenType) *Config

type Connection

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

func NewConnection

func NewConnection(fd int64, conn net.Conn, c *Config) *Connection

func (*Connection) Close

func (c *Connection) Close() error

func (*Connection) ConnectTime

func (c *Connection) ConnectTime() int64

func (*Connection) Fd

func (c *Connection) Fd() int64

func (*Connection) Ip

func (c *Connection) Ip() string

func (*Connection) IsClosed

func (c *Connection) IsClosed() bool

func (*Connection) ParseHeader

func (c *Connection) ParseHeader()

func (*Connection) Read

func (c *Connection) Read() ([]byte, *Header, error)

func (*Connection) Write

func (c *Connection) Write(buf []byte) (int, error)

type Event

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

func NewEvent

func NewEvent(header *Header, body []byte, fd int64) *Event

func (*Event) Body

func (e *Event) Body() []byte

func (*Event) Fd

func (e *Event) Fd() int64

func (*Event) Header

func (e *Event) Header() *Header

type EventInterface

type EventInterface interface {
	Close(s *Server, fd int64)
	Connect(s *Server, fd int64)
	Receive(s *Server, e *Event)
}
type Header struct {
	PackageLen int32
	BodyLen    int32
	HBuf       []byte
}

func NewHeader

func NewHeader() *Header

func (*Header) Parse

func (h *Header) Parse(buf []byte, c *Config)

type LenType

type LenType int32
const (
	U_INT_8  LenType = 1
	INT_8    LenType = 1
	U_INT_16 LenType = 2
	INT_16   LenType = 2
	U_INT_32 LenType = 4
	INT_32   LenType = 4
	U_INT_64 LenType = 8
	INT_64   LenType = 8
)

type Server

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

func NewServer

func NewServer(host string, port int32, network SocketType) *Server

func (*Server) Close

func (s *Server) Close(fd int64)

func (*Server) Connection added in v0.0.2

func (s *Server) Connection(fd int64) *Connection

func (*Server) Connections added in v0.0.2

func (s *Server) Connections() map[int64]*Connection

func (*Server) Send

func (s *Server) Send(buf []byte, fd int64) (int, error)

func (*Server) Set

func (s *Server) Set(c *Config)

func (*Server) SetEvent

func (s *Server) SetEvent(event EventInterface)

func (*Server) Start

func (s *Server) Start()

type SocketType

type SocketType string
const (
	SOCKET_TCP SocketType = "tcp"
	SOCKET_UDP SocketType = "udp"
)

Jump to

Keyboard shortcuts

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