chopper

package module
v0.0.0-...-7c17ce0 Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2018 License: MIT Imports: 7 Imported by: 0

README

Chopper

chopper is used for rapid development of TCP application and some useful library in Go. It is inspired by retlang.

Features

this package is my first Golang program, just for fun and practice.

Usage

Install
go get github.com/jiansoft/chopper
Quick Start


License

Copyright (c) 2017

Released under the MIT license:

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewApplication

func NewApplication(config ApplicationConfig, serverEvent IServerEvent) *tcpApplication

Types

type ApplicationConfig

type ApplicationConfig struct {
	Host               string
	Port               int
	ConnectionPoolSize int
	BufferSize         int
}

type BufferManager

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

This struct creates a single large buffer which can be divided up and assigned to peer struct for use with each socket I/O operation. This enables bufffers to be easily reused and guards against fragmenting heap memory.

func NewBufferManager

func NewBufferManager(maxConnectCount int, bufferSize int) *BufferManager

func (*BufferManager) FreeBuffer

func (b *BufferManager) FreeBuffer(peer *PeerSession)

Removes the buffer from a peer struct. This frees the buffer back to the buffer pool

func (*BufferManager) SetBuffer

func (b *BufferManager) SetBuffer(peer *PeerSession)

Assigns a buffer from the buffer pool to the specified peer struct

type IClientEvent

type IClientEvent interface {
	OnDisconnect()
	OnRecvComplete([]byte)
}

type IServerEvent

type IServerEvent interface {
	CreateApplication()
	CreateSession(ISession) IClientEvent
}

type ISession

type ISession interface {
	Start()
	Disconnect()
	Send(buf []byte)
	RemoteAddr() net.Addr
}

type PeerSession

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

func (*PeerSession) Disconnect

func (c *PeerSession) Disconnect()

func (PeerSession) RemoteAddr

func (c PeerSession) RemoteAddr() net.Addr

func (*PeerSession) Send

func (c *PeerSession) Send(buf []byte)

func (*PeerSession) Start

func (c *PeerSession) Start()

type TcpBinaryHander

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

func NewTcpBinaryHander

func NewTcpBinaryHander(readDoneFunc func([]byte)) *TcpBinaryHander

func (*TcpBinaryHander) Dispose

func (t *TcpBinaryHander) Dispose()

func (*TcpBinaryHander) Parse

func (t *TcpBinaryHander) Parse(buffer []byte, count int)

Parse the received data

func (TcpBinaryHander) Wrap

func (TcpBinaryHander) Wrap(data []byte) []byte

Wrap the data length into same package

Jump to

Keyboard shortcuts

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