coco

package
v0.0.0-...-9f455dc Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2023 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrServerStopped       = errors.New("coco: server already stopped")
	ErrInvalidListener     = errors.New("coco: invalid net listener")
	ErrInvalidHandler      = errors.New("coco: invalid handler")
	ErrUnsupportedProtocol = errors.New("coco: unsupported protocol")
	ErrClosedTimeout       = errors.New("coco: server closed connection timeout")
)

Functions

This section is empty.

Types

type CocoHandler

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

CocoHandler Example handler, just for testing

func (*CocoHandler) Close

func (c *CocoHandler) Close() error

func (*CocoHandler) Handle

func (c *CocoHandler) Handle(ctx context.Context, conn net.Conn)

type Config

type Config struct {
	MaxConn      uint64        `yaml:"maxConn"`
	Timeout      time.Duration `yaml:"timeout"`
	CloseTimeout time.Duration `yaml:"closeTimeout"`
	Retry        time.Duration `yaml:"retry"`
}

type Handler

type Handler interface {
	Handle(ctx context.Context, conn net.Conn)
	Close() error
}

type Option

type Option func(cfg *Config)

func WithMaxConn

func WithMaxConn(maxConn uint64) Option

func WithRetry

func WithRetry(retry time.Duration) Option

func WithTimeout

func WithTimeout(timeout time.Duration) Option

type Server

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

func NewServer

func NewServer(ctx context.Context, opts ...Option) *Server

NewServer create a new tcp server

func (*Server) Serve

func (s *Server) Serve(lis net.Listener, handler Handler) error

Serve start to accept tcp connections

func (*Server) Shutdown

func (s *Server) Shutdown() error

Jump to

Keyboard shortcuts

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