serverx

package
v1.0.8 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2023 License: GPL-3.0 Imports: 4 Imported by: 0

README

Server包

这个目录存放跟协议无关的Server管理,包括TCPServer和UnixSockServer

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Server

type Server interface {
	Run(string) error
	SetHandler(func(net.Conn))
	SetRejectHandler(func(net.Conn, error))
	SetAcceptErrorHandler(func(error))
	SetWorkersPoolSize(...uint32)
	CountBusyWorkers() uint32
	CountAvailableWorkers() uint32
	Close()
}

Server interface

type TCPServer

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

TCPServer struct

func NewTCPServer

func NewTCPServer(n ...uint32) *TCPServer

NewTCPServer 创建新的TCPServer NewTcpServer(x)表示总共有x个workers,并且全部预先创建好; NewTcpServer(y)表示总共有x个workers,只预先创建y个。

func (*TCPServer) Close

func (s *TCPServer) Close()

Close 关闭

func (*TCPServer) CountAvailableWorkers

func (s *TCPServer) CountAvailableWorkers() uint32

func (*TCPServer) CountBusyWorkers

func (s *TCPServer) CountBusyWorkers() uint32

func (*TCPServer) Run

func (s *TCPServer) Run(listen string) (err error)

Run with loop

func (*TCPServer) SetAcceptErrorHandler

func (s *TCPServer) SetAcceptErrorHandler(h func(error))

SetAcceptErrorHandler 当监听失败时的处理方法,此方法在监听协程执行,会阻塞监听 协程,处理完成之前无法监听新的连接。

func (*TCPServer) SetHandler

func (s *TCPServer) SetHandler(h func(net.Conn))

SetHandler 设置连接建立后的处理方法,此方法会分到不同的Worker去执行,不阻塞 监听协程。

func (*TCPServer) SetRejectHandler

func (s *TCPServer) SetRejectHandler(h func(net.Conn, error))

SetRejectHandler 设置当连接数过多被拒绝时的处理方法,此方法在监听协程执 行,会阻塞监听协程,处理完成之前无法监听新的连接。

func (*TCPServer) SetWorkersPoolSize

func (s *TCPServer) SetWorkersPoolSize(n ...uint32)

SetWorkersPoolSize 设置Worker数量 如果调用SetWorkersPoolSize(x)表示总共有x个workers,并且全部预先创建好; 如果调用SetWorkersPoolSize(y, x)表示总共有x个workers,只预先创建y个。

type UnixServer

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

UnixServer struct

func NewUnixServer

func NewUnixServer(n ...uint32) *UnixServer

NewUnixServer 创建新的TCPServer NewUnixServer(x)表示总共有x个workers,并且全部预先创建好; NewUnixServer(y)表示总共有x个workers,只预先创建y个。

func (*UnixServer) Close

func (s *UnixServer) Close()

Close 关闭

func (*UnixServer) CountAvailableWorkers

func (s *UnixServer) CountAvailableWorkers() uint32

func (*UnixServer) CountBusyWorkers

func (s *UnixServer) CountBusyWorkers() uint32

func (*UnixServer) Run

func (s *UnixServer) Run(file string) (err error)

Run with loop

func (*UnixServer) SetAcceptErrorHandler

func (s *UnixServer) SetAcceptErrorHandler(h func(error))

SetAcceptErrorHandler 当监听失败时的处理方法,此方法在监听协程执行,会阻塞监听 协程,处理完成之前无法监听新的连接。

func (*UnixServer) SetHandler

func (s *UnixServer) SetHandler(h func(net.Conn))

SetHandler 设置连接建立后的处理方法,此方法会分到不同的Worker去执行,不阻塞 监听协程。

func (*UnixServer) SetRejectHandler

func (s *UnixServer) SetRejectHandler(h func(net.Conn, error))

SetRejectHandler 设置当连接数过多被拒绝时的处理方法,此方法在监听协程执 行,会阻塞监听协程,处理完成之前无法监听新的连接。

func (*UnixServer) SetWorkersPoolSize

func (s *UnixServer) SetWorkersPoolSize(n ...uint32)

SetWorkersPoolSize 设置Worker数量 如果调用SetWorkersPoolSize(x)表示总共有x个workers,并且全部预先创建好; 如果调用SetWorkersPoolSize(y, x)表示总共有x个workers,只预先创建y个。

type Worker

type Worker struct {
	Work func(net.Conn)
	// contains filtered or unexported fields
}

Worker 是处理一个请求的Goroutine,worker可以复用

func (*Worker) ID

func (worker *Worker) ID() int

ID return worker id

func (*Worker) SetID

func (worker *Worker) SetID(id int)

SetID set worker id

Jump to

Keyboard shortcuts

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