fastsocket

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

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

Go to latest
Published: Nov 18, 2018 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultBuffSize = 16 * 1024
View Source
const DefaultPoolSize = 256 * 1024

Variables

View Source
var ErrScheduleTimeout = fmt.Errorf("schedule error: timed out")

ErrScheduleTimeout returned by Pool to indicate that there no free goroutines during some period of time.

Functions

func CoarseTimeNow

func CoarseTimeNow() time.Time

CoarseTimeNow returns the current time truncated to the nearest second.

This is a faster alternative to time.Now().

func SetWorkerPool

func SetWorkerPool(p *Pool)

Types

type Addr

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

func (Addr) Network

func (a Addr) Network() string

func (Addr) String

func (a Addr) String() string

type NonBlockingConn

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

func (*NonBlockingConn) Close

func (c *NonBlockingConn) Close() error

func (*NonBlockingConn) File

func (c *NonBlockingConn) File() (*os.File, error)

func (*NonBlockingConn) LocalAddr

func (c *NonBlockingConn) LocalAddr() net.Addr

func (*NonBlockingConn) Read

func (c *NonBlockingConn) Read(b []byte) (n int, err error)

func (*NonBlockingConn) RemoteAddr

func (c *NonBlockingConn) RemoteAddr() net.Addr

func (*NonBlockingConn) SetDeadline

func (c *NonBlockingConn) SetDeadline(t time.Time) error

func (*NonBlockingConn) SetReadDeadline

func (c *NonBlockingConn) SetReadDeadline(t time.Time) error

func (*NonBlockingConn) SetWriteDeadline

func (c *NonBlockingConn) SetWriteDeadline(t time.Time) error

func (*NonBlockingConn) Write

func (c *NonBlockingConn) Write(b []byte) (n int, err error)

type Pool

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

Pool contains logic of goroutine reuse.

func NewPool

func NewPool(size, queue, spawn int) *Pool

NewPool creates new goroutine pool with given size. It also creates a work queue of given size. Finally, it spawns given amount of goroutines immediately.

func (*Pool) Schedule

func (p *Pool) Schedule(task func())

Schedule schedules task to be executed over pool's workers.

func (*Pool) ScheduleTimeout

func (p *Pool) ScheduleTimeout(timeout time.Duration, task func()) error

ScheduleTimeout schedules task to be executed over pool's workers. It returns ErrScheduleTimeout when no free workers met during given timeout.

type Server

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

func NewServer

func NewServer(addrs string) (*Server, error)

func (*Server) Accept

func (s *Server) Accept(acceptFn func(net.Conn)) error

func (*Server) Close

func (s *Server) Close() error

func (*Server) Listen

func (s *Server) Listen(addrs string) (err error)

type Socket

type Socket struct {
	net.Conn
	Reader *bufio.Reader
	Writer *bufio.Writer
	// contains filtered or unexported fields
}

func NewBufferedSocket

func NewBufferedSocket(conn net.Conn, readBuffSize, writeBuffSize int, timeout time.Duration) *Socket

func NewSocket

func NewSocket(conn net.Conn) *Socket

func (*Socket) Close

func (s *Socket) Close() error

func (*Socket) Flush

func (s *Socket) Flush()

func (*Socket) IsActive

func (s *Socket) IsActive() bool

func (*Socket) Listen

func (s *Socket) Listen() error

func (*Socket) OnClose

func (s *Socket) OnClose(onClose func()) *Socket

func (*Socket) OnReadable

func (s *Socket) OnReadable(onReadable func()) *Socket

func (*Socket) Read

func (s *Socket) Read(b []byte) (n int, err error)

func (*Socket) Write

func (s *Socket) Write(b []byte) (n int, err error)

Directories

Path Synopsis
example
Package tcplisten provides customizable TCP net.Listener with various performance-related options: - SO_REUSEPORT.
Package tcplisten provides customizable TCP net.Listener with various performance-related options: - SO_REUSEPORT.

Jump to

Keyboard shortcuts

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